BuddyDev

Search

Hide profile administrator

Tagged: 

  • Participant
    Level: Initiated
    Posts: 18
    Julien ROUSSEL on #6702

    Hi,

    In the code snippet of buddydev., I do not find the code to hide the profile of administrators, I do not want it to be visible, can you help me ?

    I find this code on the internet, but it does not work, the administrator is always visible on the member page

    //on masque le superadmin sur l’annuaire des membres
    function bpdev_exclude_users($qs=false,$object=false){

    $excluded_user=’1,2′; //séparer par des virgules les ID des membres que vous souhaitez cacher

    if($object != ‘members’) //on cache pour les membres
    return $qs;

    $args=wp_parse_args($qs);

    //on ne cache PAS le profil aux amis

    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;

    }
    add_action(‘bp_ajax_querystring’,’bpdev_exclude_users’,20,2);

    // il faut aussi recompter les Membres
    function bpfr_hide_get_total_filter($count){
    return $count-1;
    }
    add_filter(‘bp_get_total_member_count’,’bpfr_hide_get_total_filter’);

  • Keymaster
    (BuddyDev Team)
    Posts: 24496
    Brajesh Singh on #6707

    Hi Julien,
    There are multiple ways to do it.
    Here is one way(I just updated the above code)

    
    function bpdev_exclude_users( $qs = false, $object = false ) {
    
    	//if not members, let us return
    	if ( $object != 'members' ) {
    		return $qs;
    	}
    
    	$args = wp_parse_args($qs);
    	//we are looking into friends list if the user id is given, do not hide here
    	if ( ! empty( $args['user_id'] ) ) {
    		return $qs;
    	}
    
    	$excluded_users = get_users( array(
    		'role'      => 'administrator',
    		'fields'    => 'ID'
    	) );
    
    	if ( ! empty( $args['exclude'] ) ) {
    
    		if ( ! is_array( $args['exclude'] ) ) {
    			$args['exclude'] = explode( ',', $args['exclude'] );
    		}
    
    		$args['exclude'] = array_merge( $args['exclude'], $excluded_users );
    
    	} else {
    		$args['exclude'] = $excluded_users;
    	}
    
    	$args['exclude'] = join(',', $args['exclude'] );
    
    	$qs = build_query($args);
    
    	return $qs;
    
    }
    add_action( 'bp_ajax_querystring','bpdev_exclude_users', 20, 2 );
    
    

    Please put it in your bp-custom.php and all the admins will be invisible in the members directory.

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 18
    Julien ROUSSEL on #6711

    Hi Brajesh

    It works, thanks a lot for sharing your code 😉
    Your “code snippets” page to change no ? Because there is less code than the last one or I am going to see on your site.

    ——————

    Another small problem, on my blog:

    https://mysocialart.com/blog/
    https://mysocialart.com/test/

    There is a link “mysocialart” (the name of the administrator), the members of the site can access the profile of the administrator with this link, ideally, I would like to remove the clickable link or redirect the members on the Homepage (for example), I think it is posible but I do not know how to code this

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 24496
    Brajesh Singh on #6721

    Hi Julien,
    Please add the following code to your bp-custom.php too

    
    
    function buddydev_redirect_from_admin_profile() {
    	//not a profile page or viewing own profile page,  no redirect
    	if ( ! bp_is_user() || bp_is_my_profile() ) {
    		return;
    	}
    
    	//check if the user is admin?
    	//there are multiple ways to do it, I will show for Super admin
    	//You can use user_can(bp_displayed_user_id(), 'cap_name' ) too, Make sure to change cap name to appropriate cap
    
    	$redirect_url = site_url('/why-did-i-get-redirected');//or any url
    
    	if ( is_super_admin( bp_displayed_user_id() ) ) {
    		bp_core_redirect( $redirect_url );
    	}
    
    }
    
    add_action( 'bp_template_redirect', 'buddydev_redirect_from_admin_profile' );
    
    

    Change the redirect url as you please.

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 18
    Julien ROUSSEL on #6733

    I was not aware of this code, thank you very much, it works wonderfully! Good day Brajesh 😉

  • Keymaster
    (BuddyDev Team)
    Posts: 24496
    Brajesh Singh on #6744

    Thank you and have a great day to you too.

    Regards
    Brajesh

The topic ‘Hide profile administrator’ is closed to new replies.

This topic is: not resolved