Black_Studio_TinyMCE_Text_Filters

The Black Studio TinyMCE Widget Black Studio TinyMCE Text Filters class.

Defined (1)

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

/includes/class-text-filters.php  
  1. final class Black_Studio_TinyMCE_Text_Filters { 
  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 add_filter() 
  23. * @uses get_option() 
  24. * @global object $wp_embed 
  25. * @since 2.0.0 
  26. */ 
  27. protected function __construct() { 
  28. // Support for autoembed urls in widget text 
  29. if ( get_option( 'embed_autourls' ) ) { 
  30. add_filter( 'widget_text', array( $this, 'autoembed' ), 4, 3 ); 
  31. // Support for smilies in widget text 
  32. if ( get_option( 'use_smilies' ) ) { 
  33. add_filter( 'widget_text', array( $this, 'convert_smilies' ), 6, 3 ); 
  34. // Support for wpautop in widget text 
  35. add_filter( 'widget_text', array( $this, 'wpautop' ), 8, 3 ); 
  36. // Support for shortcodes in widget text 
  37. add_filter( 'widget_text', array( $this, 'do_shortcode' ), 10, 3 ); 
  38.  
  39. /** 
  40. * Prevent the class from being cloned 
  41. * @return void 
  42. * @since 2.0.0 
  43. */ 
  44. protected function __clone() { 
  45. _doing_it_wrong( __FUNCTION__, __( 'Cheatin’ uh?' ), '2.0' ); 
  46.  
  47. /** 
  48. * Apply wp_kses to widget text 
  49. * @uses wp_kses_post() 
  50. * @param string $text 
  51. * @return string 
  52. * @since 2.0.0 
  53. * @deprecated 2.0.3 
  54. */ 
  55. public function wp_kses_post( $text, $instance = null, $widget = null ) { 
  56. _deprecated_function( __METHOD__, '2.0.3' ); 
  57. if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { 
  58. $text = wp_kses_post( $text ); 
  59. return $text; 
  60.  
  61. /** 
  62. * Apply auto_embed to widget text 
  63. * @param string $text 
  64. * @return string 
  65. * @since 2.0.0 
  66. */ 
  67. public function autoembed( $text, $instance = null, $widget = null ) { 
  68. if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { 
  69. global $wp_embed; 
  70. $text = $wp_embed->run_shortcode( $text ); 
  71. $text = $wp_embed->autoembed( $text ); 
  72. return $text; 
  73.  
  74. /** 
  75. * Apply smilies conversion to widget text 
  76. * @uses convert_smilies() 
  77. * @param string $text 
  78. * @return string 
  79. * @since 2.0.0 
  80. */ 
  81. public function convert_smilies( $text, $instance = null, $widget = null ) { 
  82. if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { 
  83. $text = convert_smilies( $text ); 
  84. return $text; 
  85.  
  86. /** 
  87. * Check if automatic addition of paragraphs in widget text is needed 
  88. * @uses apply_filters() 
  89. * @param mixed[] $instance 
  90. * @return boolean 
  91. * @since 2.1.0 
  92. */ 
  93. public function need_wpautop( $instance ) { 
  94. // Widgets created with previous plugin versions do not have the filter parameter set so we base the choice on the type and text fields 
  95. $need_wpautop = $instance['type'] == 'visual' && substr( $instance['text'], 0, 3 ) != '<p>'; 
  96. if ( isset( $instance['filter'] ) ) { 
  97. $need_wpautop = $instance['filter'] == 1; 
  98. $need_wpautop = apply_filters( 'black_studio_tinymce_need_wpautop', $need_wpautop, $instance ); 
  99. return $need_wpautop; 
  100.  
  101. /** 
  102. * Apply automatic paragraphs in widget text 
  103. * @uses wpautop() 
  104. * @param string $text 
  105. * @param mixed[]|null $instance 
  106. * @param object|null $widget 
  107. * @return string 
  108. * @since 2.0.0 
  109. */ 
  110. public function wpautop( $text, $instance = null, $widget = null ) { 
  111. if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { 
  112. if ( $this->need_wpautop( $instance ) ) { 
  113. $text = wpautop( $text ); 
  114. return $text; 
  115.  
  116. /** 
  117. * Process shortcodes in widget text 
  118. * @uses do_shortcode() 
  119. * @param string $text 
  120. * @return string 
  121. * @since 2.0.0 
  122. */ 
  123. public function do_shortcode( $text, $instance = null, $widget = null ) { 
  124. if ( bstw()->check_widget( $widget ) && ! empty( $instance ) ) { 
  125. $text = do_shortcode( $text ); 
  126. return $text; 
  127.  
  128. } // END class Black_Studio_TinyMCE_Text_Filters