BP_Core_Recently_Active_Widget

Recently Active Members Widget.

Defined (1)

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

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