|
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 compatibility class |
|
59
|
|
|
* |
|
60
|
|
|
* @var object |
|
61
|
|
|
* @since 2.0.0 |
|
62
|
|
|
*/ |
|
63
|
|
|
protected static $compatibility = null; |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Instance of the text filters class |
|
67
|
|
|
* |
|
68
|
|
|
* @var object |
|
69
|
|
|
* @since 2.0.0 |
|
70
|
|
|
*/ |
|
71
|
|
|
protected static $text_filters = null; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Return the main plugin instance |
|
75
|
|
|
* |
|
76
|
|
|
* @return object |
|
77
|
|
|
* @since 2.0.0 |
|
78
|
|
|
*/ |
|
79
|
|
|
public static function instance() { |
|
80
|
|
|
if ( is_null( self::$_instance ) ) { |
|
81
|
|
|
self::$_instance = new self(); |
|
82
|
|
|
} |
|
83
|
|
|
return self::$_instance; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Return the instance of the admin class |
|
88
|
|
|
* |
|
89
|
|
|
* @return object |
|
90
|
|
|
* @since 2.0.0 |
|
91
|
|
|
*/ |
|
92
|
|
|
public static function admin() { |
|
93
|
|
|
return self::$admin; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Return the instance of the admin pointer class |
|
98
|
|
|
* |
|
99
|
|
|
* @return object |
|
100
|
|
|
* @since 2.1.0 |
|
101
|
|
|
*/ |
|
102
|
|
|
public static function admin_pointer() { |
|
103
|
|
|
return self::$admin_pointer; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Return the instance of the compatibility class |
|
108
|
|
|
* |
|
109
|
|
|
* @return object |
|
110
|
|
|
* @since 2.0.0 |
|
111
|
|
|
*/ |
|
112
|
|
|
public static function compatibility() { |
|
113
|
|
|
return self::$compatibility; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Return the instance of the text filters class |
|
118
|
|
|
* |
|
119
|
|
|
* @return object |
|
120
|
|
|
* @since 2.0.0 |
|
121
|
|
|
*/ |
|
122
|
|
|
public static function text_filters() { |
|
123
|
|
|
return self::$text_filters; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get plugin version |
|
128
|
|
|
* |
|
129
|
|
|
* @return string |
|
130
|
|
|
* @since 2.0.0 |
|
131
|
|
|
*/ |
|
132
|
|
|
public static function get_version() { |
|
133
|
|
|
return self::$version; |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Get plugin basename |
|
138
|
|
|
* |
|
139
|
|
|
* @uses plugin_basename() |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
* @since 2.0.0 |
|
143
|
|
|
*/ |
|
144
|
|
|
public static function get_basename() { |
|
145
|
|
|
return plugin_basename( dirname( __FILE__ ) . '/black-studio-tinymce-widget.php' ); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Class constructor |
|
150
|
|
|
* |
|
151
|
|
|
* @uses add_action() |
|
152
|
|
|
* @uses add_filter() |
|
153
|
|
|
* @uses get_option() |
|
154
|
|
|
* @uses get_bloginfo() |
|
155
|
|
|
* |
|
156
|
|
|
* @global object $wp_embed |
|
157
|
|
|
* @since 2.0.0 |
|
158
|
|
|
*/ |
|
159
|
|
|
protected function __construct() { |
|
160
|
|
|
if ( is_admin() ) { |
|
161
|
|
|
// Instantiate admin classes on admin pages. |
|
162
|
|
|
self::$admin = Admin\Admin::instance(); |
|
163
|
|
|
self::$admin_pointer = Admin\Admin_Pointer::instance(); |
|
164
|
|
|
} else { |
|
165
|
|
|
// Instantiate text filter class on frontend pages. |
|
166
|
|
|
self::$text_filters = Utilities\Text_Filters::instance(); |
|
167
|
|
|
} |
|
168
|
|
|
// Register action and filter hooks. |
|
169
|
|
|
add_action( 'plugins_loaded', array( $this, 'load_compatibility' ), 50 ); |
|
170
|
|
|
add_action( 'widgets_init', array( $this, 'widgets_init' ) ); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Prevent the class from being cloned |
|
175
|
|
|
* |
|
176
|
|
|
* @return void |
|
177
|
|
|
* @since 2.0.0 |
|
178
|
|
|
*/ |
|
179
|
|
|
protected function __clone() { |
|
180
|
|
|
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ uh?' ), '2.0' ); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* Load compatibility class |
|
185
|
|
|
* |
|
186
|
|
|
* @uses apply_filters() |
|
187
|
|
|
* @uses get_bloginfo() |
|
188
|
|
|
* @uses plugin_dir_path() |
|
189
|
|
|
* |
|
190
|
|
|
* @return void |
|
191
|
|
|
* @since 2.0.0 |
|
192
|
|
|
*/ |
|
193
|
|
|
public function load_compatibility() { |
|
194
|
|
|
// Flag to control load of compatibility code. |
|
195
|
|
|
$load_compatibility = apply_filters( 'black_studio_tinymce_load_compatibility', true ); |
|
196
|
|
|
if ( $load_compatibility ) { |
|
197
|
|
|
include_once plugin_dir_path( __DIR__ ) . 'compat/class-black-studio-tinymce-compatibility.php'; |
|
198
|
|
|
self::$compatibility = Black_Studio_TinyMCE_Compatibility::instance(); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
/** |
|
203
|
|
|
* Widget initialization |
|
204
|
|
|
* |
|
205
|
|
|
* @uses is_blog_installed() |
|
206
|
|
|
* @uses register_widget() |
|
207
|
|
|
* |
|
208
|
|
|
* @return null|void |
|
209
|
|
|
* @since 2.0.0 |
|
210
|
|
|
*/ |
|
211
|
|
|
public function widgets_init() { |
|
212
|
|
|
if ( ! is_blog_installed() ) { |
|
213
|
|
|
return; |
|
214
|
|
|
} |
|
215
|
|
|
register_widget( 'Black_Studio_TinyMCE_Widget\\WP_Widget_Black_Studio_TinyMCE' ); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
/** |
|
219
|
|
|
* Check if a widget is a Black Studio Tinyme Widget instance |
|
220
|
|
|
* |
|
221
|
|
|
* @param object $widget Widget instance. |
|
222
|
|
|
* @return boolean |
|
223
|
|
|
* @since 2.0.0 |
|
224
|
|
|
*/ |
|
225
|
|
|
public function check_widget( $widget ) { |
|
226
|
|
|
return 'object' === gettype( $widget ) && ( 'WP_Widget_Black_Studio_TinyMCE' === get_class( $widget ) || is_subclass_of( $widget, 'WP_Widget_Black_Studio_TinyMCE' ) ); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
} // END class |
|
230
|
|
|
} // END class_exists |
|
231
|
|
|
|