1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Black Studio TinyMCE Widget - Main plugin class |
4
|
|
|
* |
5
|
|
|
* @package Black_Studio_TinyMCE_Widget |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Black_Studio_TinyMCE_Widget; |
9
|
|
|
|
10
|
|
|
// Exit if accessed directly. |
11
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
12
|
|
|
exit; |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
if ( ! class_exists( 'Black_Studio_TinyMCE_Widget\\Plugin', true ) ) { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Main plugin class |
19
|
|
|
* |
20
|
|
|
* @package Black_Studio_TinyMCE_Widget |
21
|
|
|
* @since 2.0.0 |
22
|
|
|
*/ |
23
|
|
|
final class Plugin { |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Plugin version |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
* @since 2.0.0 |
30
|
|
|
*/ |
31
|
|
|
public static $version = '2.6.2'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The single instance of the plugin class |
35
|
|
|
* |
36
|
|
|
* @var object |
37
|
|
|
* @since 2.0.0 |
38
|
|
|
*/ |
39
|
|
|
protected static $_instance = null; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Instance of admin class |
43
|
|
|
* |
44
|
|
|
* @var object |
45
|
|
|
* @since 2.0.0 |
46
|
|
|
*/ |
47
|
|
|
protected static $admin = null; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Instance of admin pointer class |
51
|
|
|
* |
52
|
|
|
* @var object |
53
|
|
|
* @since 2.1.0 |
54
|
|
|
*/ |
55
|
|
|
protected static $admin_pointer = null; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Instance of admin assets class |
59
|
|
|
* |
60
|
|
|
* @var object |
61
|
|
|
* @since 2.1.0 |
62
|
|
|
*/ |
63
|
|
|
protected static $admin_assets = null; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Instance of compatibility class |
67
|
|
|
* |
68
|
|
|
* @var object |
69
|
|
|
* @since 2.0.0 |
70
|
|
|
*/ |
71
|
|
|
protected static $compatibility = null; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Instance of the text filters class |
75
|
|
|
* |
76
|
|
|
* @var object |
77
|
|
|
* @since 2.0.0 |
78
|
|
|
*/ |
79
|
|
|
protected static $text_filters = null; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Return the main plugin instance |
83
|
|
|
* |
84
|
|
|
* @return object |
85
|
|
|
* @since 2.0.0 |
86
|
|
|
*/ |
87
|
|
|
public static function instance() { |
88
|
|
|
if ( is_null( self::$_instance ) ) { |
89
|
|
|
self::$_instance = new self(); |
90
|
|
|
} |
91
|
|
|
return self::$_instance; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return the instance of the admin class |
96
|
|
|
* |
97
|
|
|
* @return object |
98
|
|
|
* @since 2.0.0 |
99
|
|
|
*/ |
100
|
|
|
public static function admin() { |
101
|
|
|
return self::$admin; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Return the instance of the admin pointer class |
106
|
|
|
* |
107
|
|
|
* @return object |
108
|
|
|
* @since 2.1.0 |
109
|
|
|
*/ |
110
|
|
|
public static function admin_pointer() { |
111
|
|
|
return self::$admin_pointer; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return the instance of the admin assets class |
116
|
|
|
* |
117
|
|
|
* @return object |
118
|
|
|
* @since 3.0.0 |
119
|
|
|
*/ |
120
|
|
|
public static function admin_assets() { |
121
|
|
|
return self::$admin_assets; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Return the instance of the compatibility class |
126
|
|
|
* |
127
|
|
|
* @return object |
128
|
|
|
* @since 2.0.0 |
129
|
|
|
*/ |
130
|
|
|
public static function compatibility() { |
131
|
|
|
return self::$compatibility; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Return the instance of the text filters class |
136
|
|
|
* |
137
|
|
|
* @return object |
138
|
|
|
* @since 2.0.0 |
139
|
|
|
*/ |
140
|
|
|
public static function text_filters() { |
141
|
|
|
return self::$text_filters; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get plugin version |
146
|
|
|
* |
147
|
|
|
* @return string |
148
|
|
|
* @since 2.0.0 |
149
|
|
|
*/ |
150
|
|
|
public static function get_version() { |
151
|
|
|
return self::$version; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Get plugin basename |
156
|
|
|
* |
157
|
|
|
* @uses plugin_basename() |
158
|
|
|
* |
159
|
|
|
* @return string |
160
|
|
|
* @since 2.0.0 |
161
|
|
|
*/ |
162
|
|
|
public static function get_basename() { |
163
|
|
|
return plugin_basename( dirname( __FILE__ ) . '/black-studio-tinymce-widget.php' ); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Class constructor |
168
|
|
|
* |
169
|
|
|
* @uses add_action() |
170
|
|
|
* @uses add_filter() |
171
|
|
|
* @uses get_option() |
172
|
|
|
* @uses get_bloginfo() |
173
|
|
|
* |
174
|
|
|
* @global object $wp_embed |
175
|
|
|
* @since 2.0.0 |
176
|
|
|
*/ |
177
|
|
|
protected function __construct() { |
178
|
|
|
if ( is_admin() ) { |
179
|
|
|
// Instantiate admin classes on admin pages. |
180
|
|
|
self::$admin = Admin\Admin::instance(); |
181
|
|
|
self::$admin_pointer = Admin\Admin_Pointer::instance(); |
182
|
|
|
self::$admin_assets = Admin\Admin_Assets::instance(); |
183
|
|
|
} else { |
184
|
|
|
// Instantiate text filter class on frontend pages. |
185
|
|
|
self::$text_filters = Utilities\Text_Filters::instance(); |
186
|
|
|
} |
187
|
|
|
// Register action and filter hooks. |
188
|
|
|
add_action( 'plugins_loaded', array( $this, 'load_compatibility' ), 50 ); |
189
|
|
|
add_action( 'widgets_init', array( $this, 'widgets_init' ) ); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Prevent the class from being cloned |
194
|
|
|
* |
195
|
|
|
* @return void |
196
|
|
|
* @since 2.0.0 |
197
|
|
|
*/ |
198
|
|
|
protected function __clone() { |
199
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ uh?' ), '2.0' ); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Load compatibility class |
204
|
|
|
* |
205
|
|
|
* @uses apply_filters() |
206
|
|
|
* @uses get_bloginfo() |
207
|
|
|
* @uses plugin_dir_path() |
208
|
|
|
* |
209
|
|
|
* @return void |
210
|
|
|
* @since 2.0.0 |
211
|
|
|
*/ |
212
|
|
|
public function load_compatibility() { |
213
|
|
|
// Flag to control load of compatibility code. |
214
|
|
|
$load_compatibility = apply_filters( 'black_studio_tinymce_load_compatibility', true ); |
215
|
|
|
if ( $load_compatibility ) { |
216
|
|
|
self::$compatibility = Compatibility\Compatibility::instance(); |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Widget initialization |
222
|
|
|
* |
223
|
|
|
* @uses is_blog_installed() |
224
|
|
|
* @uses register_widget() |
225
|
|
|
* |
226
|
|
|
* @return null|void |
227
|
|
|
* @since 2.0.0 |
228
|
|
|
*/ |
229
|
|
|
public function widgets_init() { |
230
|
|
|
if ( ! is_blog_installed() ) { |
231
|
|
|
return; |
232
|
|
|
} |
233
|
|
|
register_widget( 'Black_Studio_TinyMCE_Widget\\WP_Widget_Black_Studio_TinyMCE' ); |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Check if a widget is a Black Studio Tinyme Widget instance |
238
|
|
|
* |
239
|
|
|
* @param object $widget Widget instance. |
240
|
|
|
* @return boolean |
241
|
|
|
* @since 2.0.0 |
242
|
|
|
*/ |
243
|
|
|
public function check_widget( $widget ) { |
244
|
|
|
return 'object' === gettype( $widget ) && ( 'WP_Widget_Black_Studio_TinyMCE' === get_class( $widget ) || is_subclass_of( $widget, 'WP_Widget_Black_Studio_TinyMCE' ) ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
} // END class |
248
|
|
|
} // END class_exists |
249
|
|
|
|