Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/05/2016 05:22:55 AM (11 years ago)
Author:
boonebgorges
Message:

Move bp-messages classes to their own files.

See #6870.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-widgets.php

    r10417 r10522  
    1111defined( 'ABSPATH' ) || exit;
    1212
     13require dirname( __FILE__ ) . '/classes/class-bp-messages-sitewide-notices-widget.php';
     14
    1315/**
    1416 * Register widgets for the Messages component.
     
    2022}
    2123add_action( 'bp_register_widgets', 'bp_messages_register_widgets' );
    22 
    23 /**
    24  * A widget that displays sitewide notices.
    25  *
    26  * @since 1.9.0
    27  */
    28 class BP_Messages_Sitewide_Notices_Widget extends WP_Widget {
    29 
    30         /**
    31          * Constructor method.
    32          */
    33         function __construct() {
    34                 parent::__construct(
    35                         'bp_messages_sitewide_notices_widget',
    36                         __( '(BuddyPress) Sitewide Notices', 'buddypress' ),
    37                         array(
    38                                 'classname'   => 'widget_bp_core_sitewide_messages buddypress widget',
    39                                 'description' => __( 'Display Sitewide Notices posted by the site administrator', 'buddypress' ),
    40                         )
    41                 );
    42         }
    43 
    44         /**
    45          * Render the widget.
    46          *
    47          * @see WP_Widget::widget() for a description of parameters.
    48          *
    49          * @param array $args     See {@WP_Widget::widget()}.
    50          * @param array $instance See {@WP_Widget::widget()}.
    51          */
    52         public function widget( $args, $instance ) {
    53 
    54                 if ( ! is_user_logged_in() ) {
    55                         return;
    56                 }
    57 
    58                 // Don't display the widget if there are no Notices to show.
    59                 $notices = BP_Messages_Notice::get_active();
    60                 if ( empty( $notices ) ) {
    61                         return;
    62                 }
    63 
    64                 extract( $args );
    65 
    66                 $title = ! empty( $instance['title'] ) ? $instance['title'] : '';
    67 
    68                 /**
    69                  * Filters the title of the Messages widget.
    70                  *
    71                  * @since 1.9.0
    72                  * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
    73                  *
    74                  * @param string $title    The widget title.
    75                  * @param array  $instance The settings for the particular instance of the widget.
    76                  * @param string $id_base  Root ID for all widgets of this type.
    77                  */
    78                 $title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    79 
    80                 echo $before_widget;
    81                 echo $before_title . $title . $after_title; ?>
    82 
    83                 <div class="bp-site-wide-message">
    84                         <?php bp_message_get_notices(); ?>
    85                 </div>
    86 
    87                 <?php
    88 
    89                 echo $after_widget;
    90         }
    91 
    92         /**
    93          * Process the saved settings for the widget.
    94          *
    95          * @see WP_Widget::update() for a description of parameters and
    96          *      return values.
    97          *
    98          * @param array $new_instance See {@WP_Widget::update()}.
    99          * @param array $old_instance See {@WP_Widget::update()}.
    100          * @return array $instance See {@WP_Widget::update()}.
    101          */
    102         public function update( $new_instance, $old_instance ) {
    103                 $instance = $old_instance;
    104                 $instance['title'] = strip_tags( $new_instance['title'] );
    105                 return $instance;
    106         }
    107 
    108         /**
    109          * Render the settings form for Appearance > Widgets.
    110          *
    111          * @see WP_Widget::form() for a description of parameters.
    112          *
    113          * @param array $instance See {@WP_Widget::form()}.
    114          *
    115          * @return string Widget form output.
    116          */
    117         public function form( $instance ) {
    118                 $instance = wp_parse_args( (array) $instance, array(
    119                         'title' => '',
    120                 ) );
    121 
    122                 $title = strip_tags( $instance['title'] ); ?>
    123 
    124                 <p>
    125                         <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'buddypress' ); ?></label>
    126                         <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 ); ?>" />
    127                 </p>
    128 
    129                 <?php
    130         }
    131 }
Note: See TracChangeset for help on using the changeset viewer.