[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-members/classes/ -> class-bp-core-recently-active-widget.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Members Recently Active widget.
   4   *
   5   * @package BuddyPress
   6   * @subpackage MembersWidgets
   7   * @since 1.0.3
   8   */
   9  
  10  // Exit if accessed directly.
  11  defined( 'ABSPATH' ) || exit;
  12  
  13  /**
  14   * Recently Active Members Widget.
  15   *
  16   * @since 1.0.3
  17   */
  18  class BP_Core_Recently_Active_Widget extends WP_Widget {
  19  
  20      /**
  21       * Constructor method.
  22       *
  23       * @since 1.5.0
  24       */
  25  	public function __construct() {
  26          $name        = _x( '(BuddyPress) Recently Active Members', 'widget name', 'buddypress' );
  27          $description = __( 'Profile photos of recently active members', 'buddypress' );
  28          parent::__construct( false, $name, array(
  29              'description'                 => $description,
  30              'classname'                   => 'widget_bp_core_recently_active_widget buddypress widget',
  31              'customize_selective_refresh' => true,
  32          ) );
  33      }
  34  
  35      /**
  36       * Display the Recently Active widget.
  37       *
  38       * @since 1.0.3
  39       *
  40       * @see WP_Widget::widget() for description of parameters.
  41       *
  42       * @param array $args     Widget arguments.
  43       * @param array $instance Widget settings, as saved by the user.
  44       */
  45  	public function widget( $args, $instance ) {
  46          global $members_template;
  47  
  48          // Get widget settings.
  49          $settings = $this->parse_settings( $instance );
  50  
  51          /**
  52           * Filters the title of the Recently Active widget.
  53           *
  54           * @since 1.8.0
  55           * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter.
  56           *
  57           * @param string $title    The widget title.
  58           * @param array  $settings The settings for the particular instance of the widget.
  59           * @param string $id_base  Root ID for all widgets of this type.
  60           */
  61          $title = apply_filters( 'widget_title', $settings['title'], $settings, $this->id_base );
  62  
  63          echo $args['before_widget'];
  64          echo $args['before_title'] . $title . $args['after_title'];
  65  
  66          $max_limit   = bp_get_widget_max_count_limit( __CLASS__ );
  67          $max_members = $settings['max_members'] > $max_limit ? $max_limit : (int) $settings['max_members'];
  68  
  69          // Setup args for querying members.
  70          $members_args = array(
  71              'user_id'         => 0,
  72              'type'            => 'active',
  73              'per_page'        => $max_members,
  74              'max'             => $max_members,
  75              'populate_extras' => true,
  76              'search_terms'    => false,
  77          );
  78  
  79          // Back up global.
  80          $old_members_template = $members_template;
  81  
  82          ?>
  83  
  84          <?php if ( bp_has_members( $members_args ) ) : ?>
  85  
  86              <div class="avatar-block">
  87  
  88                  <?php while ( bp_members() ) : bp_the_member(); ?>
  89  
  90                      <div class="item-avatar">
  91                          <a href="<?php bp_member_permalink(); ?>" class="bp-tooltip" data-bp-tooltip="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a>
  92                      </div>
  93  
  94                  <?php endwhile; ?>
  95  
  96              </div>
  97  
  98          <?php else: ?>
  99  
 100              <div class="widget-error">
 101                  <?php esc_html_e( 'There are no recently active members', 'buddypress' ); ?>
 102              </div>
 103  
 104          <?php endif; ?>
 105  
 106          <?php echo $args['after_widget'];
 107  
 108          // Restore the global.
 109          $members_template = $old_members_template;
 110      }
 111  
 112      /**
 113       * Update the Recently Active widget options.
 114       *
 115       * @since 1.0.3
 116       *
 117       * @param array $new_instance The new instance options.
 118       * @param array $old_instance The old instance options.
 119       * @return array $instance The parsed options to be saved.
 120       */
 121  	public function update( $new_instance, $old_instance ) {
 122          $instance = $old_instance;
 123  
 124          $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
 125  
 126          $instance['title']       = strip_tags( $new_instance['title'] );
 127          $instance['max_members'] = $new_instance['max_members'] > $max_limit ? $max_limit : intval( $new_instance['max_members'] );
 128  
 129          return $instance;
 130      }
 131  
 132      /**
 133       * Output the Recently Active widget options form.
 134       *
 135       * @since 1.0.3
 136       *
 137       * @param array $instance Widget instance settings.
 138       * @return void
 139       */
 140  	public function form( $instance ) {
 141          $max_limit = bp_get_widget_max_count_limit( __CLASS__ );
 142  
 143          // Get widget settings.
 144          $settings    = $this->parse_settings( $instance );
 145          $title       = strip_tags( $settings['title'] );
 146          $max_members = $settings['max_members'] > $max_limit ? $max_limit : intval( $settings['max_members'] );
 147          ?>
 148  
 149          <p>
 150              <label for="<?php echo $this->get_field_id( 'title' ); ?>">
 151                  <?php esc_html_e( 'Title:', 'buddypress' ); ?>
 152                  <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 ); ?>" style="width: 100%" />
 153              </label>
 154          </p>
 155  
 156          <p>
 157              <label for="<?php echo $this->get_field_id( 'max_members' ); ?>">
 158                  <?php esc_html_e( 'Max members to show:', 'buddypress' ); ?>
 159                  <input class="widefat" id="<?php echo $this->get_field_id( 'max_members' ); ?>" name="<?php echo $this->get_field_name( 'max_members' ); ?>" type="number" min="1" max="<?php echo esc_attr( $max_limit ); ?>" value="<?php echo esc_attr( $max_members ); ?>" style="width: 30%" />
 160              </label>
 161          </p>
 162  
 163      <?php
 164      }
 165  
 166      /**
 167       * Merge the widget settings into defaults array.
 168       *
 169       * @since 2.3.0
 170       *
 171       *
 172       * @param array $instance Widget instance settings.
 173       * @return array
 174       */
 175  	public function parse_settings( $instance = array() ) {
 176          return bp_parse_args( $instance, array(
 177              'title'          => __( 'Recently Active Members', 'buddypress' ),
 178              'max_members'      => 15,
 179          ), 'recently_active_members_widget_settings' );
 180      }
 181  }


Generated: Tue Sep 17 01:01:39 2019 Cross-referenced by PHPXref 0.7.1