1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Black Studio TinyMCE Widget - Compatibility code |
4
|
|
|
* |
5
|
|
|
* @package Black_Studio_TinyMCE_Widget |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
// Exit if accessed directly. |
9
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
10
|
|
|
exit; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
if ( ! class_exists( 'Black_Studio_TinyMCE_Compatibility' ) ) { |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class that manages compatibility code |
17
|
|
|
* |
18
|
|
|
* @package Black_Studio_TinyMCE_Widget |
19
|
|
|
* @since 2.0.0 |
20
|
|
|
*/ |
21
|
|
|
final class Black_Studio_TinyMCE_Compatibility { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The single instance of the plugin class |
25
|
|
|
* |
26
|
|
|
* @var object |
27
|
|
|
* @since 2.0.0 |
28
|
|
|
*/ |
29
|
|
|
protected static $_instance = null; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Array of compatibility modules class instances |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
* @since 2.4.0 |
36
|
|
|
*/ |
37
|
|
|
protected static $modules = null; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Instance of compatibility class for 3rd party plugins |
41
|
|
|
* |
42
|
|
|
* @var object |
43
|
|
|
* @since 2.0.0 |
44
|
|
|
* @deprecated 3.0.0 |
45
|
|
|
*/ |
46
|
|
|
protected static $plugins = null; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Instance of compatibility class for WordPress old versions |
50
|
|
|
* |
51
|
|
|
* @var object |
52
|
|
|
* @since 2.0.0 |
53
|
|
|
* @deprecated 3.0.0 |
54
|
|
|
*/ |
55
|
|
|
protected static $wordpress = null; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Class constructor |
59
|
|
|
* |
60
|
|
|
* @global object $wp_embed |
61
|
|
|
* @since 2.0.0 |
62
|
|
|
*/ |
63
|
|
|
protected function __construct() { |
64
|
|
|
$this->load_plugins(); |
65
|
|
|
$this->load_wordpress(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Prevent the class from being cloned |
70
|
|
|
* |
71
|
|
|
* @return void |
72
|
|
|
* @since 2.0.0 |
73
|
|
|
*/ |
74
|
|
|
protected function __clone() { |
75
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ uh?' ), '3.0' ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Return the single class instance |
80
|
|
|
* |
81
|
|
|
* @return object |
82
|
|
|
* @since 2.0.0 |
83
|
|
|
*/ |
84
|
|
|
public static function instance() { |
85
|
|
|
if ( is_null( self::$_instance ) ) { |
86
|
|
|
self::$_instance = new self(); |
87
|
|
|
} |
88
|
|
|
return self::$_instance; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return the instance of a compatibility class module, given its slug |
93
|
|
|
* |
94
|
|
|
* @param string $slug Slug of instance. |
95
|
|
|
* @return object |
96
|
|
|
* @since 3.0.0 |
97
|
|
|
*/ |
98
|
|
|
public static function module( $slug ) { |
99
|
|
|
return isset( self::$modules[ $slug ] ) ? self::$modules[ $slug ] : null; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Return the instance of the compatibility class for 3rd party plugins |
104
|
|
|
* |
105
|
|
|
* @return object |
106
|
|
|
* @since 2.0.0 |
107
|
|
|
* @deprecated 3.0.0 |
108
|
|
|
*/ |
109
|
|
|
public static function plugins() { |
110
|
|
|
_deprecated_function( __FUNCTION__, '3.00' ); |
111
|
|
|
include_once self::get_path() . 'class-compatibility-plugins.php'; |
112
|
|
|
self::$plugins = Black_Studio_TinyMCE_Compatibility_Plugins::instance(); |
113
|
|
|
return self::$plugins; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Return the instance of the compatibility class for WordPress old versions |
118
|
|
|
* |
119
|
|
|
* @return object |
120
|
|
|
* @since 2.0.0 |
121
|
|
|
* @deprecated 3.0.0 |
122
|
|
|
*/ |
123
|
|
|
public static function wordpress() { |
124
|
|
|
_deprecated_function( __FUNCTION__, '3.0.0' ); |
125
|
|
|
if ( version_compare( get_bloginfo( 'version' ), '3.9', '<' ) ) { |
126
|
|
|
include_once self::get_path() . 'class-compatibility-wordpress.php'; |
127
|
|
|
self::$wordpress = Black_Studio_TinyMCE_Compatibility_WordPress::instance(); |
128
|
|
|
} |
129
|
|
|
return self::$wordpress; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Load compatibility code for previous BSTW versions |
134
|
|
|
* |
135
|
|
|
* @uses apply_filters() |
136
|
|
|
* @uses plugin_dir_path() |
137
|
|
|
* |
138
|
|
|
* @return void |
139
|
|
|
* @since 2.0.0 |
140
|
|
|
* @deprecated 3.0.0 |
141
|
|
|
*/ |
142
|
|
|
public function load_deprecated() { |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Load compatibility code for other plugins |
147
|
|
|
* |
148
|
|
|
* @uses apply_filters() |
149
|
|
|
* @uses plugin_dir_path() |
150
|
|
|
* |
151
|
|
|
* @return void |
152
|
|
|
* @since 2.0.0 |
153
|
|
|
*/ |
154
|
|
|
public function load_plugins() { |
155
|
|
|
$compatibility_plugins = array( |
156
|
|
|
'siteorigin_panels', |
157
|
|
|
'wpml', |
158
|
|
|
'jetpack_after_the_deadline', |
159
|
|
|
'wp_page_widget', |
160
|
|
|
'nextgen_gallery', |
161
|
|
|
'elementor', |
162
|
|
|
); |
163
|
|
|
$compatibility_plugins = apply_filters( 'black_studio_tinymce_load_compatibility_plugins', $compatibility_plugins ); |
164
|
|
|
if ( ! empty( $compatibility_plugins ) ) { |
165
|
|
|
foreach ( $compatibility_plugins as $plugin ) { |
166
|
|
|
$this->create_module_instance( 'plugin', $plugin ); |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Load compatibility code for previous WordPress versions |
173
|
|
|
* |
174
|
|
|
* @uses get_bloginfo() |
175
|
|
|
* @uses plugin_dir_path() |
176
|
|
|
* |
177
|
|
|
* @return void |
178
|
|
|
* @since 2.0.0 |
179
|
|
|
*/ |
180
|
|
|
public function load_wordpress() { |
181
|
|
|
$compatibility_versions = array( '3.5', '3.9' ); |
182
|
|
|
foreach ( $compatibility_versions as $version ) { |
183
|
|
|
if ( version_compare( get_bloginfo( 'version' ), $version, '<' ) ) { |
184
|
|
|
$this->create_module_instance( strtolower( 'WordPress' ), 'pre_' . str_replace( '.', '', $version ) ); |
185
|
|
|
} |
186
|
|
|
} |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Get path for compatibility code files |
191
|
|
|
* |
192
|
|
|
* @uses plugin_dir_path() |
193
|
|
|
* |
194
|
|
|
* @param string $folder Folder containing the file to be loaded. |
195
|
|
|
* @return string |
196
|
|
|
* @since 3.0.0 |
197
|
|
|
*/ |
198
|
|
|
public static function get_path( $folder = '' ) { |
199
|
|
|
$path = plugin_dir_path( dirname( __FILE__ ) ) . 'compat/'; |
200
|
|
|
if ( ! empty( $folder ) ) { |
201
|
|
|
$path .= $folder . '/'; |
202
|
|
|
} |
203
|
|
|
return $path; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get instance of a compatibility module |
208
|
|
|
* |
209
|
|
|
* @param string $folder Folder containing the file to be loaded. |
210
|
|
|
* @param string $slug Slug of the file to be loaded. |
211
|
|
|
* @since 3.0.0 |
212
|
|
|
*/ |
213
|
|
|
public static function create_module_instance( $folder, $slug ) { |
214
|
|
|
$file = self::get_path( $folder ) . 'class-black-studio-tinymce-compatibility-' . $folder . '-' . str_replace( '_', '-', $slug ) . '.php'; |
215
|
|
|
if ( file_exists( $file ) ) { |
216
|
|
|
include_once $file; |
217
|
|
|
$class_name = 'Black_Studio_TinyMCE_Compatibility_' . ucwords( $folder ) . '_'; |
218
|
|
|
$class_name .= str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $slug ) ) ); |
219
|
|
|
self::$modules[ $slug ] = call_user_func( array( $class_name, 'instance' ) ); |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
} // END class Black_Studio_TinyMCE_Compatibility |
224
|
|
|
|
225
|
|
|
} // END class_exists check |
226
|
|
|
|