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