|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
// Exit if accessed directly |
|
4
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
5
|
|
|
exit; |
|
6
|
|
|
} |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class that provides compatibility Compatibility with WPML plugins |
|
10
|
|
|
* |
|
11
|
|
|
* @package Black_Studio_TinyMCE_Widget |
|
12
|
|
|
* @since 2.4.0 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
if ( ! class_exists( 'Black_Studio_TinyMCE_Compatibility_Plugin_Wpml' ) ) { |
|
16
|
|
|
|
|
17
|
|
|
final class Black_Studio_TinyMCE_Compatibility_Plugin_Wpml { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* The single instance of the class |
|
21
|
|
|
* |
|
22
|
|
|
* @var object |
|
23
|
|
|
* @since 2.4.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
protected static $_instance = null; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Return the single class instance |
|
29
|
|
|
* |
|
30
|
|
|
* @return object |
|
31
|
|
|
* @since 2.4.0 |
|
32
|
|
|
*/ |
|
33
|
|
|
public static function instance() { |
|
34
|
|
|
if ( is_null( self::$_instance ) ) { |
|
35
|
|
|
self::$_instance = new self(); |
|
36
|
|
|
} |
|
37
|
|
|
return self::$_instance; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class constructor |
|
42
|
|
|
* |
|
43
|
|
|
* @uses add_action() |
|
44
|
|
|
* @uses add_filter() |
|
45
|
|
|
* |
|
46
|
|
|
* @since 2.4.0 |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function __construct() { |
|
49
|
|
|
add_action( 'init', array( $this, 'init' ) ); |
|
50
|
|
|
add_action( 'black_studio_tinymce_before_widget', array( $this, 'widget_before' ), 10, 2 ); |
|
51
|
|
|
add_action( 'black_studio_tinymce_after_widget', array( $this, 'widget_after' ), 10, 2 ); |
|
52
|
|
|
add_filter( 'black_studio_tinymce_widget_update', array( $this, 'widget_update' ), 10, 2 ); |
|
53
|
|
|
add_filter( 'widget_text', array( $this, 'widget_text' ), 2, 3 ); |
|
54
|
|
|
if ( ! function_exists( 'is_plugin_active' ) ) { |
|
55
|
|
|
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Prevent the class from being cloned |
|
61
|
|
|
* |
|
62
|
|
|
* @return void |
|
63
|
|
|
* @since 2.4.0 |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function __clone() { |
|
66
|
|
|
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ uh?' ), '2.0' ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Initialize compatibility with WPML |
|
71
|
|
|
* |
|
72
|
|
|
* @uses is_plugin_active() |
|
73
|
|
|
* @uses has_action() |
|
74
|
|
|
* @uses remove_action() |
|
75
|
|
|
* |
|
76
|
|
|
* @return void |
|
77
|
|
|
* @since 2.4.0 |
|
78
|
|
|
*/ |
|
79
|
|
|
public function init() { |
|
80
|
|
|
if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { |
|
81
|
|
|
if ( false !== has_action( 'update_option_widget_black-studio-tinymce', 'icl_st_update_widget_title_actions' ) ) { |
|
82
|
|
|
remove_action( 'update_option_widget_black-studio-tinymce', 'icl_st_update_widget_title_actions', 5 ); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Disable WPML String translation native behavior |
|
89
|
|
|
* |
|
90
|
|
|
* @uses is_plugin_active() |
|
91
|
|
|
* @uses has_filter() |
|
92
|
|
|
* @uses remove_filter() |
|
93
|
|
|
* |
|
94
|
|
|
* @param mixed[] $args |
|
95
|
|
|
* @param mixed[] $instance |
|
96
|
|
|
* @return void |
|
97
|
|
|
* @since 2.4.0 |
|
98
|
|
|
*/ |
|
99
|
|
|
public function widget_before( $args, $instance ) { |
|
100
|
|
|
if( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) { |
|
|
|
|
|
|
101
|
|
|
// Avoid native WPML string translation of widget titles |
|
102
|
|
|
// For widgets inserted in pages built with Page Builder (SiteOrigin panels) and also when WPML Widgets is active |
|
103
|
|
|
if ( false !== has_filter( 'widget_title', 'icl_sw_filters_widget_title' ) ) { |
|
104
|
|
|
if ( isset( $instance['panels_info'] ) || is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { |
|
105
|
|
|
remove_filter( 'widget_title', 'icl_sw_filters_widget_title', 0 ); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
// Avoid native WPML string translation of widget texts (for all widgets) |
|
109
|
|
|
// Black Studio TinyMCE Widget already supports WPML string translation, so this is needed to prevent duplicate translations |
|
110
|
|
|
if ( false !== has_filter( 'widget_text', 'icl_sw_filters_widget_text' ) ) { |
|
111
|
|
|
remove_filter( 'widget_text', 'icl_sw_filters_widget_text', 0 ); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
/** |
|
117
|
|
|
* Re-Enable WPML String translation native behavior |
|
118
|
|
|
* |
|
119
|
|
|
* @uses is_plugin_active() |
|
120
|
|
|
* @uses has_filter() |
|
121
|
|
|
* @uses add_filter() |
|
122
|
|
|
* |
|
123
|
|
|
* @param mixed[] $args |
|
124
|
|
|
* @param mixed[] $instance |
|
125
|
|
|
* @return void |
|
126
|
|
|
* @since 2.4.0 |
|
127
|
|
|
*/ |
|
128
|
|
|
public function widget_after( $args, $instance ) { |
|
129
|
|
|
if( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) { |
|
|
|
|
|
|
130
|
|
|
if ( false === has_filter( 'widget_title', 'icl_sw_filters_widget_title' ) && function_exists( 'icl_sw_filters_widget_title' ) ) { |
|
131
|
|
|
if ( isset( $instance['panels_info'] ) || is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { |
|
132
|
|
|
add_filter( 'widget_title', 'icl_sw_filters_widget_title', 0 ); |
|
133
|
|
|
} |
|
134
|
|
|
} |
|
135
|
|
|
if ( false === has_filter( 'widget_text', 'icl_sw_filters_widget_text' ) && function_exists( 'icl_sw_filters_widget_text' ) ) { |
|
136
|
|
|
add_filter( 'widget_text', 'icl_sw_filters_widget_text', 0 ); |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Add widget text to WPML String translation |
|
143
|
|
|
* |
|
144
|
|
|
* @uses is_plugin_active() |
|
145
|
|
|
* @uses icl_register_string() (WPML) |
|
146
|
|
|
* |
|
147
|
|
|
* @param mixed[] $instance |
|
148
|
|
|
* @param object $widget |
|
149
|
|
|
* @return mixed[] |
|
150
|
|
|
* @since 2.4.0 |
|
151
|
|
|
*/ |
|
152
|
|
|
public function widget_update( $instance, $widget ) { |
|
153
|
|
|
if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && ! is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { |
|
154
|
|
|
if ( function_exists( 'icl_register_string' ) && ! empty( $widget->number ) ) { |
|
155
|
|
|
if ( ! isset( $instance['panels_info'] ) ) { // Avoid translation of Page Builder (SiteOrigin panels) widgets |
|
156
|
|
|
icl_register_string( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $instance['text'] ); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
} |
|
160
|
|
|
return $instance; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Translate widget text |
|
165
|
|
|
* |
|
166
|
|
|
* @uses is_plugin_active() |
|
167
|
|
|
* @uses icl_t() (WPML) |
|
168
|
|
|
* |
|
169
|
|
|
* @param string $text |
|
170
|
|
|
* @param mixed[]|null $instance |
|
171
|
|
|
* @param object|null $widget |
|
172
|
|
|
* @return string |
|
173
|
|
|
* @since 2.4.0 |
|
174
|
|
|
*/ |
|
175
|
|
|
public function widget_text( $text, $instance = null, $widget = null ) { |
|
176
|
|
|
if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) && ! is_plugin_active( 'wpml-widgets/wpml-widgets.php' ) ) { |
|
177
|
|
|
if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { |
|
178
|
|
|
if ( function_exists( 'icl_t' ) ) { |
|
179
|
|
|
// Avoid translation of Page Builder (SiteOrigin panels) widgets |
|
180
|
|
|
if ( ! isset( $instance['panels_info'] ) ) { |
|
181
|
|
|
$text = icl_t( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $text ); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
return $text; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
} // END class Black_Studio_TinyMCE_Compatibility_Plugin_Wpml |
|
190
|
|
|
|
|
191
|
|
|
} // END class_exists check |
|
192
|
|
|
|