Bpbbpst_Support_New_Support

Buddy-bbPress Support Topic new Support Topic widget.

Defined (1)

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

/includes/widgets.php  
  1. class Bpbbpst_Support_New_Support extends WP_Widget { 
  2. /** 
  3. * Buddy-bbPress Support Topic new support toppic widget 
  4. * @since 2.0 
  5. * @uses WP_Widget::__construct() to init the widget 
  6. * @uses add_filter() to filter bbPress topic query, breadcrumb and pagination 
  7. * @uses add_action() to enqueue widget style 
  8. */ 
  9. public function __construct() { 
  10.  
  11. $widget_ops = array( 'description' => __( 'Displays a short message to invite users to add a new support topic on support only forums', 'buddy-bbpress-support-topic' ) ); 
  12. $control_ops = array('width' => 400, 'height' => 200); 
  13. parent::__construct( false, $name = __( 'New Support Topic', 'buddy-bbpress-support-topic' ), $widget_ops, $control_ops ); 
  14.  
  15.  
  16. /** 
  17. * Register the widget 
  18. * @since 2.0 
  19. * @uses register_widget() to register the widget 
  20. */ 
  21. public static function register_widget() { 
  22. register_widget( 'Bpbbpst_Support_New_Support' ); 
  23.  
  24. /** 
  25. * Displays the output, the button to post new support topics 
  26. * @since 2.0 
  27. * @param mixed $args Arguments 
  28. * @param array $instance Instance 
  29. * @uses apply_filters() to let plugins or themes modify the value 
  30. * @uses do_action() to let plugins or themes run some actions from this point 
  31. * @uses esc_html() to sanitize the button caption 
  32. * @uses bbp_get_forum_permalink() to build link to forum 
  33. * @uses add_query_arg() to build the new topic url 
  34. * @uses wpautop() to automatically add paragraphs to text 
  35. * @return string html output 
  36. */ 
  37. public function widget( $args, $instance ) { 
  38. if ( empty( $instance['bpbbpst_title'] ) ) { 
  39. $instance['bpbbpst_title'] = __( 'New Support topic', 'buddy-bbpress-support-topic' ); 
  40.  
  41. if ( empty( $instance['bpbbpst_button'] ) ) { 
  42. $instance['bpbbpst_button'] = __( 'Ask for Support', 'buddy-bbpress-support-topic' ); 
  43.  
  44. if ( empty( $instance['bpbbpst_forum_id'] ) ) { 
  45. $instance['bpbbpst_forum_id'] = false; 
  46.  
  47. $text = apply_filters( 'widget_text', empty( $instance['bpbbpst_text'] ) ? '' : $instance['bpbbpst_text'], $instance ); 
  48.  
  49. do_action( 'bpbbpst_new_topic_widget_before_content' ); 
  50.  
  51. if ( empty( $instance['bpbbpst_forum_id'] ) ) { 
  52. return false; 
  53.  
  54. $widget_display = apply_filters( 'bpbbpst_new_topic_widget_display', true ); 
  55.  
  56. if ( empty( $widget_display ) ) { 
  57. return false; 
  58.  
  59. $button_caption = esc_html( $instance['bpbbpst_button'] ); 
  60. $forum_post_form_link = bbp_get_forum_permalink( $instance['bpbbpst_forum_id'] ); 
  61.  
  62. if ( ! empty( $instance['bpbbpst_referer'] ) ) { 
  63. $forum_post_form_link = add_query_arg( 'bpbbpst-referer', '1', $forum_post_form_link ); 
  64.  
  65. $forum_post_form_link .= '#bbp_topic_title'; 
  66.  
  67.  
  68. $html_link = '<a href="'. esc_url( $forum_post_form_link ) .'" title="'. $button_caption . '" class="button submit bpbbpst-btn">'. $button_caption. '</a>'; 
  69.  
  70. $a_link = apply_filters( 'bpbbpst_new_support_widget_button', $html_link, $forum_post_form_link, $button_caption ); 
  71.  
  72. echo $args['before_widget']; 
  73. echo $args['before_title'] . $instance['bpbbpst_title'] . $args['after_title']; ?> 
  74.  
  75. <div class="textwidget"> 
  76.  
  77. <?php echo ! empty( $instance['bpbbpst_filter'] ) ? wpautop( $text ) : $text; ?> 
  78.  
  79. </div> 
  80.  
  81. <div class="bpbbpst-action"> 
  82. <?php echo $a_link;?> 
  83. </div> 
  84.  
  85. <?php 
  86. do_action( 'bpbbpst_new_topic_widget_after_content' ); 
  87. echo $args['after_widget']; 
  88.  
  89. /** 
  90. * Update the new support topic widget options (title) 
  91. * @since 2.0 
  92. * @param array $new_instance The new instance options 
  93. * @param array $old_instance The old instance options 
  94. * @uses current_user_can() to check for current user's capabiility 
  95. * @uses wp_filter_post_kses() to sanitize the text 
  96. * @return array the instance 
  97. */ 
  98. public function update( $new_instance, $old_instance ) { 
  99. $instance = $old_instance; 
  100.  
  101. $instance['bpbbpst_title'] = strip_tags( $new_instance['bpbbpst_title'] ); 
  102. $instance['bpbbpst_button'] = strip_tags( $new_instance['bpbbpst_button'] ); 
  103.  
  104. if ( current_user_can('unfiltered_html') ) { 
  105. $instance['bpbbpst_text'] = $new_instance['bpbbpst_text']; 
  106. } else { 
  107. $instance['bpbbpst_text'] = stripslashes( wp_filter_post_kses( addslashes( $new_instance['bpbbpst_text'] ) ) ); 
  108.  
  109. $instance['bpbbpst_filter'] = isset( $new_instance['bpbbpst_filter'] ); 
  110. $instance['bpbbpst_forum_id'] = ! empty( $new_instance['bpbbpst_forum_id'] ) ? intval( $new_instance['bpbbpst_forum_id'] ) : 0; 
  111. $instance['bpbbpst_referer'] = isset( $new_instance['bpbbpst_referer'] ); 
  112.  
  113. return $instance; 
  114.  
  115. /** 
  116. * Output the new support topic widget options form 
  117. * @since 2.0 
  118. * @param $instance Instance 
  119. * @uses wp_parse_args() to merge instance defined arguments into defaults array 
  120. * @uses esc_textarea() to sanitize the text 
  121. * @uses esc_attr() to sanitize attibutes 
  122. * @uses Bpbbpst_Support_New_Support::get_field_id() To output the field id 
  123. * @uses Bpbbpst_Support_New_Support::get_field_name() To output the field name 
  124. * @uses checked() to activate the checkbox if it needs to 
  125. * @uses bpbbpst_get_support_only_forums() to get the selectbox of support only forums 
  126. */ 
  127. public function form( $instance ) { 
  128. $defaults = array( 
  129. 'bpbbpst_title' => __( 'New Support topic', 'buddy-bbpress-support-topic' ),  
  130. 'bpbbpst_button' => __( 'Ask for Support', 'buddy-bbpress-support-topic' ),  
  131. 'bpbbpst_text' => '',  
  132. 'bpbbpst_forum_id' => 0 
  133. ); 
  134.  
  135. $instance = wp_parse_args( (array) $instance, $defaults ); 
  136.  
  137. $bpbbpst_title = strip_tags( $instance['bpbbpst_title'] ); 
  138. $bpbbpst_button = strip_tags( $instance['bpbbpst_button'] ); 
  139. $bpbbpst_text = esc_textarea( $instance['bpbbpst_text'] ); 
  140. $bpbbpst_forum_id = intval( $instance['bpbbpst_forum_id'] ); 
  141. ?> 
  142. <p> 
  143. <label for="bpbbpst_title"><?php _e( 'Title:', 'buddy-bbpress-support-topic' ); ?> 
  144. <input class="widefat" id="<?php echo $this->get_field_id( 'bpbbpst_title' ); ?>" name="<?php echo $this->get_field_name( 'bpbbpst_title' ); ?>" type="text" value="<?php echo esc_attr( $bpbbpst_title ); ?>" style="width: 100%" /> 
  145. </label> 
  146. </p> 
  147. <p> 
  148. <label for="bpbbpst_button"><?php _e( 'Button caption:', 'buddy-bbpress-support-topic' ); ?> 
  149. <input class="widefat" id="<?php echo $this->get_field_id( 'bpbbpst_button' ); ?>" name="<?php echo $this->get_field_name( 'bpbbpst_button' ); ?>" type="text" value="<?php echo esc_attr( $bpbbpst_button ); ?>" style="width: 100%" /> 
  150. </label> 
  151. </p> 
  152. <textarea class="widefat" rows="8" cols="20" id="<?php echo $this->get_field_id('bpbbpst_text'); ?>" name="<?php echo $this->get_field_name('bpbbpst_text'); ?>"><?php echo $bpbbpst_text; ?></textarea> 
  153.  
  154. <p><input id="<?php echo $this->get_field_id('bpbbpst_filter'); ?>" name="<?php echo $this->get_field_name('bpbbpst_filter'); ?>" type="checkbox" <?php checked(isset($instance['bpbbpst_filter']) ? $instance['bpbbpst_filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('bpbbpst_filter'); ?>"><?php _e( 'Automatically add paragraphs', 'buddy-bbpress-support-topic' ); ?></label></p> 
  155. <p> 
  156. <label for="<?php echo $this->get_field_id('bpbbpst_forum_id'); ?>"><?php _e('Select the support only forum:', 'buddy-bbpress-support-topic') ?></label> 
  157.  
  158. <?php bpbbpst_get_support_only_forums( $bpbbpst_forum_id, $this->get_field_id('bpbbpst_forum_id'), $this->get_field_name('bpbbpst_forum_id') );?> 
  159.  
  160. </p> 
  161. <p><input id="<?php echo $this->get_field_id('bpbbpst_referer'); ?>" name="<?php echo $this->get_field_name('bpbbpst_referer'); ?>" type="checkbox" <?php checked(isset($instance['bpbbpst_referer']) ? $instance['bpbbpst_referer'] : 0); ?> /> <label for="<?php echo $this->get_field_id('bpbbpst_referer'); ?>"><?php _e( 'Automatically display a link to referer for moderators', 'buddy-bbpress-support-topic' ); ?></label></p> 
  162. <?php