• Home
  • WordPress
    • How To
    • Plugins
    • Themes
      • Genesis
      • Themify
      • Mysite myway
    • Security
    • Developer
    • Teaching
    • Conference
    • Chat
  • Blog
  • About
  • Freelance
    • Plugins
    • Teaching
    • Need help?
    • CV og ref.
  • Contact

Easy Web Design Tutorials

WordPress Tutorials and more

  • Home
  • WordPress
    • How To
    • Plugins
    • Themes
      • Genesis
      • Themify
      • Mysite myway
    • Security
    • Developer
    • Teaching
    • Conference
    • Chat
  • Blog
  • About
  • Freelance
    • Plugins
    • Teaching
    • Need help?
    • CV og ref.
  • Contact

1 July - 2018 By Paal Joachim Add a Comment
Last updated on: July 1, 2021

BuddyPress: How to show only subscribers on the Members page

Code I used to only show subscriber on the members page:
// https://premium.wpmudev.org/forums/topic/how-can-i-filter-members-according-to-wp-user-role
add_action( ‘bp_ajax_querystring’, ‘bpdev_exclude_users’, 20, 2 );
function bpdev_exclude_users( $qs=false, $object=false ){

$user = wp_get_current_user();
if ( $user->roles ) {
$role = ‘Subscriber’;
//if ( in_array( ‘family’, (array) $user->roles ) ) {
// $role = ‘service’;
//}elseif ( in_array( ‘service’, (array) $user->roles ) ) {
// $role = ‘family’;
}else{
$role = false;
}

if( ! $role ) return $qs;

$includes = array();
$users = get_users( array( ‘role’ => $role ) );
foreach( $users as $user ){
array_push( $includes, $user->ID );
}

if( $object != ‘members’ )
return $qs;

$args = wp_parse_args( $qs );

if( ! empty( $args[‘user_id’] ) )
return $qs;

if( ! empty( $args[‘include’] ) )
$args[‘include’] = $args[‘include’] . ‘,’ . implode( ‘,’, $includes );
else
$args[‘include’] = implode( ‘,’, $includes );

$qs = build_query( $args );

return $qs;

}

Share this:

  • Email

Categories: Plugins, WordPress

Paal Joachim Romdahl

I enjoy teaching and creating tutorials. As well creating web sites.
I help people gain WordPress knowledge through my easy to follow tutorials and specialized training. Contact me for more information on how I can improve your WordPress skills and to help get your web site quickly up and running.

Leave a Comment Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

© 2022 · By Easy Web Design Tutorials · Built on the Genesis Framework · WordPress · Log in · ⇪