Complex classes like Black_Studio_TinyMCE_Compatibility_WordPress 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_WordPress, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 21 | final class Black_Studio_TinyMCE_Compatibility_WordPress { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The single instance of the class |
||
| 25 | * |
||
| 26 | * @var object |
||
| 27 | * @since 2.0.0 |
||
| 28 | */ |
||
| 29 | protected static $_instance = null; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Return the single class instance |
||
| 33 | * |
||
| 34 | * @return object |
||
| 35 | * @since 2.0.0 |
||
| 36 | */ |
||
| 37 | public static function instance() { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Class constructor |
||
| 46 | * |
||
| 47 | * @uses get_bloginfo() |
||
| 48 | * @uses add_action() |
||
| 49 | * |
||
| 50 | * @since 2.0.0 |
||
| 51 | */ |
||
| 52 | protected function __construct() { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Prevent the class from being cloned |
||
| 64 | * |
||
| 65 | * @return void |
||
| 66 | * @since 2.0.0 |
||
| 67 | */ |
||
| 68 | protected function __clone() { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Compatibility for WordPress prior to 3.2 |
||
| 74 | * |
||
| 75 | * @uses remove_action() |
||
| 76 | * @uses add_action() |
||
| 77 | * |
||
| 78 | * @return void |
||
| 79 | * @since 2.0.0 |
||
| 80 | */ |
||
| 81 | public function wp_pre_32() { |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Enqueue footer scripts for WordPress prior to 3.2 |
||
| 90 | * |
||
| 91 | * @uses wp_tiny_mce() |
||
| 92 | * @uses wp_tiny_mce_preload_dialogs() |
||
| 93 | * |
||
| 94 | * @return void |
||
| 95 | * @since 2.0.0 |
||
| 96 | */ |
||
| 97 | public function wp_pre_32_admin_print_footer_scripts() { |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Compatibility for WordPress prior to 3.3 |
||
| 108 | * |
||
| 109 | * @uses add_filter() |
||
| 110 | * @uses add_action() |
||
| 111 | * @uses remove_action() |
||
| 112 | * @uses get_bloginfo() |
||
| 113 | * |
||
| 114 | * @return void |
||
| 115 | * @since 2.0.0 |
||
| 116 | */ |
||
| 117 | public function wp_pre_33() { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Remove WP fullscreen mode and set the native tinyMCE fullscreen mode for WordPress prior to 3.3 |
||
| 139 | * |
||
| 140 | * @param mixed[] $settings Array of settings. |
||
| 141 | * @return mixed[] |
||
| 142 | * @since 2.0.0 |
||
| 143 | */ |
||
| 144 | public function wp_pre_33_tiny_mce_before_init( $settings ) { |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Enqueue styles for WordPress prior to 3.3 |
||
| 158 | * |
||
| 159 | * @uses wp_enqueue_style() |
||
| 160 | * @uses Black_Studio_TinyMCE_Admin::enqueue_style() |
||
| 161 | * |
||
| 162 | * @return void |
||
| 163 | * @since 2.0.0 |
||
| 164 | */ |
||
| 165 | public function wp_pre_33_admin_print_styles() { |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Enqueue header scripts for WordPress prior to 3.3 |
||
| 173 | * |
||
| 174 | * @uses wp_enqueue_script() |
||
| 175 | * @uses Black_Studio_TinyMCE_Admin::enqueue_script() |
||
| 176 | * @uses Black_Studio_TinyMCE_Admin::localize_script() |
||
| 177 | * |
||
| 178 | * @return void |
||
| 179 | * @since 2.0.0 |
||
| 180 | */ |
||
| 181 | public function wp_pre_33_admin_print_scripts() { |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Filter to enqueue style / script for WordPress prior to 3.3 |
||
| 189 | * |
||
| 190 | * @return string |
||
| 191 | * @since 2.0.0 |
||
| 192 | */ |
||
| 193 | public function wp_pre_33_handle() { |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Enqueue footer scripts for WordPress prior to 3.3 |
||
| 199 | * |
||
| 200 | * @uses wp_tiny_mce() |
||
| 201 | * @uses wp_preload_dialog() |
||
| 202 | * |
||
| 203 | * @return void |
||
| 204 | * @since 2.0.0 |
||
| 205 | */ |
||
| 206 | public function wp_pre_33_admin_print_footer_scripts() { |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Compatibility for WordPress prior to 3.5 |
||
| 217 | * |
||
| 218 | * @uses add_filter() |
||
| 219 | * @uses Black_Studio_TinyMCE_Admin::enabled() |
||
| 220 | * |
||
| 221 | * @return void |
||
| 222 | * @since 2.0.0 |
||
| 223 | */ |
||
| 224 | public function wp_pre_35() { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Enable full media options in upload dialog for WordPress prior to 3.5 |
||
| 232 | * (this is done excluding post_id parameter in Thickbox iframe url) |
||
| 233 | * |
||
| 234 | * @global string $pagenow |
||
| 235 | * @param string $upload_iframe_src Source of the iframe for the upload dialog. |
||
| 236 | * @return string |
||
| 237 | * @since 2.0.0 |
||
| 238 | */ |
||
| 239 | public function wp_pre_35_upload_iframe_src( $upload_iframe_src ) { |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Compatibility for WordPress prior to 3.9 |
||
| 249 | * |
||
| 250 | * @uses add_action() |
||
| 251 | * @uses remove_action() |
||
| 252 | * @uses add_filter() |
||
| 253 | * @uses get_bloginfo() |
||
| 254 | * @uses Black_Studio_TinyMCE_Admin::enabled() |
||
| 255 | * |
||
| 256 | * @return void |
||
| 257 | * @since 2.0.0 |
||
| 258 | */ |
||
| 259 | public function wp_pre_39() { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Filter to enqueue style / script for WordPress prior to 3.9 |
||
| 279 | * |
||
| 280 | * @return string |
||
| 281 | * @since 2.0.0 |
||
| 282 | */ |
||
| 283 | public function wp_pre_39_handle() { |
||
| 286 | |||
| 287 | /** |
||
| 288 | * TinyMCE initialization for WordPress prior to 3.9 |
||
| 289 | * |
||
| 290 | * @param mixed[] $settings Array of settings. |
||
| 291 | * @return mixed[] |
||
| 292 | * @since 2.0.0 |
||
| 293 | */ |
||
| 294 | public function wp_pre_39_tiny_mce_before_init( $settings ) { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * Enqueue footer scripts for WordPress prior to 3.9 |
||
| 310 | * |
||
| 311 | * @uses wp_editor() |
||
| 312 | * |
||
| 313 | * @return void |
||
| 314 | * @since 2.0.0 |
||
| 315 | */ |
||
| 316 | public function wp_pre_39_admin_print_footer_scripts() { |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Output the visual editor code for WordPress prior to 3.9 |
||
| 324 | * |
||
| 325 | * @uses esc_attr() |
||
| 326 | * @uses esc_textarea() |
||
| 327 | * @uses do_action() |
||
| 328 | * |
||
| 329 | * @param string $text Widget text. |
||
| 330 | * @param string $id Widget ID. |
||
| 331 | * @param string $name Widget name. |
||
| 332 | * @param string $type Widget type. |
||
| 333 | * @return void |
||
| 334 | * @since 2.0.0 |
||
| 335 | */ |
||
| 336 | public function wp_pre_39_editor( $text, $id, $name = '', $type = 'visual' ) { |
||
| 355 | |||
| 356 | } // END class Black_Studio_TinyMCE_Compatibility_Wordpress |
||
| 357 | |||
| 359 |