Complex classes like Black_Studio_TinyMCE_Compatibility_Plugins often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Black_Studio_TinyMCE_Compatibility_Plugins, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | final class Black_Studio_TinyMCE_Compatibility_Plugins { |
||
18 | |||
19 | /** |
||
20 | * The single instance of the class |
||
21 | * |
||
22 | * @var object |
||
23 | * @since 2.0.0 |
||
24 | */ |
||
25 | protected static $_instance = null; |
||
26 | |||
27 | /** |
||
28 | * Return the single class instance |
||
29 | * |
||
30 | * @param string[] $plugins |
||
31 | * @return object |
||
32 | * @since 2.0.0 |
||
33 | */ |
||
34 | public static function instance( $plugins = array() ) { |
||
40 | |||
41 | /** |
||
42 | * Class constructor |
||
43 | * |
||
44 | * @param string[] $plugins |
||
45 | * @since 2.0.0 |
||
46 | */ |
||
47 | protected function __construct( $plugins ) { |
||
57 | |||
58 | /** |
||
59 | * Prevent the class from being cloned |
||
60 | * |
||
61 | * @return void |
||
62 | * @since 2.0.0 |
||
63 | */ |
||
64 | protected function __clone() { |
||
67 | |||
68 | /** |
||
69 | * Compatibility with WPML |
||
70 | * |
||
71 | * @uses add_filter() |
||
72 | * |
||
73 | * @return void |
||
74 | * @since 2.0.0 |
||
75 | */ |
||
76 | public function wpml() { |
||
83 | |||
84 | /** |
||
85 | * Initialize compatibility with WPML and WPML Widgets plugins |
||
86 | * |
||
87 | * @uses is_plugin_active() |
||
88 | * @uses has_action() |
||
89 | * @uses remove_action() |
||
90 | * |
||
91 | * @return void |
||
92 | * @since 2.3.1 |
||
93 | */ |
||
94 | public function wpml_init() { |
||
101 | |||
102 | /** |
||
103 | * Disable WPML String translation native behavior |
||
104 | * |
||
105 | * @uses remove_filter() |
||
106 | * |
||
107 | * @param mixed[] $args |
||
108 | * @param mixed[] $instance |
||
109 | * @return void |
||
110 | * @since 2.3.0 |
||
111 | */ |
||
112 | public function wpml_widget_before( $args, $instance ) { |
||
129 | |||
130 | /** |
||
131 | * Re-Enable WPML String translation native behavior |
||
132 | * |
||
133 | * @uses add_filter() |
||
134 | * |
||
135 | * @param mixed[] $args |
||
136 | * @param mixed[] $instance |
||
137 | * @return void |
||
138 | * @since 2.3.0 |
||
139 | */ |
||
140 | public function wpml_widget_after( $args, $instance ) { |
||
152 | |||
153 | /** |
||
154 | * Add widget text to WPML String translation |
||
155 | * |
||
156 | * @uses is_plugin_active() |
||
157 | * @uses icl_register_string() Part of WPML |
||
158 | * |
||
159 | * @param mixed[] $instance |
||
160 | * @param object $widget |
||
161 | * @return mixed[] |
||
162 | * @since 2.0.0 |
||
163 | */ |
||
164 | public function wpml_widget_update( $instance, $widget ) { |
||
174 | |||
175 | /** |
||
176 | * Translate widget text |
||
177 | * |
||
178 | * @uses is_plugin_active() |
||
179 | * @uses icl_t() Part of WPML |
||
180 | * |
||
181 | * @param string $text |
||
182 | * @param mixed[]|null $instance |
||
183 | * @param object|null $widget |
||
184 | * @return string |
||
185 | * @since 2.0.0 |
||
186 | */ |
||
187 | public function wpml_widget_text( $text, $instance = null, $widget = null ) { |
||
200 | |||
201 | /** |
||
202 | * Compatibility for WP Page Widget plugin |
||
203 | * |
||
204 | * @uses add_action() |
||
205 | * |
||
206 | * @return void |
||
207 | * @since 2.0.0 |
||
208 | */ |
||
209 | public function wp_page_widget() { |
||
212 | |||
213 | /** |
||
214 | * Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+) |
||
215 | * |
||
216 | * @uses add_filter() |
||
217 | * @uses add_action() |
||
218 | * @uses is_plugin_active() |
||
219 | * @uses get_bloginfo() |
||
220 | * |
||
221 | * @return void |
||
222 | * @since 2.0.0 |
||
223 | */ |
||
224 | public function wp_page_widget_admin_init() { |
||
230 | |||
231 | /** |
||
232 | * Enable filter for WP Page Widget plugin |
||
233 | * |
||
234 | * @param string[] $pages |
||
235 | * @return string[] |
||
236 | * @since 2.0.0 |
||
237 | */ |
||
238 | public function wp_page_widget_enable_pages( $pages ) { |
||
249 | |||
250 | /** |
||
251 | * Enqueue script for WP Page Widget plugin |
||
252 | * |
||
253 | * @uses apply_filters() |
||
254 | * @uses wp_enqueue_script() |
||
255 | * @uses plugins_url() |
||
256 | * @uses SCRIPT_DEBUG |
||
257 | * |
||
258 | * @return void |
||
259 | * @since 2.0.0 |
||
260 | */ |
||
261 | public function wp_page_widget_enqueue_script() { |
||
273 | |||
274 | /** |
||
275 | * Compatibility with Page Builder (SiteOrigin Panels) |
||
276 | * |
||
277 | * @uses add_action() |
||
278 | * |
||
279 | * @return void |
||
280 | * @since 2.0.0 |
||
281 | */ |
||
282 | public function siteorigin_panels() { |
||
286 | |||
287 | /** |
||
288 | * Initialize compatibility for Page Builder (SiteOrigin Panels) |
||
289 | * |
||
290 | * @uses add_filter() |
||
291 | * @uses add_action() |
||
292 | * @uses remove_filter() |
||
293 | * @uses add_action() |
||
294 | * @uses is_plugin_active() |
||
295 | * |
||
296 | * @return void |
||
297 | * @since 2.0.0 |
||
298 | */ |
||
299 | public function siteorigin_panels_admin_init() { |
||
309 | |||
310 | /** |
||
311 | * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation |
||
312 | * |
||
313 | * @param object $the_widget |
||
314 | * @return object |
||
315 | * @since 2.0.0 |
||
316 | */ |
||
317 | public function siteorigin_panels_widget_object( $the_widget ) { |
||
323 | |||
324 | /** |
||
325 | * Add selector for widget detection for Page Builder (SiteOrigin Panels) |
||
326 | * |
||
327 | * @param string[] $selectors |
||
328 | * @return string[] |
||
329 | * @since 2.0.0 |
||
330 | */ |
||
331 | public function siteorigin_panels_container_selectors( $selectors ) { |
||
335 | |||
336 | /** |
||
337 | * Add activate events for Page Builder (SiteOrigin Panels) |
||
338 | * |
||
339 | * @param string[] $events |
||
340 | * @return string[] |
||
341 | * @since 2.0.0 |
||
342 | */ |
||
343 | public function siteorigin_panels_activate_events( $events ) { |
||
347 | |||
348 | /** |
||
349 | * Add deactivate events for Page Builder (SiteOrigin Panels) |
||
350 | * |
||
351 | * @param string[] $events |
||
352 | * @return string[] |
||
353 | * @since 2.0.0 |
||
354 | */ |
||
355 | public function siteorigin_panels_deactivate_events( $events ) { |
||
359 | |||
360 | /** |
||
361 | * Add pages filter to enable editor for Page Builder (SiteOrigin Panels) |
||
362 | * |
||
363 | * @param string[] $pages |
||
364 | * @return string[] |
||
365 | * @since 2.0.0 |
||
366 | */ |
||
367 | public function siteorigin_panels_enable_pages( $pages ) { |
||
375 | |||
376 | /** |
||
377 | * Disable old compatibility code provided by Page Builder (SiteOrigin Panels) |
||
378 | * |
||
379 | * @return void |
||
380 | * @since 2.0.0 |
||
381 | */ |
||
382 | public function siteorigin_panels_disable_compat( ) { |
||
386 | |||
387 | /** |
||
388 | * Compatibility with Jetpack After the deadline |
||
389 | * |
||
390 | * @uses add_action() |
||
391 | * |
||
392 | * @return void |
||
393 | * @since 2.0.0 |
||
394 | */ |
||
395 | public function jetpack_after_the_deadline() { |
||
398 | |||
399 | /** |
||
400 | * Load Jetpack After the deadline scripts |
||
401 | * |
||
402 | * @uses add_filter() |
||
403 | * |
||
404 | * @return void |
||
405 | * @since 2.0.0 |
||
406 | */ |
||
407 | public function jetpack_after_the_deadline_load() { |
||
410 | |||
411 | /** |
||
412 | * Compatibility for Elementor plugin |
||
413 | * |
||
414 | * @uses add_filter() |
||
415 | * |
||
416 | * @return void |
||
417 | * @since 2.5.0 |
||
418 | */ |
||
419 | public function elementor() { |
||
424 | |||
425 | } // END class Black_Studio_TinyMCE_Compatibility_Plugins |
||
426 | |||
428 |