Working My Sites Filter

So previously I was struggling with stripping out the Participants blogs that the bbPress/BuddyPress combo was adding to the My Sites list. I got it working and added a bit to deal with it kicking out blogs a little too aggressively.

First to get the actual name of the Participant slug, I made a page template for a theme that only did one thing- listed the user roles array. It is dead simple and looks like so . . .

 * Template Name: user roles 
 * @package WordPress
 * @subpackage Lies
 * @since Twenty Fourteen 1.0
     global $wp_roles;
     $roles = $wp_roles->get_names();

     // Below code will print the all list of roles.

Throwing that in a theme let me know that the slug for participant was actually bbp_participant. I spent a lot of time thinking I was doing something else wrong. I’m also not a huge fan of doing things this way in PHP. I wish I had the a console log option like in javascript.

Plugin Name: ALT Lab Remove Participant Blogs
Plugin URI:
Description: Removes all the blogs where you are just a participant
Author: Tom Woodward
Version: 1.1
Author URI:

function remove_non_admin_blogs($blogs) {
 				global $current_user; 
    			$user_id = $current_user->ID; 
    			$role = 'bbp_participant';

                foreach ( $blogs as $blog_id => $blog ) {

                    // Get the user object for the user for this blog.
                    $user = new WP_User( $user_id, '', $blog_id );
                    // if they only have one user role for that blog . . . then 
				if (count( $user->roles ) === 1 ){
                    // Remove this blog from the list if the user is just a participant
                    if (in_array( $role, $user->roles ) ) {
                        unset( $blogs[ $blog_id ] );

                return $blogs;
add_filter( 'get_blogs_of_user', 'remove_non_admin_blogs' );

Trackbacks and Pingbacks on this post

  1. Weaving Tangled Webs – Bionic Teaching said on January 30, 2016 at 10:54 am

    […] I had to figure out two things as a result. First, I needed to stop auto-Participant association. I eventually found a way to do that but I still had to deal with the stuff that already happened. The right way to do it was to delete the users who were participants across the multisite. But . . . at that time we couldn’t access our database through anything but php myadmin and it wouldn’t run because the database was too big. So I had to treat the problem and strip the sites from the displayed list. […]

  2. Filtering the My Sites List (Again) – Bionic Teaching said on February 27, 2016 at 9:18 pm

    […] I made a filter a while back to keep people who were associated with blogs through the bbpress/buddypress auto-enrollment feature from having tons of sites show up in their My Sites list. It was never a perfect solution and felt sloppy because it relied on having only one role and that role being bbp_participant. It also failed when I un-network activated bbPress because it couldn’t filter people who had no role (and there was still some invisible connection). And the final nail was that it seemed to fail intermittently and I had no idea why. […]