Tagged: active, active friends, active members, friends
Thanks to the buddypress active members block one can display active members even in the sidebar of his/her buddypress site, however, I would like this to be restricted only to the active friends of the logged in user.
Is there any plugin for that, or can someone please help me with the code to do that.
This should not affect the buddypress main members directory, and also thanks in advance for whatever assistance provided me.Hello Joseph,
Welcome to the BuddyDev Forums. BuddyPress does not provide and filter to modify active members query args at the time of listing active members using Widget or block. But you can use the following code to list active friends of logged-in users.
Try shortcode: [buddydev-active-friends-list]
add_shortcode( 'buddydev-active-friends-list', function ( $atts ) { if ( ! is_user_logged_in() ) { return ''; } $atts = shortcode_atts( array( 'max' => 5 ), $atts ); $members_args = array( 'user_id' => 0, 'type' => 'active', 'max' => absint( $atts['max'] ), 'populate_extras' => true, 'search_terms' => false, ); $friends_ids = friends_get_friend_user_ids( get_current_user_id() ); $members_args['include'] = empty( $friends_ids ) ? array( 0 ) : $friends_ids; ob_start(); ?> <?php if ( bp_has_members( $members_args ) ) : ?> <div class="bd-active-friends-list avatar-block"> <?php while ( bp_members() ) : bp_the_member(); ?> <div class="item-avatar"> <a href="<?php bp_member_permalink(); ?>" class="bp-tooltip" data-bp-tooltip="<?php bp_member_name(); ?>"><?php bp_member_avatar(); ?></a> </div> <?php endwhile; ?> </div> <?php else: ?> <div class="error"> <?php esc_html_e( 'No active friend found.', 'buddypress' ); ?> </div> <?php endif; ?> <?php return ob_get_clean(); } );
Please give it a try.
Regards
RaviHi Keymaster,
Thanks for the helpful response, however I think the code is still one step away from the actual purpose, it displays all friends. Can you please do a little bit more of filtering to display only the active friends.Once again thanks a lot.
By active friends, I mean friends that are logged in at the moment.
Hello Joseph,
Please replace type ‘active’ with ‘online’ in the ‘$members_args’ variable it will list online friends.
Also, Note that BuddyPress consider the last 15 minutes active user as online users. You can change this threshold value using the filter.
Please check and let me know.
Regards
RaviHi Keymaster,
Thanks a lot, it really works.
Also, concerning “Note that BuddyPress consider the last 15 minutes active user as online users. You can change this threshold value using the filter”, I would like to reduce this to 5 minutes. Hope you can help me with this as well.Once again thank you very much.
I’m just seeing this last response. Thanks again Keymaster for all the assistance.
The topic ‘ [Resolved] Display only Active Friends for Logged in user’ is closed to new replies.