BP_Core_Whos_Online_Widget

Who's Online Widget.

Defined (1)

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

/bp-members/classes/class-bp-core-whos-online-widget.php  
  1. class BP_Core_Whos_Online_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Constructor method. 
  5. * @since 1.5.0 
  6. */ 
  7. public function __construct() { 
  8. $name = _x( "(BuddyPress) Who's Online", 'widget name', 'buddypress' ); 
  9. $description = __( 'Profile photos of online users', 'buddypress' ); 
  10. parent::__construct( false, $name, array( 
  11. 'description' => $description,  
  12. 'classname' => 'widget_bp_core_whos_online_widget buddypress widget',  
  13. 'customize_selective_refresh' => true,  
  14. ) ); 
  15.  
  16. /** 
  17. * Display the Who's Online 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 Who's Online 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'] . $args['before_title'] . $title . $args['after_title']; 
  40.  
  41. // Setup args for querying members. 
  42. $members_args = array( 
  43. 'user_id' => 0,  
  44. 'type' => 'online',  
  45. 'per_page' => $settings['max_members'],  
  46. 'max' => $settings['max_members'],  
  47. 'populate_extras' => true,  
  48. 'search_terms' => false,  
  49. ); 
  50.  
  51. // Back up global. 
  52. $old_members_template = $members_template; 
  53.  
  54. ?> 
  55.  
  56. <?php if ( bp_has_members( $members_args ) ) : ?> 
  57.  
  58. <div class="avatar-block"> 
  59.  
  60. <?php while ( bp_members() ) : bp_the_member(); ?> 
  61.  
  62. <div class="item-avatar"> 
  63. <a href="<?php bp_member_permalink(); ?>" title="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a> 
  64. </div> 
  65.  
  66. <?php endwhile; ?> 
  67.  
  68. </div> 
  69.  
  70. <?php else: ?> 
  71.  
  72. <div class="widget-error"> 
  73. <?php esc_html_e( 'There are no users currently online', 'buddypress' ); ?> 
  74. </div> 
  75.  
  76. <?php endif; ?> 
  77.  
  78. <?php echo $args['after_widget']; 
  79.  
  80. // Restore the global. 
  81. $members_template = $old_members_template; 
  82.  
  83. /** 
  84. * Update the Who's Online widget options. 
  85. * @since 1.0.3 
  86. * @param array $new_instance The new instance options. 
  87. * @param array $old_instance The old instance options. 
  88. * @return array $instance The parsed options to be saved. 
  89. */ 
  90. public function update( $new_instance, $old_instance ) { 
  91. $instance = $old_instance; 
  92. $instance['title'] = strip_tags( $new_instance['title'] ); 
  93. $instance['max_members'] = strip_tags( $new_instance['max_members'] ); 
  94.  
  95. return $instance; 
  96.  
  97. /** 
  98. * Output the Who's Online widget options form. 
  99. * @since 1.0.3 
  100. * @param array $instance Widget instance settings. 
  101. * @return void 
  102. */ 
  103. public function form( $instance ) { 
  104.  
  105. // Get widget settings. 
  106. $settings = $this->parse_settings( $instance ); 
  107. $title = strip_tags( $settings['title'] ); 
  108. $max_members = strip_tags( $settings['max_members'] ); ?> 
  109.  
  110. <p> 
  111. <label for="<?php echo $this->get_field_id( 'title' ); ?>"> 
  112. <?php esc_html_e( 'Title:', 'buddypress' ); ?> 
  113. <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%" /> 
  114. </label> 
  115. </p> 
  116.  
  117. <p> 
  118. <label for="<?php echo $this->get_field_id( 'max_members' ); ?>"> 
  119. <?php esc_html_e( 'Max members to show:', 'buddypress' ); ?> 
  120. <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%" /> 
  121. </label> 
  122. </p> 
  123.  
  124. <?php 
  125.  
  126. /** 
  127. * Merge the widget settings into defaults array. 
  128. * @since 2.3.0 
  129. * @param array $instance Widget instance settings. 
  130. * @return array 
  131. */ 
  132. public function parse_settings( $instance = array() ) { 
  133. return bp_parse_args( $instance, array( 
  134. 'title' => __( "Who's Online", 'buddypress' ),  
  135. 'max_members' => 15,  
  136. ), 'members_widget_settings' );