[ Index ] |
PHP Cross Reference of BuddyPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * BuddyPress Members 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 * Members Widget. 15 * 16 * @since 1.0.3 17 */ 18 class BP_Core_Members_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 28 // Setup widget name & description. 29 $name = _x( '(BuddyPress) Members', 'widget name', 'buddypress' ); 30 $description = __( 'A dynamic list of recently active, popular, and newest members', 'buddypress' ); 31 32 // Call WP_Widget constructor. 33 parent::__construct( false, $name, array( 34 'description' => $description, 35 'classname' => 'widget_bp_core_members_widget buddypress widget', 36 'customize_selective_refresh' => true, 37 'show_instance_in_rest' => true, 38 ) ); 39 40 if ( is_customize_preview() || bp_is_widget_block_active( '', $this->id_base ) ) { 41 add_action( 'bp_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); 42 } 43 } 44 45 /** 46 * Enqueue scripts. 47 * 48 * @since 2.6.0 49 */ 50 public function enqueue_scripts() { 51 wp_enqueue_script( 'bp-widget-members' ); 52 } 53 54 /** 55 * Display the Members widget. 56 * 57 * @since 1.0.3 58 * 59 * @see WP_Widget::widget() for description of parameters. 60 * 61 * @param array $args Widget arguments. 62 * @param array $instance Widget settings, as saved by the user. 63 */ 64 public function widget( $args, $instance ) { 65 global $members_template; 66 67 // Get widget settings. 68 $settings = $this->parse_settings( $instance ); 69 70 /** 71 * Filters the title of the Members widget. 72 * 73 * @since 1.8.0 74 * @since 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. 75 * 76 * @param string $title The widget title. 77 * @param array $settings The settings for the particular instance of the widget. 78 * @param string $id_base Root ID for all widgets of this type. 79 */ 80 $title = apply_filters( 'widget_title', $settings['title'], $settings, $this->id_base ); 81 $title = $settings['link_title'] ? '<a href="' . bp_get_members_directory_permalink() . '">' . $title . '</a>' : $title; 82 83 /** 84 * Filters the separator of the member widget links. 85 * 86 * @since 2.4.0 87 * 88 * @param string $separator Separator string. Default '|'. 89 */ 90 $separator = apply_filters( 'bp_members_widget_separator', '|' ); 91 92 // Output before widget HTMl, title (and maybe content before & after it). 93 echo $args['before_widget'] . $args['before_title'] . $title . $args['after_title']; 94 95 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 96 $max_members = $settings['max_members'] > $max_limit ? $max_limit : (int) $settings['max_members']; 97 98 // Setup args for querying members. 99 $members_args = array( 100 'user_id' => 0, 101 'type' => $settings['member_default'], 102 'per_page' => $max_members, 103 'max' => $max_members, 104 'populate_extras' => true, 105 'search_terms' => false, 106 ); 107 108 // Back up the global. 109 $old_members_template = $members_template; 110 111 ?> 112 113 <?php if ( bp_has_members( $members_args ) ) : ?> 114 115 <div class="item-options" id="members-list-options"> 116 <a href="<?php bp_members_directory_permalink(); ?>" id="newest-members" <?php if ( 'newest' === $settings['member_default'] ) : ?>class="selected"<?php endif; ?>><?php esc_html_e( 'Newest', 'buddypress' ); ?></a> 117 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span> 118 <a href="<?php bp_members_directory_permalink(); ?>" id="recently-active-members" <?php if ( 'active' === $settings['member_default'] ) : ?>class="selected"<?php endif; ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></a> 119 120 <?php if ( bp_is_active( 'friends' ) ) : ?> 121 <span class="bp-separator" role="separator"><?php echo esc_html( $separator ); ?></span> 122 <a href="<?php bp_members_directory_permalink(); ?>" id="popular-members" <?php if ( 'popular' === $settings['member_default'] ) : ?>class="selected"<?php endif; ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></a> 123 124 <?php endif; ?> 125 126 </div> 127 128 <ul id="members-list" class="item-list" aria-live="polite" aria-relevant="all" aria-atomic="true"> 129 130 <?php while ( bp_members() ) : bp_the_member(); ?> 131 132 <li class="vcard"> 133 <div class="item-avatar"> 134 <a href="<?php bp_member_permalink() ?>" class="bp-tooltip" data-bp-tooltip="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a> 135 </div> 136 137 <div class="item"> 138 <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div> 139 <div class="item-meta"> 140 <?php if ( 'newest' == $settings['member_default'] ) : ?> 141 <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_registered( array( 'relative' => false ) ) ); ?>"><?php bp_member_registered(); ?></span> 142 <?php elseif ( 'active' == $settings['member_default'] ) : ?> 143 <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span> 144 <?php else : ?> 145 <span class="activity"><?php bp_member_total_friend_count(); ?></span> 146 <?php endif; ?> 147 </div> 148 </div> 149 </li> 150 151 <?php endwhile; ?> 152 153 </ul> 154 155 <?php wp_nonce_field( 'bp_core_widget_members', '_wpnonce-members', false ); ?> 156 157 <input type="hidden" name="members_widget_max" id="members_widget_max" value="<?php echo esc_attr( $settings['max_members'] ); ?>" /> 158 159 <?php else: ?> 160 161 <div class="widget-error"> 162 <?php esc_html_e( 'No one has signed up yet!', 'buddypress' ); ?> 163 </div> 164 165 <?php endif; ?> 166 167 <?php echo $args['after_widget']; 168 169 // Restore the global. 170 $members_template = $old_members_template; 171 } 172 173 /** 174 * Update the Members widget options. 175 * 176 * @since 1.0.3 177 * 178 * @param array $new_instance The new instance options. 179 * @param array $old_instance The old instance options. 180 * @return array $instance The parsed options to be saved. 181 */ 182 public function update( $new_instance, $old_instance ) { 183 $instance = $old_instance; 184 185 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 186 187 $instance['title'] = strip_tags( $new_instance['title'] ); 188 $instance['max_members'] = $new_instance['max_members'] > $max_limit ? $max_limit : intval( $new_instance['max_members'] ); 189 $instance['member_default'] = strip_tags( $new_instance['member_default'] ); 190 $instance['link_title'] = ! empty( $new_instance['link_title'] ); 191 192 return $instance; 193 } 194 195 /** 196 * Output the Members widget options form. 197 * 198 * @since 1.0.3 199 * 200 * @param array $instance Widget instance settings. 201 * @return void 202 */ 203 public function form( $instance ) { 204 $max_limit = bp_get_widget_max_count_limit( __CLASS__ ); 205 206 // Get widget settings. 207 $settings = $this->parse_settings( $instance ); 208 $title = strip_tags( $settings['title'] ); 209 $max_members = $settings['max_members'] > $max_limit ? $max_limit : intval( $settings['max_members'] ); 210 $member_default = strip_tags( $settings['member_default'] ); 211 $link_title = (bool) $settings['link_title']; ?> 212 213 <p> 214 <label for="<?php echo $this->get_field_id( 'title' ); ?>"> 215 <?php esc_html_e( 'Title:', 'buddypress' ); ?> 216 <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%" /> 217 </label> 218 </p> 219 220 <p> 221 <label for="<?php echo $this->get_field_id( 'link_title' ) ?>"> 222 <input type="checkbox" name="<?php echo $this->get_field_name( 'link_title' ) ?>" id="<?php echo $this->get_field_id( 'link_title' ) ?>" value="1" <?php checked( $link_title ) ?> /> 223 <?php esc_html_e( 'Link widget title to Members directory', 'buddypress' ); ?> 224 </label> 225 </p> 226 227 <p> 228 <label for="<?php echo $this->get_field_id( 'max_members' ); ?>"> 229 <?php esc_html_e( 'Max members to show:', 'buddypress' ); ?> 230 <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%" /> 231 </label> 232 </p> 233 234 <p> 235 <label for="<?php echo $this->get_field_id( 'member_default' ) ?>"><?php esc_html_e( 'Default members to show:', 'buddypress' ); ?></label> 236 <select name="<?php echo $this->get_field_name( 'member_default' ) ?>" id="<?php echo $this->get_field_id( 'member_default' ) ?>"> 237 <option value="newest" <?php if ( 'newest' === $member_default ) : ?>selected="selected"<?php endif; ?>><?php esc_html_e( 'Newest', 'buddypress' ); ?></option> 238 <option value="active" <?php if ( 'active' === $member_default ) : ?>selected="selected"<?php endif; ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></option> 239 <option value="popular" <?php if ( 'popular' === $member_default ) : ?>selected="selected"<?php endif; ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></option> 240 </select> 241 </p> 242 243 <?php 244 } 245 246 /** 247 * Merge the widget settings into defaults array. 248 * 249 * @since 2.3.0 250 * 251 * @param array $instance Widget instance settings. 252 * @return array 253 */ 254 public function parse_settings( $instance = array() ) { 255 return bp_parse_args( 256 $instance, 257 array( 258 'title' => __( 'Members', 'buddypress' ), 259 'max_members' => 5, 260 'member_default' => 'active', 261 'link_title' => false, 262 ), 263 'members_widget_settings' 264 ); 265 } 266 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Dec 22 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |