BP_Core_Friends_Widget::widget( array $args, array $instance )
Display the widget.
Description
Parameters
- $args
-
(Required) Widget arguments.
- $instance
-
(Required) The widget settings, as saved by the user.
Source
File: bp-friends/classes/class-bp-core-friends-widget.php
function widget( $args, $instance ) { global $members_template; extract( $args ); if ( ! bp_displayed_user_id() ) { return; } $user_id = bp_displayed_user_id(); $link = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() ); $instance['title'] = sprintf( __( "%s's Connections", 'buddyboss' ), bp_get_displayed_user_fullname() ); if ( empty( $instance['friend_default'] ) ) { $instance['friend_default'] = 'active'; } /** * Filters the Connections widget title. * * @since BuddyPress 1.8.0 * @since BuddyPress 2.3.0 Added 'instance' and 'id_base' to arguments passed to filter. * * @param string $title The widget title. * @param array $instance The settings for the particular instance of the widget. * @param string $id_base Root ID for all widgets of this type. */ $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); echo $before_widget; $title = $instance['link_title'] ? '<a href="' . esc_url( $link ) . '">' . esc_html( $title ) . '</a>' : esc_html( $title ); echo $before_title . $title . $after_title; $members_args = array( 'user_id' => absint( $user_id ), 'type' => sanitize_text_field( $instance['friend_default'] ), 'max' => absint( $instance['max_friends'] ), 'populate_extras' => 1, ); // Back up the global. $old_members_template = $members_template; ?> <?php if ( bp_has_members( $members_args ) ) : ?> <div class="item-options" id="friends-list-options"> <a href="<?php bp_members_directory_permalink(); ?>" id="newest-friends" <?php if ( $instance['friend_default'] == 'newest' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Newest', 'buddyboss' ); ?></a> | <a href="<?php bp_members_directory_permalink(); ?>" id="recently-active-friends" <?php if ( $instance['friend_default'] == 'active' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Active', 'buddyboss' ); ?></a> | <a href="<?php bp_members_directory_permalink(); ?>" id="popular-friends" <?php if ( $instance['friend_default'] == 'popular' ) : ?>class="selected"<?php endif; ?>><?php _e( 'Popular', 'buddyboss' ); ?></a> </div> <ul id="friends-list" class="item-list"> <?php while ( bp_members() ) : bp_the_member(); ?> <li class="vcard"> <div class="item-avatar"> <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a> </div> <div class="item"> <div class="item-title fn"><a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a></div> <div class="item-meta"> <?php if ( 'newest' == $instance['friend_default'] ) : ?> <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_registered( array( 'relative' => false ) ) ); ?>"><?php bp_member_registered(); ?></span> <?php elseif ( 'active' == $instance['friend_default'] ) : ?> <span class="activity" data-livestamp="<?php bp_core_iso8601_date( bp_get_member_last_active( array( 'relative' => false ) ) ); ?>"><?php bp_member_last_active(); ?></span> <?php else : ?> <span class="activity"><?php bp_member_total_friend_count(); ?></span> <?php endif; ?> </div> </div> </li> <?php endwhile; ?> </ul> <?php wp_nonce_field( 'bp_core_widget_friends', '_wpnonce-friends' ); ?> <input type="hidden" name="friends_widget_max" id="friends_widget_max" value="<?php echo absint( $instance['max_friends'] ); ?>" /> <?php else: ?> <div class="widget-error"> <?php _e( 'Sorry, no members were found.', 'buddyboss' ); ?> </div> <?php endif; ?> <?php echo $after_widget; // Restore the global. $members_template = $old_members_template; }
Changelog
Version | Description |
---|---|
BuddyPress 1.9.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.