BP_Messages_Sitewide_Notices_Widget

A widget that displays sitewide notices.

Defined (1)

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

/bp-messages/classes/class-bp-messages-sitewide-notices-widget.php  
  1. class BP_Messages_Sitewide_Notices_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Constructor method. 
  5. */ 
  6. function __construct() { 
  7. parent::__construct( 
  8. 'bp_messages_sitewide_notices_widget',  
  9. __( '(BuddyPress) Sitewide Notices', 'buddypress' ),  
  10. array( 
  11. 'classname' => 'widget_bp_core_sitewide_messages buddypress widget',  
  12. 'description' => __( 'Display Sitewide Notices posted by the site administrator', 'buddypress' ),  
  13. 'customize_selective_refresh' => true,  
  14. ); 
  15.  
  16. /** 
  17. * Render the widget. 
  18. * @see WP_Widget::widget() for a description of parameters. 
  19. * @param array $args See {@WP_Widget::widget()}. 
  20. * @param array $instance See {@WP_Widget::widget()}. 
  21. */ 
  22. public function widget( $args, $instance ) { 
  23.  
  24. if ( ! is_user_logged_in() ) { 
  25. return; 
  26.  
  27. // Don't display the widget if there are no Notices to show. 
  28. $notices = BP_Messages_Notice::get_active(); 
  29. if ( empty( $notices ) ) { 
  30. return; 
  31.  
  32. extract( $args ); 
  33.  
  34. $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; 
  35.  
  36. /** 
  37. * Filters the title of the Messages widget. 
  38. * @since 1.9.0 
  39. * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 
  40. * @param string $title The widget title. 
  41. * @param array $instance The settings for the particular instance of the widget. 
  42. * @param string $id_base Root ID for all widgets of this type. 
  43. */ 
  44. $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 
  45.  
  46. echo $before_widget; 
  47. echo $before_title . $title . $after_title; ?> 
  48.  
  49. <div class="bp-site-wide-message"> 
  50. <?php bp_message_get_notices(); ?> 
  51. </div> 
  52.  
  53. <?php 
  54.  
  55. echo $after_widget; 
  56.  
  57. /** 
  58. * Process the saved settings for the widget. 
  59. * @see WP_Widget::update() for a description of parameters and 
  60. * return values. 
  61. * @param array $new_instance See {@WP_Widget::update()}. 
  62. * @param array $old_instance See {@WP_Widget::update()}. 
  63. * @return array $instance See {@WP_Widget::update()}. 
  64. */ 
  65. public function update( $new_instance, $old_instance ) { 
  66. $instance = $old_instance; 
  67. $instance['title'] = strip_tags( $new_instance['title'] ); 
  68. return $instance; 
  69.  
  70. /** 
  71. * Render the settings form for Appearance > Widgets. 
  72. * @see WP_Widget::form() for a description of parameters. 
  73. * @param array $instance See {@WP_Widget::form()}. 
  74. * @return string Widget form output. 
  75. */ 
  76. public function form( $instance ) { 
  77. $instance = wp_parse_args( (array) $instance, array( 
  78. 'title' => '',  
  79. ) ); 
  80.  
  81. $title = strip_tags( $instance['title'] ); ?> 
  82.  
  83. <p> 
  84. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?></label> 
  85. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> 
  86. </p> 
  87.  
  88. <?php