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 | * Flag to keep track of removed WPML filter on widget title |
||
29 | * |
||
30 | * @var boolean |
||
31 | * @since 2.6.1 |
||
32 | */ |
||
33 | private $wpml_removed_widget_title_filter = false; |
||
34 | |||
35 | /** |
||
36 | * Flag to keep track of removed WPML filter on widget text |
||
37 | * |
||
38 | * @var boolean |
||
39 | * @since 2.6.1 |
||
40 | */ |
||
41 | private $wpml_removed_widget_text_filter = false; |
||
42 | |||
43 | /** |
||
44 | * Return the single class instance |
||
45 | * |
||
46 | * @param string[] $plugins |
||
47 | * @return object |
||
48 | * @since 2.0.0 |
||
49 | */ |
||
50 | public static function instance( $plugins = array() ) { |
||
56 | |||
57 | /** |
||
58 | * Class constructor |
||
59 | * |
||
60 | * @param string[] $plugins |
||
61 | * @since 2.0.0 |
||
62 | */ |
||
63 | protected function __construct( $plugins ) { |
||
73 | |||
74 | /** |
||
75 | * Prevent the class from being cloned |
||
76 | * |
||
77 | * @return void |
||
78 | * @since 2.0.0 |
||
79 | */ |
||
80 | protected function __clone() { |
||
83 | |||
84 | /** |
||
85 | * Compatibility with WPML |
||
86 | * |
||
87 | * @uses add_filter() |
||
88 | * |
||
89 | * @return void |
||
90 | * @since 2.0.0 |
||
91 | */ |
||
92 | public function wpml() { |
||
100 | |||
101 | /** |
||
102 | * Helper function to get WPML version |
||
103 | * |
||
104 | * @uses get_plugin_data() |
||
105 | * |
||
106 | * @return string |
||
107 | * @since 2.6.0 |
||
108 | */ |
||
109 | public function wpml_get_version() { |
||
113 | |||
114 | /** |
||
115 | * Initialize compatibility with WPML and WPML Widgets plugins |
||
116 | * |
||
117 | * @uses is_plugin_active() |
||
118 | * @uses has_action() |
||
119 | * @uses remove_action() |
||
120 | * |
||
121 | * @return void |
||
122 | * @since 2.3.1 |
||
123 | */ |
||
124 | public function wpml_init() { |
||
131 | |||
132 | /** |
||
133 | * Disable WPML String translation native behavior |
||
134 | * |
||
135 | * @uses remove_filter() |
||
136 | * |
||
137 | * @param mixed[] $args |
||
138 | * @param mixed[] $instance |
||
139 | * @return void |
||
140 | * @since 2.3.0 |
||
141 | */ |
||
142 | public function wpml_widget_before( $args, $instance ) { |
||
163 | |||
164 | /** |
||
165 | * Re-Enable WPML String translation native behavior |
||
166 | * |
||
167 | * @uses add_filter() |
||
168 | * |
||
169 | * @param mixed[] $args |
||
170 | * @param mixed[] $instance |
||
171 | * @return void |
||
172 | * @since 2.3.0 |
||
173 | */ |
||
174 | public function wpml_widget_after( $args, $instance ) { |
||
192 | |||
193 | /** |
||
194 | * Add widget text to WPML String translation |
||
195 | * |
||
196 | * @uses is_plugin_active() |
||
197 | * @uses icl_register_string() Part of WPML |
||
198 | * |
||
199 | * @param mixed[] $instance |
||
200 | * @param object $widget |
||
201 | * @return mixed[] |
||
202 | * @since 2.0.0 |
||
203 | */ |
||
204 | public function wpml_widget_update( $instance, $widget ) { |
||
218 | |||
219 | /** |
||
220 | * Translate widget text |
||
221 | * |
||
222 | * @uses is_plugin_active() |
||
223 | * @uses icl_t() Part of WPML |
||
224 | * @uses icl_st_is_registered_string() Part of WPML |
||
225 | * |
||
226 | * @param string $text |
||
227 | * @param mixed[]|null $instance |
||
228 | * @param object|null $widget |
||
229 | * @return string |
||
230 | * @since 2.0.0 |
||
231 | */ |
||
232 | public function wpml_widget_text( $text, $instance = null, $widget = null ) { |
||
247 | |||
248 | /** |
||
249 | * Check for existing deprecated translations (made with WPML String Translations plugin) and display warning |
||
250 | * |
||
251 | * @uses is_plugin_active() |
||
252 | * @uses icl_st_is_registered_string() Part of WPML |
||
253 | * @uses admin_url() |
||
254 | * |
||
255 | * @param mixed[]|null $instance |
||
256 | * @param object|null $widget |
||
257 | * @return void |
||
258 | * @since 2.6.0 |
||
259 | */ |
||
260 | public function wpml_check_deprecated_translations( $instance, $widget ) { |
||
273 | |||
274 | /** |
||
275 | * Compatibility for WP Page Widget plugin |
||
276 | * |
||
277 | * @uses add_action() |
||
278 | * |
||
279 | * @return void |
||
280 | * @since 2.0.0 |
||
281 | */ |
||
282 | public function wp_page_widget() { |
||
285 | |||
286 | /** |
||
287 | * Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+) |
||
288 | * |
||
289 | * @uses add_filter() |
||
290 | * @uses add_action() |
||
291 | * @uses is_plugin_active() |
||
292 | * @uses get_bloginfo() |
||
293 | * |
||
294 | * @return void |
||
295 | * @since 2.0.0 |
||
296 | */ |
||
297 | public function wp_page_widget_init() { |
||
304 | |||
305 | /** |
||
306 | * Enable filter for WP Page Widget plugin |
||
307 | * |
||
308 | * @param string[] $pages |
||
309 | * @return string[] |
||
310 | * @since 2.0.0 |
||
311 | */ |
||
312 | public function wp_page_widget_enable_pages( $pages ) { |
||
323 | |||
324 | /** |
||
325 | * Add WP Page Widget marker |
||
326 | * |
||
327 | * @param mixed[] $instance |
||
328 | * @param object $widget |
||
329 | * @return mixed[] |
||
330 | * @since 2.5.0 |
||
331 | */ |
||
332 | public function wp_page_widget_add_data( $instance, $widget ) { |
||
340 | |||
341 | /** |
||
342 | * Enqueue script for WP Page Widget plugin |
||
343 | * |
||
344 | * @uses apply_filters() |
||
345 | * @uses wp_enqueue_script() |
||
346 | * @uses plugins_url() |
||
347 | * @uses SCRIPT_DEBUG |
||
348 | * |
||
349 | * @return void |
||
350 | * @since 2.0.0 |
||
351 | */ |
||
352 | public function wp_page_widget_enqueue_script() { |
||
364 | |||
365 | /** |
||
366 | * Compatibility with Page Builder (SiteOrigin Panels) |
||
367 | * |
||
368 | * @uses add_action() |
||
369 | * |
||
370 | * @return void |
||
371 | * @since 2.0.0 |
||
372 | */ |
||
373 | public function siteorigin_panels() { |
||
377 | |||
378 | /** |
||
379 | * Initialize compatibility for Page Builder (SiteOrigin Panels) |
||
380 | * |
||
381 | * @uses add_filter() |
||
382 | * @uses add_action() |
||
383 | * @uses remove_filter() |
||
384 | * @uses add_action() |
||
385 | * @uses is_plugin_active() |
||
386 | * |
||
387 | * @return void |
||
388 | * @since 2.0.0 |
||
389 | */ |
||
390 | public function siteorigin_panels_admin_init() { |
||
401 | |||
402 | /** |
||
403 | * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation |
||
404 | * |
||
405 | * @param object $widget |
||
406 | * @return object |
||
407 | * @since 2.0.0 |
||
408 | */ |
||
409 | public function siteorigin_panels_widget_object( $widget ) { |
||
415 | |||
416 | /** |
||
417 | * Add selector for widget detection for Page Builder (SiteOrigin Panels) |
||
418 | * |
||
419 | * @param string[] $selectors |
||
420 | * @return string[] |
||
421 | * @since 2.0.0 |
||
422 | */ |
||
423 | public function siteorigin_panels_container_selectors( $selectors ) { |
||
427 | |||
428 | /** |
||
429 | * Add activate events for Page Builder (SiteOrigin Panels) |
||
430 | * |
||
431 | * @param string[] $events |
||
432 | * @return string[] |
||
433 | * @since 2.0.0 |
||
434 | */ |
||
435 | public function siteorigin_panels_activate_events( $events ) { |
||
439 | |||
440 | /** |
||
441 | * Add deactivate events for Page Builder (SiteOrigin Panels) |
||
442 | * |
||
443 | * @param string[] $events |
||
444 | * @return string[] |
||
445 | * @since 2.0.0 |
||
446 | */ |
||
447 | public function siteorigin_panels_deactivate_events( $events ) { |
||
451 | |||
452 | /** |
||
453 | * Add pages filter to enable editor for Page Builder (SiteOrigin Panels) |
||
454 | * |
||
455 | * @param string[] $pages |
||
456 | * @return string[] |
||
457 | * @since 2.0.0 |
||
458 | */ |
||
459 | public function siteorigin_panels_enable_pages( $pages ) { |
||
467 | |||
468 | /** |
||
469 | * Add widget field for Page Builder (SiteOrigin Panels) |
||
470 | * |
||
471 | * @param string[] fields |
||
472 | * @return string[] |
||
473 | * @since 2.6.0 |
||
474 | */ |
||
475 | public function siteorigin_panels_additional_fields( $fields ) { |
||
479 | |||
480 | /** |
||
481 | * Disable old compatibility code provided by Page Builder (SiteOrigin Panels) |
||
482 | * |
||
483 | * @return void |
||
484 | * @since 2.0.0 |
||
485 | */ |
||
486 | public function siteorigin_panels_disable_compat( ) { |
||
490 | |||
491 | /** |
||
492 | * Compatibility with Jetpack After the deadline |
||
493 | * |
||
494 | * @uses add_action() |
||
495 | * |
||
496 | * @return void |
||
497 | * @since 2.0.0 |
||
498 | */ |
||
499 | public function jetpack_after_the_deadline() { |
||
502 | |||
503 | /** |
||
504 | * Load Jetpack After the deadline scripts |
||
505 | * |
||
506 | * @uses add_filter() |
||
507 | * |
||
508 | * @return void |
||
509 | * @since 2.0.0 |
||
510 | */ |
||
511 | public function jetpack_after_the_deadline_load() { |
||
514 | |||
515 | /** |
||
516 | * Compatibility for Elementor plugin |
||
517 | * |
||
518 | * @uses add_filter() |
||
519 | * |
||
520 | * @return void |
||
521 | * @since 2.5.0 |
||
522 | */ |
||
523 | public function elementor() { |
||
529 | |||
530 | /** |
||
531 | * Unregister Widget for Elementor plugin |
||
532 | * |
||
533 | * @uses unregister_widget() |
||
534 | * |
||
535 | * @return void |
||
536 | * @since 2.5.1 |
||
537 | */ |
||
538 | public function elementor_unregister_widget() { |
||
541 | |||
542 | } // END class Black_Studio_TinyMCE_Compatibility_Plugins |
||
543 | |||
545 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.