Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************/
- /* Excludes users with role of "suspended" from the loop */
- /*********************************************************/
- function bgmc_get_user_ids_by_role($role) {
- $users = array();
- $founded_users = get_users( array( 'role' => $role ) );
- if ( !empty( $founded_users) ) foreach ( (array)$founded_users as $user ) $users[] = $user->ID;
- return $users;
- }
- function bgmc_exclude_by_role( $exclude_roles, $implode = true ) {
- $memberArray = array();
- foreach ( $exclude_roles as $exclude_role ) $memberArray = array_merge( $memberArray, bgmc_get_user_ids_by_role( $exclude_role ) );
- if ( !$implode ) return $memberArray;
- $theExcludeString = implode( ",", $memberArray );
- return $theExcludeString;
- }
- function bgmc_exclude_byroles( $qs=false,$object=false ) {
- if ( $object!='members' ) return $qs; //hide for members only
- $args = wp_parse_args( $qs );
- if ( !empty( $args['user_id'] ) ) return $qs; //check if we are searching for friends list etc?, do not exclude in this case
- $excluded_roles = array( 'suspended' ); // you can add roles here
- $exclude = get_transient( 'excluded_members' ); // Use a transient to prevent overloading the database on sites with a lot of members
- if ( !$exclude ) :
- $exclude = bgmc_exclude_by_role( $excluded_roles );
- set_transient( 'excluded_members', $exclude, WEEK_IN_SECONDS );
- endif;
- if ( !empty( $args['exclude'] ) ):
- $args['exclude'] = $args['exclude'].','.$exclude;
- else:
- $args['exclude'] = $exclude;
- endif;
- $qs = build_query($args);
- return $qs;
- }
- add_action( 'bp_ajax_querystring', 'bgmc_exclude_byroles', 20, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement