Hide profiles of a specific role (not admin) except from profile owner or admin
-
I found some code it hide admin profiles from other users and I’d like the same functionality but only for ‘subscribers’ I’d still like all other users to appear.
function hide_admin_profiles() { // Bail if this is not a profile. if ( ! bp_is_user_profile() ) return; if ( ! is_super_admin() ) { if ( is_super_admin( bp_displayed_user_id() ) ) { wp_redirect( home_url() ); exit; } } } add_action( 'init', 'hide_admin_profiles' );
I have the following in my functions.php already that might have a usable variable or array already.
It hides the designated roles from the members loop.<?php add_action('bp_ajax_querystring','bpdev_exclude_users',20,2); function bpdev_exclude_users($qs=false,$object=false){ //list of users to exclude $excluded_user=join(',',bpdev_get_subscriber_user_ids());//comma separated ids of users whom you want to exclude if($object!='members')//hide for members only return $qs; $args=wp_parse_args($qs); //check if we are searching for friends list etc?, do not exclude in this case if(!empty($args['user_id'])) return $qs; if(!empty($args['exclude'])) $args['exclude']=$args['exclude'].','.$excluded_user; else $args['exclude']=$excluded_user; $qs=build_query($args); return $qs; } function bpdev_get_subscriber_user_ids(){ $users=array(); $subscribers= get_users( array( 'role' => 'subscriber' ) ); if(!empty($subscribers)){ foreach((array)$subscribers as $subscriber) $users[]=$subscriber->ID; } return $users; } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Hide profiles of a specific role (not admin) except from profile owner or admin’ is closed to new replies.