Refining the My Sites List

The following plugin (network activated) will strip out all blogs from your My Sites list where you aren’t an admin.

I cobbled it together from some stuff Mark did to generate a list of blogs for the Mother Blog plugin. While it would be great for me, it would not work all that well for other people on rampages.

Part of this is being driven by the BuddyPress/bbPress decision to add any logged in member who visits any other blog as a “Participant.” I had something that was stopping this previously but it seems to have stopped working.

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

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

                    // Get the user object for the user for this blog.
                    $user = new WP_User( $user_id, '', $blog_id );

                    // Remove this blog from the list if the user doesn't have the role for it.
                    if ( ! in_array( $role, $user->roles ) ) {
                        unset( $blogs[ $blog_id ] );
                    }
                }

                return $blogs;
            }    
add_filter( 'get_blogs_of_user', 'remove_non_admin_blogs' );
print_r ($user->roles);
?>

So I thought I could just flip this a bit and make it do the opposite (kick out any blogs where I am a participant).

function remove_non_admin_blogs($blogs) {
 				global $current_user; 
    			$user_id = $current_user->ID; 
    			$role = '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 );

                    // Remove this blog from the list if the user is a participant.
                    if (in_array( $role, $user->roles ) ) {
                        unset( $blogs[ $blog_id ] );
                    }
                }

                return $blogs;
            }    
add_filter( 'get_blogs_of_user', 'remove_non_admin_blogs' );
print_r ($user->roles);
?>

It works fine for the normal roles but not for participant. I’m not sure why. Anyone have a clue? Special roles are accessed some other way?

UPDATE

Turns out the slug is bbp_participant. Pays to look more deeply.

Comments on this post

No comments.

Leave a Reply

Trackbacks and Pingbacks on this post

No trackbacks.

TrackBack URL