WP_Widget_Black_Studio_TinyMCE

The Black Studio TinyMCE Widget WP Widget Black Studio TinyMCE class.

Defined (1)

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

/includes/class-widget.php  
  1. class WP_Widget_Black_Studio_TinyMCE extends WP_Widget { 
  2.  
  3. /** 
  4. * Widget Class constructor 
  5. * @uses WP_Widget::__construct() 
  6. * @since 0.5 
  7. */ 
  8. public function __construct() { 
  9. /** translators: title of the widget */ 
  10. $widget_title = __( 'Visual Editor', 'black-studio-tinymce-widget' ); 
  11. /** translators: description of the widget, shown in available widgets */ 
  12. $widget_description = __( 'Arbitrary text or HTML with visual editor', 'black-studio-tinymce-widget' ); 
  13. $widget_ops = array( 'classname' => 'widget_black_studio_tinymce', 'description' => $widget_description ); 
  14. $control_ops = array( 'width' => 800, 'height' => 600 ); 
  15. parent::__construct( 'black-studio-tinymce', $widget_title, $widget_ops, $control_ops ); 
  16.  
  17. /** 
  18. * Output widget HTML code 
  19. * @uses apply_filters() 
  20. * @uses WP_Widget::$id_base 
  21. * @param string[] $args 
  22. * @param mixed[] $instance 
  23. * @return void 
  24. * @since 0.5 
  25. */ 
  26. public function widget( $args, $instance ) { 
  27. $before_widget = $args['before_widget']; 
  28. $after_widget = $args['after_widget']; 
  29. $before_title = $args['before_title']; 
  30. $after_title = $args['after_title']; 
  31. $before_text = apply_filters( 'black_studio_tinymce_before_text', '<div class="textwidget">', $instance ); 
  32. $after_text = apply_filters( 'black_studio_tinymce_after_text', '</div>', $instance ); 
  33. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); 
  34. $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance, $this ); 
  35. $hide_empty = apply_filters( 'black_studio_tinymce_hide_empty', false, $instance ); 
  36. if ( ! ( $hide_empty && empty( $text ) ) ) { 
  37. $output = $before_widget; 
  38. if ( ! empty( $title ) ) { 
  39. $output .= $before_title . $title . $after_title; 
  40. $output .= $before_text . $text . $after_text; 
  41. $output .= $after_widget; 
  42. echo $output; // xss ok 
  43.  
  44. /** 
  45. * Update widget data 
  46. * @uses current_user_can() 
  47. * @uses wp_filter_post_kses() 
  48. * @uses apply_filters() 
  49. * @param mixed[] $new_instance 
  50. * @param mixed[] $old_instance 
  51. * @return mixed[] 
  52. * @since 0.5 
  53. */ 
  54. public function update( $new_instance, $old_instance ) { 
  55. $instance = $old_instance; 
  56. $instance['title'] = strip_tags( $new_instance['title'] ); 
  57. if ( current_user_can( 'unfiltered_html' ) ) { 
  58. $instance['text'] = $new_instance['text']; 
  59. else { 
  60. $instance['text'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['text'] ) ) ); // wp_filter_post_kses() expects slashed 
  61. $instance['type'] = strip_tags( $new_instance['type'] ); 
  62. $instance['filter'] = strip_tags( $new_instance['filter'] ); 
  63. $instance = apply_filters( 'black_studio_tinymce_widget_update', $instance, $this ); 
  64. return $instance; 
  65.  
  66. /** 
  67. * Output widget form 
  68. * @uses wp_parse_args() 
  69. * @uses apply_filters() 
  70. * @uses esc_attr() 
  71. * @uses esc_textarea() 
  72. * @uses WP_Widget::get_field_id() 
  73. * @uses WP_Widget::get_field_name() 
  74. * @uses _e() 
  75. * @uses do_action() 
  76. * @uses apply_filters() 
  77. * @param mixed[] $instance 
  78. * @return void 
  79. * @since 0.5 
  80. */ 
  81. public function form( $instance ) { 
  82. global $wp_customize; 
  83. $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '', 'type' => 'visual' ) ); 
  84. // Force Visual mode in Customizer (to avoid glitches) 
  85. if ( $wp_customize ) { 
  86. $instance['type'] = 'visual'; 
  87. // Guess (wpautop) filter value for widgets created with previous version 
  88. if ( ! isset( $instance['filter'] ) ) { 
  89. $instance['filter'] = $instance['type'] == 'visual' && substr( $instance['text'], 0, 3 ) != '<p>' ? 1 : 0; 
  90. $title = strip_tags( $instance['title'] ); 
  91. do_action( 'black_studio_tinymce_before_editor' ); 
  92. ?> 
  93. <input id="<?php echo esc_attr( $this->get_field_id( 'type' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'type' ) ); ?>" type="hidden" value="<?php echo esc_attr( $instance['type'] ); ?>" /> 
  94. <p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:' ); ?></label> 
  95. <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p> 
  96. <?php 
  97. do_action( 'black_studio_tinymce_editor', $instance['text'], $this->get_field_id( 'text' ), $this->get_field_name( 'text' ), $instance['type'] ); 
  98. do_action( 'black_studio_tinymce_after_editor' ); 
  99. ?> 
  100. <input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>-hidden" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="hidden" value="0" /> 
  101. <p><input id="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'filter' ) ); ?>" type="checkbox" value="1" <?php checked( $instance['filter'] ); ?> /> <label for="<?php echo esc_attr( $this->get_field_id( 'filter' ) ); ?>"><?php _e( 'Automatically add paragraphs' ); ?></label></p> 
  102. <?php 
  103.  
  104. } // END class WP_Widget_Black_Studio_TinyMCE