Black_Studio_TinyMCE_Compatibility_Plugins

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

Defined (1)

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

/includes/class-compatibility-plugins.php  
  1. final class Black_Studio_TinyMCE_Compatibility_Plugins { 
  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. * @param string[] $plugins 
  13. * @return object 
  14. * @since 2.0.0 
  15. */ 
  16. public static function instance( $plugins = array() ) { 
  17. if ( is_null( self::$_instance ) ) { 
  18. self::$_instance = new self( $plugins ); 
  19. return self::$_instance; 
  20.  
  21. /** 
  22. * Class constructor 
  23. * @param string[] $plugins 
  24. * @since 2.0.0 
  25. */ 
  26. protected function __construct( $plugins ) { 
  27. foreach ( $plugins as $plugin ) { 
  28. if ( is_callable( array( $this, $plugin ), false ) ) { 
  29. $this->$plugin(); 
  30.  
  31. /** 
  32. * Prevent the class from being cloned 
  33. * @return void 
  34. * @since 2.0.0 
  35. */ 
  36. protected function __clone() { 
  37. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ uh?' ), '2.0' ); 
  38.  
  39. /** 
  40. * Compatibility with WPML 
  41. * @uses add_filter() 
  42. * @return void 
  43. * @since 2.0.0 
  44. */ 
  45. public function wpml() { 
  46. add_filter( 'black_studio_tinymce_widget_update', array( $this, 'wpml_widget_update' ), 10, 2 ); 
  47. add_filter( 'widget_text', array( $this, 'wpml_widget_text' ), 2, 3 ); 
  48.  
  49. /** 
  50. * Add widget text to WPML String translation 
  51. * @uses icl_register_string() Part of WPML 
  52. * @param mixed[] $instance 
  53. * @param object $widget 
  54. * @return mixed[] 
  55. * @since 2.0.0 
  56. */ 
  57. public function wpml_widget_update( $instance, $widget ) { 
  58. if ( function_exists( 'icl_register_string' ) && ! empty( $widget->number ) ) { 
  59. if ( ! isset( $instance['panels_info'] ) ) { // Avoid translation of Page Builder (SiteOrigin panels) widgets 
  60. icl_register_string( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $instance['text'] ); 
  61. return $instance; 
  62.  
  63. /** 
  64. * Translate widget text 
  65. * @uses icl_t() Part of WPML 
  66. * @param string $text 
  67. * @param mixed[]|null $instance 
  68. * @param object|null $widget 
  69. * @return string 
  70. * @since 2.0.0 
  71. */ 
  72. public function wpml_widget_text( $text, $instance = null, $widget = null ) { 
  73. if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { 
  74. if ( function_exists( 'icl_t' ) ) { 
  75. if ( ! isset( $instance['panels_info'] ) ) { // Avoid translation of Page Builder (SiteOrigin panels) widgets 
  76. $text = icl_t( 'Widgets', 'widget body - ' . $widget->id_base . '-' . $widget->number, $text ); 
  77. return $text; 
  78.  
  79. /** 
  80. * Compatibility for WP Page Widget plugin 
  81. * @uses add_action() 
  82. * @return void 
  83. * @since 2.0.0 
  84. */ 
  85. public function wp_page_widget() { 
  86. add_action( 'admin_init', array( $this, 'wp_page_widget_admin_init' ) ); 
  87.  
  88. /** 
  89. * Initialize compatibility for WP Page Widget plugin (only for WordPress 3.3+) 
  90. * @uses add_filter() 
  91. * @uses add_action() 
  92. * @uses is_plugin_active() 
  93. * @uses get_bloginfo() 
  94. * @return void 
  95. * @since 2.0.0 
  96. */ 
  97. public function wp_page_widget_admin_init() { 
  98. if ( is_admin() && is_plugin_active( 'wp-page-widget/wp-page-widgets.php' ) && version_compare( get_bloginfo( 'version' ), '3.3', '>=' ) ) { 
  99. add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'wp_page_widget_enable_pages' ) ); 
  100. add_action( 'admin_print_scripts', array( $this, 'wp_page_widget_enqueue_script' ) ); 
  101.  
  102. /** 
  103. * Enable filter for WP Page Widget plugin 
  104. * @param string[] $pages 
  105. * @return string[] 
  106. * @since 2.0.0 
  107. */ 
  108. public function wp_page_widget_enable_pages( $pages ) { 
  109. $pages[] = 'post-new.php'; 
  110. $pages[] = 'post.php'; 
  111. if ( isset( $_GET['action'] ) && 'edit' == $_GET['action'] ) { 
  112. $pages[] = 'edit-tags.php'; 
  113. if ( isset( $_GET['page'] ) && in_array( $_GET['page'], array( 'pw-front-page', 'pw-search-page' ) ) ) { 
  114. $pages[] = 'admin.php'; 
  115. return $pages; 
  116.  
  117. /** 
  118. * Enqueue script for WP Page Widget plugin 
  119. * @uses apply_filters() 
  120. * @uses wp_enqueue_script() 
  121. * @uses plugins_url() 
  122. * @uses SCRIPT_DEBUG 
  123. * @return void 
  124. * @since 2.0.0 
  125. */ 
  126. public function wp_page_widget_enqueue_script() { 
  127. $main_script = apply_filters( 'black-studio-tinymce-widget-script', 'black-studio-tinymce-widget' ); 
  128. $compat_script = 'wp-page-widget'; 
  129. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  130. wp_enqueue_script( 
  131. $compat_script,  
  132. plugins_url( 'js/' . $compat_script . $suffix . '.js', dirname( __FILE__ ) ),  
  133. array( 'jquery', 'editor', 'quicktags', $main_script ),  
  134. bstw()->get_version(),  
  135. true 
  136. ); 
  137.  
  138. /** 
  139. * Compatibility with Page Builder (SiteOrigin Panels) 
  140. * @uses add_action() 
  141. * @return void 
  142. * @since 2.0.0 
  143. */ 
  144. public function siteorigin_panels() { 
  145. add_action( 'admin_init', array( $this, 'siteorigin_panels_disable_compat' ), 7 ); 
  146. add_action( 'admin_init', array( $this, 'siteorigin_panels_admin_init' ) ); 
  147.  
  148. /** 
  149. * Initialize compatibility for Page Builder (SiteOrigin Panels) 
  150. * @uses add_filter() 
  151. * @uses add_action() 
  152. * @uses remove_filter() 
  153. * @uses add_action() 
  154. * @uses is_plugin_active() 
  155. * @return void 
  156. * @since 2.0.0 
  157. */ 
  158. public function siteorigin_panels_admin_init() { 
  159. if ( is_admin() && is_plugin_active( 'siteorigin-panels/siteorigin-panels.php' ) ) { 
  160. add_filter( 'siteorigin_panels_widget_object', array( $this, 'siteorigin_panels_widget_object' ), 10 ); 
  161. add_filter( 'black_studio_tinymce_container_selectors', array( $this, 'siteorigin_panels_container_selectors' ) ); 
  162. add_filter( 'black_studio_tinymce_activate_events', array( $this, 'siteorigin_panels_activate_events' ) ); 
  163. add_filter( 'black_studio_tinymce_deactivate_events', array( $this, 'siteorigin_panels_deactivate_events' ) ); 
  164. add_filter( 'black_studio_tinymce_enable_pages', array( $this, 'siteorigin_panels_enable_pages' ) ); 
  165. remove_filter( 'widget_text', array( bstw()->text_filters(), 'wpautop' ), 8 ); 
  166.  
  167. /** 
  168. * Remove widget number to prevent translation when using Page Builder (SiteOrigin Panels) + WPML String Translation 
  169. * @param object $the_widget 
  170. * @return object 
  171. * @since 2.0.0 
  172. */ 
  173. public function siteorigin_panels_widget_object( $the_widget ) { 
  174. if ( isset( $the_widget->id_base ) && 'black-studio-tinymce' == $the_widget->id_base ) { 
  175. $the_widget->number = ''; 
  176. return $the_widget; 
  177.  
  178. /** 
  179. * Add selector for widget detection for Page Builder (SiteOrigin Panels) 
  180. * @param string[] $selectors 
  181. * @return string[] 
  182. * @since 2.0.0 
  183. */ 
  184. public function siteorigin_panels_container_selectors( $selectors ) { 
  185. $selectors[] = 'div.panel-dialog'; 
  186. return $selectors; 
  187.  
  188. /** 
  189. * Add activate events for Page Builder (SiteOrigin Panels) 
  190. * @param string[] $events 
  191. * @return string[] 
  192. * @since 2.0.0 
  193. */ 
  194. public function siteorigin_panels_activate_events( $events ) { 
  195. $events[] = 'panelsopen'; 
  196. return $events; 
  197.  
  198. /** 
  199. * Add deactivate events for Page Builder (SiteOrigin Panels) 
  200. * @param string[] $events 
  201. * @return string[] 
  202. * @since 2.0.0 
  203. */ 
  204. public function siteorigin_panels_deactivate_events( $events ) { 
  205. $events[] = 'panelsdone'; 
  206. return $events; 
  207.  
  208. /** 
  209. * Add pages filter to enable editor for Page Builder (SiteOrigin Panels) 
  210. * @param string[] $pages 
  211. * @return string[] 
  212. * @since 2.0.0 
  213. */ 
  214. public function siteorigin_panels_enable_pages( $pages ) { 
  215. $pages[] = 'post-new.php'; 
  216. $pages[] = 'post.php'; 
  217. if ( isset( $_GET['page'] ) && 'so_panels_home_page' == $_GET['page'] ) { 
  218. $pages[] = 'themes.php'; 
  219. return $pages; 
  220.  
  221. /** 
  222. * Disable old compatibility code provided by Page Builder (SiteOrigin Panels) 
  223. * @return void 
  224. * @since 2.0.0 
  225. */ 
  226. public function siteorigin_panels_disable_compat( ) { 
  227. remove_action( 'admin_init', 'siteorigin_panels_black_studio_tinymce_admin_init' ); 
  228. remove_action( 'admin_enqueue_scripts', 'siteorigin_panels_black_studio_tinymce_admin_enqueue', 15 ); 
  229.  
  230. /** 
  231. * Compatibility with Jetpack After the deadline 
  232. * @uses add_action() 
  233. * @return void 
  234. * @since 2.0.0 
  235. */ 
  236. public function jetpack_after_the_deadline() { 
  237. add_action( 'black_studio_tinymce_load', array( $this, 'jetpack_after_the_deadline_load' ) ); 
  238.  
  239. /** 
  240. * Load Jetpack After the deadline scripts 
  241. * @uses add_filter() 
  242. * @return void 
  243. * @since 2.0.0 
  244. */ 
  245. public function jetpack_after_the_deadline_load() { 
  246. add_filter( 'atd_load_scripts', '__return_true' ); 
  247.  
  248. } // END class Black_Studio_TinyMCE_Compatibility_Plugins