Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to Hide Admin accounts 2016?

Viewing 13 replies - 1 through 13 (of 13 total)

  • Henry Wright
    Moderator

    @henrywright


    semperaye
    Participant

    @semperaye

    say what lol?


    semperaye
    Participant

    @semperaye

    There is this code posted by someone on this thread 2.5 years ago:

    https://buddypress.org/support/topic/hide-certain-admins-as-being-online/

    /* disable Recording Site Activity for Admins */
    add_action(“bp_loaded”,”bpdev_init_sm_mode”);
    function bpdev_init_sm_mode(){
    if(is_super_admin())
    remove_action(“wp_head”,”bp_core_record_activity”);//id SM is on, remove the record activity hook
    }
    /* ——————————————– */

    But not sure if that is custom css, or if that is something that needs to be placed in the bp-custom.php file? Also, that code appears to only block admin activity, not profile, and members list….

    Is there a way to do all of this via some custom CSS? That would obviously be the easiest way to solve this since there are no currently working plugins.


    Henry Wright
    Moderator

    @henrywright

    Hi @semperaye

    Unfortunately, CSS isn’t a great solution here. To get this done properly, you will need to do 3 things:

    1. Profile

    Either implement a redirect or respond with a 404 page not found when an admin profile is visited.

    2. Member directory

    Use bp_parse_args() to filter the loop so that all admins are removed.

    3. Activity stream

    Again you can use bp_parse_args() to filter the loop so that all admins are removed.


    Jakob
    Participant

    @jakobbader

    What happened to the plugin “BP Hide User” from r-a-y? I can’t find it anymore on wordpress.org, it did worke well.


    semperaye
    Participant

    @semperaye

    @jakobbader,

    I saw that plugin a few weeks ago, tried to find it again, and now it’s gone…


    ericreynolds007
    Participant

    @ericreynolds007


    Im_a_MARVEL
    Participant

    @im_a_marvel

    Here’s the best thing that works https://buddydev.com/buddypress/hiding-users-on-buddypress-based-site/
    Like a charm


    Jakob
    Participant

    @jakobbader


    semperaye
    Participant

    @semperaye

    I couldn’t get the plugin from github to work. The instructions said to click the hide user button but there isn’t one.


    semperaye
    Participant

    @semperaye

    Note: Although that plugin from github isn’t working as described, it seems to have filtered my admins from my members list so I guess it worked somehow 😛

    If it ends up not working, do we just copy and past the text from buddydev into customcss?


    livingflame
    Participant

    @livingflame

    @henrywright

    This work okey –>: but, How I can Hide Admin from BuddyPress Widget??

    —->

    // 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 );
    
    // 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 );
    
    // 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');
    
    

    livingflame
    Participant

    @livingflame

    Solution: HIDE ADMIN FROM BP WIDGETS AND DIRECTORY

    This code is complementary for the other ==>

    Hiding Users on BuddyPress based site

    So, full code:

    
    // Exclude Admin from Directories and BP Widgets 
    add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users' );
     
    function buddydev_exclude_users( $args ) {
        //do not exclude in admin
        if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
            return $args;
        }
        
        $excluded = isset( $args['exclude'] )? $args['exclude'] : array();
     
        if( !is_array( $excluded ) ) {
            $excluded = explode(',', $excluded );
        }
        
        $user_ids = array( 1, ); // enter user ids here
        
        
        $excluded = array_merge( $excluded, $user_ids );
        
        $args['exclude'] = $excluded;
        
        return $args;
    }
    
    // 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 );
    
    // 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 );
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] How to Hide Admin accounts 2016?’ is closed to new replies.
Skip to toolbar