Black_Studio_TinyMCE_Compatibility_WordPress

The Black Studio TinyMCE Widget Black Studio TinyMCE Compatibility WordPress class.

Defined (1)

The class is defined in the following location(s).

/includes/class-compatibility-wordpress.php  
  1. final class Black_Studio_TinyMCE_Compatibility_Wordpress { 
  2.  
  3. /** 
  4. * The single instance of the class 
  5. * @var object 
  6. * @since 2.0.0 
  7. */ 
  8. protected static $_instance = null; 
  9.  
  10. /** 
  11. * Return the single class instance 
  12. * @return object 
  13. * @since 2.0.0 
  14. */ 
  15. public static function instance() { 
  16. if ( is_null( self::$_instance ) ) { 
  17. self::$_instance = new self(); 
  18. return self::$_instance; 
  19.  
  20. /** 
  21. * Class constructor 
  22. * @uses get_bloginfo() 
  23. * @uses add_action() 
  24. * @since 2.0.0 
  25. */ 
  26. protected function __construct() { 
  27. $current_version = get_bloginfo( 'version' ); 
  28. $previous_versions = array( '3.2', '3.3', '3.5', '3.9' ); 
  29. foreach ( $previous_versions as $previous_version ) { 
  30. if ( version_compare( $current_version, $previous_version, '<' ) ) { 
  31. add_action( 'admin_init', array( $this, 'wp_pre_' . str_replace( '.', '', $previous_version ) ), intval( 10 * $previous_version ) ); 
  32.  
  33. /** 
  34. * Prevent the class from being cloned 
  35. * @return void 
  36. * @since 2.0.0 
  37. */ 
  38. protected function __clone() { 
  39. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ uh?' ), '2.0' ); 
  40.  
  41. /** 
  42. * Compatibility for WordPress prior to 3.2 
  43. * @uses remove_action() 
  44. * @uses add_action() 
  45. * @return void 
  46. * @since 2.0.0 
  47. */ 
  48. public function wp_pre_32() { 
  49. if ( bstw()->admin()->enabled() ) { 
  50. remove_action( 'admin_print_footer_scripts', array( bstw()->admin(), 'admin_print_footer_scripts' ) ); 
  51. add_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_32_admin_print_footer_scripts' ) ); 
  52.  
  53. /** 
  54. * Enqueue footer scripts for WordPress prior to 3.2 
  55. * @uses wp_tiny_mce() 
  56. * @uses wp_tiny_mce_preload_dialogs() 
  57. * @return void 
  58. * @since 2.0.0 
  59. */ 
  60. public function wp_pre_32_admin_print_footer_scripts() { 
  61. if ( function_exists( 'wp_tiny_mce' ) ) { 
  62. wp_tiny_mce( false, array() ); 
  63. if ( function_exists( 'wp_tiny_mce_preload_dialogs' ) ) { 
  64. wp_tiny_mce_preload_dialogs(); 
  65.  
  66. /** 
  67. * Compatibility for WordPress prior to 3.3 
  68. * @uses add_filter() 
  69. * @uses add_action() 
  70. * @uses remove_action() 
  71. * @uses get_bloginfo() 
  72. * @return void 
  73. * @since 2.0.0 
  74. */ 
  75. public function wp_pre_33() { 
  76. $wp_version = get_bloginfo( 'version' ); 
  77. if ( bstw()->admin()->enabled() ) { 
  78. add_filter( 'tiny_mce_before_init', array( $this, 'wp_pre_33_tiny_mce_before_init' ), 67 ); 
  79. add_filter( 'black-studio-tinymce-widget-script', array( $this, 'wp_pre_33_handle' ), 67 ); 
  80. add_filter( 'black-studio-tinymce-widget-style', array( $this, 'wp_pre_33_handle' ), 67 ); 
  81. remove_action( 'admin_print_styles', array( bstw()->admin(), 'admin_print_styles' ) ); 
  82. add_action( 'admin_print_styles', array( $this, 'wp_pre_33_admin_print_styles' ) ); 
  83. remove_action( 'admin_print_scripts', array( bstw()->admin(), 'admin_print_scripts' ) ); 
  84. add_action( 'admin_print_scripts', array( $this, 'wp_pre_33_admin_print_scripts' ) ); 
  85. remove_action( 'admin_print_footer_scripts', array( bstw()->admin(), 'admin_print_footer_scripts' ) ); 
  86. if ( ! version_compare( $wp_version, '3.2', '<' ) ) { 
  87. remove_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_32_admin_print_footer_scripts' ) ); 
  88. add_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_33_admin_print_footer_scripts' ) ); 
  89. remove_action( 'admin_print_scripts', array( bstw()->admin(), 'pointer_load' ) ); 
  90. remove_filter( 'black_studio_tinymce_admin_pointers-widgets', array( bstw()->admin(), 'pointer_register' ) ); 
  91.  
  92. /** 
  93. * Remove WP fullscreen mode and set the native tinyMCE fullscreen mode for WordPress prior to 3.3 
  94. * @param mixed[] $settings 
  95. * @return mixed[] 
  96. * @since 2.0.0 
  97. */ 
  98. public function wp_pre_33_tiny_mce_before_init( $settings ) { 
  99. $plugins = explode( ', ', $settings['plugins'] ); 
  100. if ( isset( $plugins['wpfullscreen'] ) ) { 
  101. unset( $plugins['wpfullscreen'] ); 
  102. if ( ! isset( $plugins['fullscreen'] ) ) { 
  103. $plugins[] = 'fullscreen'; 
  104. $settings['plugins'] = implode( ', ', $plugins ); 
  105. return $settings; 
  106.  
  107. /** 
  108. * Enqueue styles for WordPress prior to 3.3 
  109. * @uses wp_enqueue_style() 
  110. * @uses Black_Studio_TinyMCE_Admin::enqueue_style() 
  111. * @return void 
  112. * @since 2.0.0 
  113. */ 
  114. public function wp_pre_33_admin_print_styles() { 
  115. wp_enqueue_style( 'thickbox' ); 
  116. wp_enqueue_style( 'editor-buttons' ); 
  117. bstw()->admin()->enqueue_style(); 
  118.  
  119. /** 
  120. * Enqueue header scripts for WordPress prior to 3.3 
  121. * @uses wp_enqueue_script() 
  122. * @uses Black_Studio_TinyMCE_Admin::enqueue_script() 
  123. * @uses Black_Studio_TinyMCE_Admin::localize_script() 
  124. * @return void 
  125. * @since 2.0.0 
  126. */ 
  127. public function wp_pre_33_admin_print_scripts() { 
  128. wp_enqueue_script( 'media-upload' ); 
  129. bstw()->admin()->enqueue_script(); 
  130. bstw()->admin()->localize_script(); 
  131.  
  132. /** 
  133. * Filter to enqueue style / script for WordPress prior to 3.3 
  134. * @return string 
  135. * @since 2.0.0 
  136. */ 
  137. public function wp_pre_33_handle() { 
  138. return 'black-studio-tinymce-widget-pre33'; 
  139.  
  140. /** 
  141. * Enqueue footer scripts for WordPress prior to 3.3 
  142. * @uses wp_tiny_mce() 
  143. * @uses wp_preload_dialog() 
  144. * @return void 
  145. * @since 2.0.0 
  146. */ 
  147. public function wp_pre_33_admin_print_footer_scripts() { 
  148. if ( function_exists( 'wp_tiny_mce' ) ) { 
  149. wp_tiny_mce( false, array() ); 
  150. if ( function_exists( 'wp_preload_dialogs' ) ) { 
  151. wp_preload_dialogs( array( 'plugins' => 'wpdialogs, wplink, wpfullscreen' ) ); 
  152.  
  153. /** 
  154. * Compatibility for WordPress prior to 3.5 
  155. * @uses add_filter() 
  156. * @uses Black_Studio_TinyMCE_Admin::enabled() 
  157. * @return void 
  158. * @since 2.0.0 
  159. */ 
  160. public function wp_pre_35() { 
  161. if ( bstw()->admin()->enabled() ) { 
  162. add_filter( '_upload_iframe_src', array( $this, 'wp_pre_35_upload_iframe_src' ), 65 ); 
  163.  
  164. /** 
  165. * Enable full media options in upload dialog for WordPress prior to 3.5 
  166. * (this is done excluding post_id parameter in Thickbox iframe url) 
  167. * @global string $pagenow 
  168. * @param string $upload_iframe_src 
  169. * @return string 
  170. * @since 2.0.0 
  171. */ 
  172. public function wp_pre_35_upload_iframe_src( $upload_iframe_src ) { 
  173. global $pagenow; 
  174. if ( 'widgets.php' == $pagenow || ( 'admin-ajax.php' == $pagenow && isset( $_POST['id_base'] ) && 'black-studio-tinymce' == $_POST['id_base'] ) ) { 
  175. $upload_iframe_src = str_replace( 'post_id=0', '', $upload_iframe_src ); 
  176. return $upload_iframe_src; 
  177.  
  178. /** 
  179. * Compatibility for WordPress prior to 3.9 
  180. * @uses add_action() 
  181. * @uses remove_action() 
  182. * @uses add_filter() 
  183. * @uses get_bloginfo() 
  184. * @uses Black_Studio_TinyMCE_Admin::enabled() 
  185. * @return void 
  186. * @since 2.0.0 
  187. */ 
  188. public function wp_pre_39() { 
  189. $wp_version = get_bloginfo( 'version' ); 
  190. if ( bstw()->admin()->enabled() ) { 
  191. add_filter( 'black-studio-tinymce-widget-script', array( $this, 'wp_pre_39_handle' ), 61 ); 
  192. add_filter( 'tiny_mce_before_init', array( $this, 'wp_pre_39_tiny_mce_before_init' ), 61 ); 
  193. add_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_39_admin_print_footer_scripts' ) ); 
  194. remove_action( 'admin_print_footer_scripts', array( bstw()->admin(), 'admin_print_footer_scripts' ) ); 
  195. if ( ! version_compare( $wp_version, '3.2', '<' ) ) { 
  196. remove_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_32_admin_print_footer_scripts' ) ); 
  197. if ( ! version_compare( $wp_version, '3.3', '<' ) ) { 
  198. remove_action( 'admin_print_footer_scripts', array( $this, 'wp_pre_33_admin_print_footer_scripts' ) ); 
  199. add_action( 'black_studio_tinymce_editor', array( $this, 'wp_pre_39_editor' ), 10, 4 ); 
  200. remove_action( 'black_studio_tinymce_editor', array( bstw()->admin(), 'editor' ), 10, 3 ); 
  201.  
  202. /** 
  203. * Filter to enqueue style / script for WordPress prior to 3.9 
  204. * @return string 
  205. * @since 2.0.0 
  206. */ 
  207. public function wp_pre_39_handle() { 
  208. return 'black-studio-tinymce-widget-pre39'; 
  209.  
  210. /** 
  211. * TinyMCE initialization for WordPress prior to 3.9 
  212. * @param mixed[] $settings 
  213. * @return mixed[] 
  214. * @since 2.0.0 
  215. */ 
  216. public function wp_pre_39_tiny_mce_before_init( $settings ) { 
  217. $custom_settings = array( 
  218. 'remove_linebreaks' => false,  
  219. 'convert_newlines_to_brs' => false,  
  220. 'force_p_newlines' => true,  
  221. 'force_br_newlines' => false,  
  222. 'remove_redundant_brs' => false,  
  223. 'forced_root_block' => 'p',  
  224. 'apply_source_formatting' => true,  
  225. ); 
  226. // Return modified settings 
  227. return array_merge( $settings, $custom_settings ); 
  228.  
  229. /** 
  230. * Enqueue footer scripts for WordPress prior to 3.9 
  231. * @uses wp_editor() 
  232. * @return void 
  233. * @since 2.0.0 
  234. */ 
  235. public function wp_pre_39_admin_print_footer_scripts() { 
  236. if ( function_exists( 'wp_editor' ) ) { 
  237. wp_editor( '', 'black-studio-tinymce-widget' ); 
  238.  
  239. /** 
  240. * Output the visual editor code for WordPress prior to 3.9 
  241. * @uses esc_attr() 
  242. * @uses esc_textarea() 
  243. * @uses do_action() 
  244. * @return void 
  245. * @since 2.0.0 
  246. */ 
  247. public function wp_pre_39_editor( $text, $id, $name = '', $type = 'visual' ) { 
  248. $switch_class = $type == 'visual' ? 'html-active' : 'tmce-active'; 
  249. ?> 
  250. <div id="<?php echo esc_attr( $id ); ?>-wp-content-wrap" class="wp-core-ui wp-editor-wrap <?php echo esc_attr( $switch_class ); ?> has-dfw"> 
  251. <div id="<?php echo esc_attr( $id ); ?>-wp-content-editor-tools" class="wp-editor-tools hide-if-no-js"> 
  252. <div class="wp-editor-tabs"> 
  253. <a id="<?php echo esc_attr( $id ); ?>-content-html" class="wp-switch-editor switch-html"><?php _e( 'HTML' ); ?></a> 
  254. <a id="<?php echo esc_attr( $id ); ?>-content-tmce" class="wp-switch-editor switch-tmce"><?php _e( 'Visual' ); ?></a> 
  255. </div> 
  256. <div id="<?php esc_attr( $id ); ?>-wp-content-media-buttons" class="wp-media-buttons"> 
  257. <?php do_action( 'media_buttons', $id ); ?> 
  258. </div> 
  259. </div> 
  260. <div class="wp-editor-container"> 
  261. <textarea class="widefat" rows="20" cols="40" id="<?php echo esc_attr( $id ); ?>" name="<?php echo esc_attr( $name ); ?>"><?php echo esc_textarea( $text ); ?></textarea> 
  262. </div> 
  263. </div> 
  264. <?php 
  265.  
  266. } // END class Black_Studio_TinyMCE_Compatibility_Wordpress