|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Black Studio TinyMCE Widget - Compatibility code |
|
4
|
|
|
* |
|
5
|
|
|
* @package Black_Studio_TinyMCE_Widget |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Black_Studio_TinyMCE_Widget\Compatibility; |
|
9
|
|
|
|
|
10
|
|
|
// Exit if accessed directly. |
|
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
12
|
|
|
exit; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
if ( ! class_exists( 'Black_Studio_TinyMCE_Widget\\Compatibility\\Compatibility', false ) ) { |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class that manages compatibility code |
|
19
|
|
|
* |
|
20
|
|
|
* @package Black_Studio_TinyMCE_Widget |
|
21
|
|
|
* @since 2.0.0 |
|
22
|
|
|
*/ |
|
23
|
|
|
final class Compatibility { |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* The single instance of the plugin class |
|
27
|
|
|
* |
|
28
|
|
|
* @var object |
|
29
|
|
|
* @since 2.0.0 |
|
30
|
|
|
*/ |
|
31
|
|
|
protected static $_instance = null; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Array of compatibility modules class instances |
|
35
|
|
|
* |
|
36
|
|
|
* @var array |
|
37
|
|
|
* @since 2.4.0 |
|
38
|
|
|
*/ |
|
39
|
|
|
protected static $modules = null; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Class constructor |
|
43
|
|
|
* |
|
44
|
|
|
* @global object $wp_embed |
|
45
|
|
|
* @since 2.0.0 |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function __construct() { |
|
48
|
|
|
$this->load_plugins(); |
|
49
|
|
|
$this->load_wordpress(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Prevent the class from being cloned |
|
54
|
|
|
* |
|
55
|
|
|
* @return void |
|
56
|
|
|
* @since 2.0.0 |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function __clone() { |
|
59
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ uh?' ), '3.0' ); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Return the single class instance |
|
64
|
|
|
* |
|
65
|
|
|
* @return object |
|
66
|
|
|
* @since 2.0.0 |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function instance() { |
|
69
|
|
|
if ( is_null( self::$_instance ) ) { |
|
70
|
|
|
self::$_instance = new self(); |
|
71
|
|
|
} |
|
72
|
|
|
return self::$_instance; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return the instance of a compatibility class module, given its slug |
|
77
|
|
|
* |
|
78
|
|
|
* @param string $slug Slug of instance. |
|
79
|
|
|
* @return object |
|
80
|
|
|
* @since 3.0.0 |
|
81
|
|
|
*/ |
|
82
|
|
|
public static function module( $slug ) { |
|
83
|
|
|
return isset( self::$modules[ $slug ] ) ? self::$modules[ $slug ] : null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Load compatibility code for other plugins |
|
88
|
|
|
* |
|
89
|
|
|
* @uses apply_filters() |
|
90
|
|
|
* @uses plugin_dir_path() |
|
91
|
|
|
* |
|
92
|
|
|
* @return void |
|
93
|
|
|
* @since 2.0.0 |
|
94
|
|
|
*/ |
|
95
|
|
|
public function load_plugins() { |
|
96
|
|
|
$compatibility_plugins = array( |
|
97
|
|
|
'siteorigin_panels', |
|
98
|
|
|
'wpml', |
|
99
|
|
|
'jetpack_after_the_deadline', |
|
100
|
|
|
'wp_page_widget', |
|
101
|
|
|
'nextgen_gallery', |
|
102
|
|
|
'elementor', |
|
103
|
|
|
); |
|
104
|
|
|
$compatibility_plugins = apply_filters( 'black_studio_tinymce_load_compatibility_plugins', $compatibility_plugins ); |
|
105
|
|
|
if ( ! empty( $compatibility_plugins ) ) { |
|
106
|
|
|
foreach ( $compatibility_plugins as $plugin ) { |
|
107
|
|
|
$this->create_module_instance( 'plugin', $plugin ); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Load compatibility code for previous WordPress versions |
|
114
|
|
|
* |
|
115
|
|
|
* @uses get_bloginfo() |
|
116
|
|
|
* @uses plugin_dir_path() |
|
117
|
|
|
* |
|
118
|
|
|
* @return void |
|
119
|
|
|
* @since 2.0.0 |
|
120
|
|
|
*/ |
|
121
|
|
|
public function load_wordpress() { |
|
122
|
|
|
$compatibility_versions = array( '3.5', '3.9' ); |
|
123
|
|
|
foreach ( $compatibility_versions as $version ) { |
|
124
|
|
|
if ( version_compare( get_bloginfo( 'version' ), $version, '<' ) ) { |
|
125
|
|
|
$this->create_module_instance( strtolower( 'WordPress' ), 'pre_' . str_replace( '.', '', $version ) ); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Get path for compatibility code files |
|
132
|
|
|
* |
|
133
|
|
|
* @uses plugin_dir_path() |
|
134
|
|
|
* |
|
135
|
|
|
* @param string $folder Folder containing the file to be loaded. |
|
136
|
|
|
* @return string |
|
137
|
|
|
* @since 3.0.0 |
|
138
|
|
|
*/ |
|
139
|
|
|
public static function get_path( $folder = '' ) { |
|
140
|
|
|
$path = plugin_dir_path( dirname( __FILE__ ) ) . 'compat/'; |
|
141
|
|
|
if ( ! empty( $folder ) ) { |
|
142
|
|
|
$path .= $folder . '/'; |
|
143
|
|
|
} |
|
144
|
|
|
return $path; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Get instance of a compatibility module |
|
149
|
|
|
* |
|
150
|
|
|
* @param string $folder Folder containing the file to be loaded. |
|
151
|
|
|
* @param string $slug Slug of the file to be loaded. |
|
152
|
|
|
* @since 3.0.0 |
|
153
|
|
|
*/ |
|
154
|
|
|
public static function create_module_instance( $folder, $slug ) { |
|
155
|
|
|
$class_name = ucwords( $folder ) . '\\' . str_replace( ' ', '_', ucwords( str_replace( '_', ' ', $slug ) ) ); |
|
156
|
|
|
self::$modules[ $slug ] = call_user_func( array( $class_name, 'instance' ) ); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
} // END class |
|
160
|
|
|
|
|
161
|
|
|
} // END class_exists |
|
162
|
|
|
|