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() { |
||
84 | |||
85 | /** |
||
86 | * Helper function to get WPML version |
||
87 | * |
||
88 | * @uses get_plugin_data() |
||
89 | * |
||
90 | * @return string |
||
91 | * @since 2.5.2 |
||
92 | */ |
||
93 | public function wpml_get_version() { |
||
97 | |||
98 | /** |
||
99 | * Initialize compatibility with WPML and WPML Widgets plugins |
||
100 | * |
||
101 | * @uses is_plugin_active() |
||
102 | * @uses has_action() |
||
103 | * @uses remove_action() |
||
104 | * |
||
105 | * @return void |
||
106 | * @since 2.3.1 |
||
107 | */ |
||
108 | public function wpml_init() { |
||
115 | |||
116 | /** |
||
117 | * Disable WPML String translation native behavior |
||
118 | * |
||
119 | * @uses remove_filter() |
||
120 | * |
||
121 | * @param mixed[] $args |
||
122 | * @param mixed[] $instance |
||
123 | * @return void |
||
124 | * @since 2.3.0 |
||
125 | */ |
||
126 | public function wpml_widget_before( $args, $instance ) { |
||
143 | |||
144 | /** |
||
145 | * Re-Enable WPML String translation native behavior |
||
146 | * |
||
147 | * @uses add_filter() |
||
148 | * |
||
149 | * @param mixed[] $args |
||
150 | * @param mixed[] $instance |
||
151 | * @return void |
||
152 | * @since 2.3.0 |
||
153 | */ |
||
154 | public function wpml_widget_after( $args, $instance ) { |
||
166 | |||
167 | /** |
||
168 | * Add widget text to WPML String translation |
||
169 | * |
||
170 | * @uses is_plugin_active() |
||
171 | * @uses icl_register_string() Part of WPML |
||
172 | * |
||
173 | * @param mixed[] $instance |
||
174 | * @param object $widget |
||
175 | * @return mixed[] |
||
176 | * @since 2.0.0 |
||
177 | */ |
||
178 | public function wpml_widget_update( $instance, $widget ) { |
||
192 | |||
193 | /** |
||
194 | * Translate widget text |
||
195 | * |
||
196 | * @uses is_plugin_active() |
||
197 | * @uses icl_t() Part of WPML |
||
198 | * @uses icl_st_is_registered_string() Part of WPML |
||
199 | * |
||
200 | * @param string $text |
||
201 | * @param mixed[]|null $instance |
||
202 | * @param object|null $widget |
||
203 | * @return string |
||
204 | * @since 2.0.0 |
||
205 | */ |
||
206 | public function wpml_widget_text( $text, $instance = null, $widget = null ) { |
||
221 | |||
222 | /** |
||
223 | * Check for existing deprecated translations (made with WPML String Translations plugin) and display warning |
||
224 | * |
||
225 | * @uses is_plugin_active() |
||
226 | * @uses icl_st_is_registered_string() Part of WPML |
||
227 | * @uses admin_url() |
||
228 | * |
||
229 | * @param mixed[]|null $instance |
||
230 | * @param object|null $widget |
||
231 | * @return void |
||
232 | * @since 2.5.2 |
||
233 | */ |
||
234 | public function wpml_check_deprecated_translations( $instance, $widget ) { |
||
247 | |||
248 | /** |
||
249 | * Compatibility for WP Page Widget plugin |
||
250 | * |
||
251 | * @uses add_action() |
||
252 | * |
||
253 | * @return void |
||
254 | * @since 2.0.0 |
||
255 | */ |
||
256 | public function wp_page_widget() { |
||
259 | |||
260 | /** |
||
261 | * Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+) |
||
262 | * |
||
263 | * @uses add_filter() |
||
264 | * @uses add_action() |
||
265 | * @uses is_plugin_active() |
||
266 | * @uses get_bloginfo() |
||
267 | * |
||
268 | * @return void |
||
269 | * @since 2.0.0 |
||
270 | */ |
||
271 | public function wp_page_widget_init() { |
||
278 | |||
279 | /** |
||
280 | * Enable filter for WP Page Widget plugin |
||
281 | * |
||
282 | * @param string[] $pages |
||
283 | * @return string[] |
||
284 | * @since 2.0.0 |
||
285 | */ |
||
286 | public function wp_page_widget_enable_pages( $pages ) { |
||
297 | |||
298 | /** |
||
299 | * Add WP Page Widget marker |
||
300 | * |
||
301 | * @param mixed[] $instance |
||
302 | * @param object $widget |
||
303 | * @return mixed[] |
||
304 | * @since 2.5.0 |
||
305 | */ |
||
306 | public function wp_page_widget_add_data( $instance, $widget ) { |
||
314 | |||
315 | /** |
||
316 | * Enqueue script for WP Page Widget plugin |
||
317 | * |
||
318 | * @uses apply_filters() |
||
319 | * @uses wp_enqueue_script() |
||
320 | * @uses plugins_url() |
||
321 | * @uses SCRIPT_DEBUG |
||
322 | * |
||
323 | * @return void |
||
324 | * @since 2.0.0 |
||
325 | */ |
||
326 | public function wp_page_widget_enqueue_script() { |
||
338 | |||
339 | /** |
||
340 | * Compatibility with Page Builder (SiteOrigin Panels) |
||
341 | * |
||
342 | * @uses add_action() |
||
343 | * |
||
344 | * @return void |
||
345 | * @since 2.0.0 |
||
346 | */ |
||
347 | public function siteorigin_panels() { |
||
351 | |||
352 | /** |
||
353 | * Initialize compatibility for Page Builder (SiteOrigin Panels) |
||
354 | * |
||
355 | * @uses add_filter() |
||
356 | * @uses add_action() |
||
357 | * @uses remove_filter() |
||
358 | * @uses add_action() |
||
359 | * @uses is_plugin_active() |
||
360 | * |
||
361 | * @return void |
||
362 | * @since 2.0.0 |
||
363 | */ |
||
364 | public function siteorigin_panels_admin_init() { |
||
375 | |||
376 | /** |
||
377 | * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation |
||
378 | * |
||
379 | * @param object $widget |
||
380 | * @return object |
||
381 | * @since 2.0.0 |
||
382 | */ |
||
383 | public function siteorigin_panels_widget_object( $widget ) { |
||
389 | |||
390 | /** |
||
391 | * Add selector for widget detection for Page Builder (SiteOrigin Panels) |
||
392 | * |
||
393 | * @param string[] $selectors |
||
394 | * @return string[] |
||
395 | * @since 2.0.0 |
||
396 | */ |
||
397 | public function siteorigin_panels_container_selectors( $selectors ) { |
||
401 | |||
402 | /** |
||
403 | * Add activate events for Page Builder (SiteOrigin Panels) |
||
404 | * |
||
405 | * @param string[] $events |
||
406 | * @return string[] |
||
407 | * @since 2.0.0 |
||
408 | */ |
||
409 | public function siteorigin_panels_activate_events( $events ) { |
||
413 | |||
414 | /** |
||
415 | * Add deactivate events for Page Builder (SiteOrigin Panels) |
||
416 | * |
||
417 | * @param string[] $events |
||
418 | * @return string[] |
||
419 | * @since 2.0.0 |
||
420 | */ |
||
421 | public function siteorigin_panels_deactivate_events( $events ) { |
||
425 | |||
426 | /** |
||
427 | * Add pages filter to enable editor for Page Builder (SiteOrigin Panels) |
||
428 | * |
||
429 | * @param string[] $pages |
||
430 | * @return string[] |
||
431 | * @since 2.0.0 |
||
432 | */ |
||
433 | public function siteorigin_panels_enable_pages( $pages ) { |
||
441 | |||
442 | /** |
||
443 | * Add widget field for Page Builder (SiteOrigin Panels) |
||
444 | * |
||
445 | * @param mixed[] $instance |
||
446 | * @param object $widget |
||
447 | * @return mixed[] |
||
448 | * @since 2.5.2 |
||
449 | */ |
||
450 | public function siteorigin_panels_additional_fields( $fields ) { |
||
454 | |||
455 | /** |
||
456 | * Disable old compatibility code provided by Page Builder (SiteOrigin Panels) |
||
457 | * |
||
458 | * @return void |
||
459 | * @since 2.0.0 |
||
460 | */ |
||
461 | public function siteorigin_panels_disable_compat( ) { |
||
465 | |||
466 | /** |
||
467 | * Compatibility with Jetpack After the deadline |
||
468 | * |
||
469 | * @uses add_action() |
||
470 | * |
||
471 | * @return void |
||
472 | * @since 2.0.0 |
||
473 | */ |
||
474 | public function jetpack_after_the_deadline() { |
||
477 | |||
478 | /** |
||
479 | * Load Jetpack After the deadline scripts |
||
480 | * |
||
481 | * @uses add_filter() |
||
482 | * |
||
483 | * @return void |
||
484 | * @since 2.0.0 |
||
485 | */ |
||
486 | public function jetpack_after_the_deadline_load() { |
||
489 | |||
490 | /** |
||
491 | * Compatibility for Elementor plugin |
||
492 | * |
||
493 | * @uses add_filter() |
||
494 | * |
||
495 | * @return void |
||
496 | * @since 2.5.0 |
||
497 | */ |
||
498 | public function elementor() { |
||
504 | |||
505 | /** |
||
506 | * Unregister Widget for Elementor plugin |
||
507 | * |
||
508 | * @uses unregister_widget() |
||
509 | * |
||
510 | * @return void |
||
511 | * @since 2.5.1 |
||
512 | */ |
||
513 | public function elementor_unregister_widget() { |
||
516 | |||
517 | } // END class Black_Studio_TinyMCE_Compatibility_Plugins |
||
518 | |||
520 |