[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Messages Sitewide Notices Widget. 4 * 5 * @package BuddyPress 6 * @subpackage MessagesClasses 7 * @since 1.9.0 8 */ 9 10 // Exit if accessed directly. 11 defined( 'ABSPATH' ) || exit; 12 13 /** 14 * A widget that displays sitewide notices. 15 * 16 * @since 1.9.0 17 */ 18 class BP_Messages_Sitewide_Notices_Widget extends WP_Widget { 19 20 /** 21 * Constructor method. 22 * 23 * @since 1.9.0 24 * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options. 25 */ 26 public function __construct() { 27 parent::__construct( 28 'bp_messages_sitewide_notices_widget', 29 __( '(BuddyPress) Sitewide Notices', 'buddypress' ), 30 array( 31 'classname' => 'widget_bp_core_sitewide_messages buddypress widget', 32 'description' => __( 'Display Sitewide Notices posted by the site administrator', 'buddypress' ), 33 'customize_selective_refresh' => true, 34 'show_instance_in_rest' => true, 35 ) 36 ); 37 } 38 39 /** 40 * Render the widget. 41 * 42 * @see WP_Widget::widget() for a description of parameters. 43 * 44 * @param array $args See {@WP_Widget::widget()}. 45 * @param array $instance See {@WP_Widget::widget()}. 46 */ 47 public function widget( $args, $instance ) { 48 49 if ( ! is_user_logged_in() ) { 50 return; 51 } 52 53 // Don't display the widget if there are no Notices to show. 54 $notices = BP_Messages_Notice::get_active(); 55 if ( empty( $notices ) ) { 56 return; 57 } 58 59 extract( $args ); 60 61 $title = ! empty( $instance['title'] ) ? $instance['title'] : ''; 62 63 /** 64 * Filters the title of the Messages widget. 65 * 66 * @since 1.9.0 67 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 68 * 69 * @param string $title The widget title. 70 * @param array $instance The settings for the particular instance of the widget. 71 * @param string $id_base Root ID for all widgets of this type. 72 */ 73 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base ); 74 75 echo $before_widget; 76 echo $before_title . $title . $after_title; ?> 77 78 <div class="bp-site-wide-message"> 79 <?php bp_message_get_notices(); ?> 80 </div> 81 82 <?php 83 84 echo $after_widget; 85 } 86 87 /** 88 * Process the saved settings for the widget. 89 * 90 * @see WP_Widget::update() for a description of parameters and 91 * return values. 92 * 93 * @param array $new_instance See {@WP_Widget::update()}. 94 * @param array $old_instance See {@WP_Widget::update()}. 95 * @return array $instance See {@WP_Widget::update()}. 96 */ 97 public function update( $new_instance, $old_instance ) { 98 $instance = $old_instance; 99 $instance['title'] = strip_tags( $new_instance['title'] ); 100 return $instance; 101 } 102 103 /** 104 * Render the settings form for Appearance > Widgets. 105 * 106 * @see WP_Widget::form() for a description of parameters. 107 * 108 * @param array $instance See {@WP_Widget::form()}. 109 */ 110 public function form( $instance ) { 111 $instance = bp_parse_args( 112 (array) $instance, 113 array( 114 'title' => '', 115 ) 116 ); 117 118 $title = strip_tags( $instance['title'] ); ?> 119 120 <p> 121 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?></label> 122 <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 ); ?>" /> 123 </p> 124 125 <?php 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |