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 ) { |
||
175 | |||
176 | /** |
||
177 | * Translate widget text |
||
178 | * |
||
179 | * @uses is_plugin_active() |
||
180 | * @uses icl_t() Part of WPML |
||
181 | * |
||
182 | * @param string $text |
||
183 | * @param mixed[]|null $instance |
||
184 | * @param object|null $widget |
||
185 | * @return string |
||
186 | * @since 2.0.0 |
||
187 | */ |
||
188 | public function wpml_widget_text( $text, $instance = null, $widget = null ) { |
||
201 | |||
202 | /** |
||
203 | * Compatibility for WP Page Widget plugin |
||
204 | * |
||
205 | * @uses add_action() |
||
206 | * |
||
207 | * @return void |
||
208 | * @since 2.0.0 |
||
209 | */ |
||
210 | public function wp_page_widget() { |
||
213 | |||
214 | /** |
||
215 | * Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+) |
||
216 | * |
||
217 | * @uses add_filter() |
||
218 | * @uses add_action() |
||
219 | * @uses is_plugin_active() |
||
220 | * @uses get_bloginfo() |
||
221 | * |
||
222 | * @return void |
||
223 | * @since 2.0.0 |
||
224 | */ |
||
225 | public function wp_page_widget_init() { |
||
232 | |||
233 | /** |
||
234 | * Enable filter for WP Page Widget plugin |
||
235 | * |
||
236 | * @param string[] $pages |
||
237 | * @return string[] |
||
238 | * @since 2.0.0 |
||
239 | */ |
||
240 | public function wp_page_widget_enable_pages( $pages ) { |
||
251 | |||
252 | /** |
||
253 | * Add WP Page Widget marker |
||
254 | * |
||
255 | * @param mixed[] $instance |
||
256 | * @param object $widget |
||
257 | * @return mixed[] |
||
258 | * @since 2.5.0 |
||
259 | */ |
||
260 | public function wp_page_widget_add_data( $instance, $widget ) { |
||
268 | |||
269 | /** |
||
270 | * Enqueue script for WP Page Widget plugin |
||
271 | * |
||
272 | * @uses apply_filters() |
||
273 | * @uses wp_enqueue_script() |
||
274 | * @uses plugins_url() |
||
275 | * @uses SCRIPT_DEBUG |
||
276 | * |
||
277 | * @return void |
||
278 | * @since 2.0.0 |
||
279 | */ |
||
280 | public function wp_page_widget_enqueue_script() { |
||
292 | |||
293 | /** |
||
294 | * Compatibility with Page Builder (SiteOrigin Panels) |
||
295 | * |
||
296 | * @uses add_action() |
||
297 | * |
||
298 | * @return void |
||
299 | * @since 2.0.0 |
||
300 | */ |
||
301 | public function siteorigin_panels() { |
||
305 | |||
306 | /** |
||
307 | * Initialize compatibility for Page Builder (SiteOrigin Panels) |
||
308 | * |
||
309 | * @uses add_filter() |
||
310 | * @uses add_action() |
||
311 | * @uses remove_filter() |
||
312 | * @uses add_action() |
||
313 | * @uses is_plugin_active() |
||
314 | * |
||
315 | * @return void |
||
316 | * @since 2.0.0 |
||
317 | */ |
||
318 | public function siteorigin_panels_admin_init() { |
||
328 | |||
329 | /** |
||
330 | * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation |
||
331 | * |
||
332 | * @param object $widget |
||
333 | * @return object |
||
334 | * @since 2.0.0 |
||
335 | */ |
||
336 | public function siteorigin_panels_widget_object( $widget ) { |
||
342 | |||
343 | /** |
||
344 | * Add selector for widget detection for Page Builder (SiteOrigin Panels) |
||
345 | * |
||
346 | * @param string[] $selectors |
||
347 | * @return string[] |
||
348 | * @since 2.0.0 |
||
349 | */ |
||
350 | public function siteorigin_panels_container_selectors( $selectors ) { |
||
354 | |||
355 | /** |
||
356 | * Add activate events for Page Builder (SiteOrigin Panels) |
||
357 | * |
||
358 | * @param string[] $events |
||
359 | * @return string[] |
||
360 | * @since 2.0.0 |
||
361 | */ |
||
362 | public function siteorigin_panels_activate_events( $events ) { |
||
366 | |||
367 | /** |
||
368 | * Add deactivate events for Page Builder (SiteOrigin Panels) |
||
369 | * |
||
370 | * @param string[] $events |
||
371 | * @return string[] |
||
372 | * @since 2.0.0 |
||
373 | */ |
||
374 | public function siteorigin_panels_deactivate_events( $events ) { |
||
378 | |||
379 | /** |
||
380 | * Add pages filter to enable editor for Page Builder (SiteOrigin Panels) |
||
381 | * |
||
382 | * @param string[] $pages |
||
383 | * @return string[] |
||
384 | * @since 2.0.0 |
||
385 | */ |
||
386 | public function siteorigin_panels_enable_pages( $pages ) { |
||
394 | |||
395 | /** |
||
396 | * Disable old compatibility code provided by Page Builder (SiteOrigin Panels) |
||
397 | * |
||
398 | * @return void |
||
399 | * @since 2.0.0 |
||
400 | */ |
||
401 | public function siteorigin_panels_disable_compat( ) { |
||
405 | |||
406 | /** |
||
407 | * Compatibility with Jetpack After the deadline |
||
408 | * |
||
409 | * @uses add_action() |
||
410 | * |
||
411 | * @return void |
||
412 | * @since 2.0.0 |
||
413 | */ |
||
414 | public function jetpack_after_the_deadline() { |
||
417 | |||
418 | /** |
||
419 | * Load Jetpack After the deadline scripts |
||
420 | * |
||
421 | * @uses add_filter() |
||
422 | * |
||
423 | * @return void |
||
424 | * @since 2.0.0 |
||
425 | */ |
||
426 | public function jetpack_after_the_deadline_load() { |
||
429 | |||
430 | /** |
||
431 | * Compatibility for Elementor plugin |
||
432 | * |
||
433 | * @uses add_filter() |
||
434 | * |
||
435 | * @return void |
||
436 | * @since 2.5.0 |
||
437 | */ |
||
438 | public function elementor() { |
||
443 | |||
444 | } // END class Black_Studio_TinyMCE_Compatibility_Plugins |
||
445 | |||
447 |