This topic has 8 replies, 3 voices, and was last updated 9 years by klosurdo.

  • Author
  • #48274
     klosurdo
    Participant

    Hi,

    I am looking to remove the admin profiles from the website. I researched the following code in this forum but am having trouble getting it to work.

    COPY CODE
    /* Hide admin */
    add_action('bp_init', 'kleo_private_admin');
    function kleo_private_admin(){
        global $bp;
        if(is_super_admin())
        {
            remove_action("wp_head","bp_core_record_activity"); //id SM is on, remove the record activity hook
            //then remove the last activity, if present
            delete_user_meta($bp->loggedin_user->id, 'last_activity');
        }
    }
    
    add_action('bp_ajax_querystring','kleo_exclude_users',20,2);
    function kleo_exclude_users($qs=false,$object=false)
    {
        //list of users to exclude
    
        $excluded_user='2,3';//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 listing friends?, 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;
    }

    The admins are still visiable. As seen here http://www.cmpg-annex.org/member-galleries/

    I want to make admins invisible to both logged in and non logged in viewers.

    Thanks for any help

    #48312
     klosurdo
    Participant

    Am I doing something incorrectly? or is there a better way to do this through a plugin
    ?

    #48368
     Radu
    Moderator

    Hello Klosurdo,

    Try with this snippet

    COPY CODE
    
    
    function bpdev_exclude_users($qs=false,$object=false){
        
        $excluded_user='1'; // Id's to remove, separated by comma
        
        if($object != 'members' && $object != 'friends')// hide admin to members & friends 
        return $qs;
        
        $args=wp_parse_args($qs);
     
        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);
     
    // once admin is removed, we must recount the members !
    function bpfr_hide_get_total_filter($count){
        return $count-1;
    }
    add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
    
    

    Let me know if it works.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #48384
     klosurdo
    Participant

    Thanks Radu,

    Unfortunatey it did not work. Still showing the admins here http://www.cmpg-annex.org/member-galleries/ and elwhere through the site

    #48387
     Radu
    Moderator

    It welcome,

    Try this solution : http://buddydev.com/buddypress/exclude-users-from-members-directory-on-a-buddypress-based-social-network/ or this : http://pastebin.com/phUXcaDN or this :

    COPY CODE
    
    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=’1′;//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’])||!empty($args[‘search_terms’]))
    return $qs;
    
    if(!empty($args[‘exclude’]))
    $args[‘exclude’]=$args[‘exclude’].’,’.$excluded_user;
    else
    $args[‘exclude’]=$excluded_user;
    
    $qs=build_query($args);
    
    return $qs;
    
    }
    
    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #48431
     klosurdo
    Participant

    I am really struggling with this one. I searched this site and buddy press and tried every code available with no success. Below is the last code I tried with no success.

    https://buddypress.org/support/topic/hide-admins-activities-from-all-activity-feeds-in-buddypress/

    Any ideas what I am doing incorrectly? This code is inserted in my child themes fuction.php correct?

    I am racking my brain on this one!

    Ken

    COPY CODE
    // deny access to admins profile. User is redirected to the homepage
    
    function bpfr_hide_admins_profile() {
    	global $bp; 
    	if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) :
    	wp_redirect( home_url() );
    	exit;
    	endif;
    }
    add_action( 'wp', 'bpfr_hide_admins_profile', 1 );
    
    // Remove admin from the member directory
    
    function bpdev_exclude_users($qs=false,$object=false){
    	
    	$excluded_user='1'; // Id's to remove, separated by comma
    	
    	if($object != 'members' && $object != 'friends')// hide admin to members & friends 
    	return $qs;
    	
    	$args=wp_parse_args($qs);
    	
    	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);
    
    // once admin is removed, we must recount the members !
    
    function bpfr_hide_get_total_filter($count){
    	return $count-1;
    }
    add_filter('bp_get_total_member_count','bpfr_hide_get_total_filter');
    
    // hide admin's activities from all activity feeds
    
    function bpfr_hide_admin_activity( $a, $activities ) {	
    	
    	// ... but allow admin to see his activities!
    	if ( is_site_admin() )	
    	return $activities;	
    	
    	foreach ( $activities->activities as $key => $activity ) {	
    		// ID's to exclude, separated by commas. ID 1 is always the superadmin
    		if ( $activity->user_id == 1  ) {			
    			
    			unset( $activities->activities[$key] );			
    			
    			$activities->activity_count = $activities->activity_count-1;			
    			$activities->total_activity_count = $activities->total_activity_count-1;			
    			$activities->pag_num = $activities->pag_num -1;				
    		}		
    	}		
    	// Renumber the array keys to account for missing items 	
    	$activities_new = array_values( $activities->activities );		
    	$activities->activities = $activities_new;	
    	
    	return $activities;
    	
    }
    add_action( 'bp_has_activities', 'bpfr_hide_admin_activity', 10, 2 );
    #48441
     sharmstr
    Moderator

    Did you try disabling plugins? Maybe something you have installed is filtering the bp_ajax_querystring after you are.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    This support site is not about custom work. If you need custom development please contact cornel@seventhqueen.com

    #48483
     klosurdo
    Participant

    Tried disabling plugins and its still a no-go.

    #48734
     klosurdo
    Participant

    Giving up on this one. Hopefully a way can be figured out in the future.

Viewing 9 posts - 1 through 9 (of 9 total)

The forum ‘KLEO’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?