DataSettings.php
2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
namespace WPML\PB\SiteOrigin;
use WPML\FP\Obj;
class DataSettings implements \IWPML_Page_Builders_Data_Settings {
/**
* @return string
*/
public function get_meta_field() {
return 'panels_data';
}
/**
* @return string
*/
public function get_node_id_field() {
return 'widget_id';
}
/**
* @return array
*/
public function get_fields_to_copy() {
return [];
}
/**
* @param array $data
*
* @return array
*/
public function convert_data_to_array( $data ) {
return $data;
}
/**
* @param array $data
*
* @return array
*/
public function prepare_data_for_saving( array $data ) {
return $data;
}
/**
* @return string
*/
public function get_pb_name() {
return 'SiteOrigin';
}
/**
* @return array
*/
public function get_fields_to_save() {
return [ $this->get_meta_field() ];
}
public function add_hooks() {
add_filter( 'pre_wpml_is_translated_taxonomy', [ $this, 'filterMenus' ], 10, 2 );
add_filter( 'siteorigin_panels_widgets', [ $this, 'removeWidgets' ] );
add_filter( 'siteorigin_panels_widget_form', [ $this, 'removeLanguageSelector' ] );
}
/**
* By letting WPML think `nav_menu` is translatable, it will filter out items in other languages.
* To avoid interfeering with anything else, we do this only for the SiteOrigin menu widget.
*
* @param bool|null $result
* @param string $tax
*
* @return bool|null
*/
public function filterMenus( $result, $tax ) {
/* phpcs:ignore WordPress.Security.NonceVerification.Recommended */
if ( is_admin() && 'nav_menu' === $tax && Obj::prop( 'action', $_REQUEST ) === 'so_panels_widget_form' ) {
$result = true;
}
return $result;
}
/**
* @param array $widgets
*
* @return array
*/
public function removeWidgets( $widgets ) {
unset( $widgets['WPML_LS_Widget'], $widgets['WP_Widget_Text_Icl'] );
return $widgets;
}
/**
* @param int $postId
*
* @return bool
*/
public function is_handling_post( $postId ) {
return (bool) get_post_meta( $postId, $this->get_meta_field(), true );
}
/**
* @param string $form
*
* @return string
*/
public function removeLanguageSelector( $form ) {
$form = preg_replace( '/<p>[\n\r\t]*<label for="wpml-language">.*<\/p>/s', '', $form, 1 );
$form = preg_replace( '/<select name="icl_language">.*<\/label>/s', '', $form, 1 );
return $form;
}
}