This topic has 17 replies, 3 voices, and was last updated 7 years by Roader.

  • Author
  • #146842
     Roader
    Participant

    Where is Admin here?  Is Hidden!

    How?   Using this php code in functions.php

    This is a security measures, because if a hacker see your username, maybe he can try to hack you.

    For this reason, you can Hide the Super Admin, and create a General Moderator for your site.  In this situation Super Admin is only for Maintenance.

     

    But, this code is incomplete, because it  does not hide super admin’s vcard from BuddyPress Widgets. 

    So, Please, Radu and others, Tell us How we can Hide super admin using php. 

     

     

    <——————– 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 );

     

     

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

     

     

     

     

     

    Attachments:
    You must be logged in to view attached files.
    #146872
     Laura
    Moderator

    Hello, this is not something related to the theme but Buddypress plugin, which is the plugin that handles profiles, member directory, groups…
    Said so, there are many topics around buddypress forum regarding this matter, so it will be easy for you to find the answers there 🙂
    Such as:
    -https://buddypress.org/support/topic/hide-admin-from-members-and-activity/
    -https://buddypress.org/support/search/hide+admin+in+directory/

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

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #146954
     Roader
    Participant

    Querida Laura. Yo tomé los códigos de esos enlaces previamente. Pero ahí no aparece cómo esconder el Admin de los WidGets de BP. Por esa razón abrí este Ticket aquí a ver si tú o Radu me ayudan.

    #147068
     Laura
    Moderator

    Hola, prueba https://premium.wpmudev.org/forums/topic/exclude-users-from-buddypress-members-widget

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

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #147179
     Roader
    Participant

    Tampoco me sirve ese link Laura.

    #147394
     Laura
    Moderator

    Hola, ahora mismo no hay nada mas 🙁

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

    Laura Solanes - Graphic Designer and Web Designer

    Please be patient as I try to answer each topic as fast as i can.

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Always happy to help you 🙂

    #147605
     Roader
    Participant

    Laura, plis, pídele a Radu que revise, ya que él maneja más el php quizás sepa algo.

    #147896
     Radu
    Moderator

    Hi,

    IF that code doesn’t work on BuddyPress widgets ask this on BuddyPress forums since we not change the logic of BuddyPress widgets.

    Cheers
    R.

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

    For now the solution is:

    #members-list > li:nth-child(1) {
    display: none;
    }

    #147953
     Roader
    Participant

    Theme Options / Styling options / Quick CSS

    #members-list > li.vcard:nth-child(1) {
    display: none;
    }

    #147970
     Roader
    Participant

    🙁 bad solution. This css works when you are login using user#1 but, for other user, user#1 is visible (>_<)

    I need a Php code for that. Is VERY, VERY important to hide Super Admin or Admins.

    #148096
     Radu
    Moderator

    Hi,

    Please see this guide: https://buddydev.com/buddypress/exclude-users-from-members-directory-on-a-buddypress-based-social-network/
    It should work.

    There are more solutions on the web regarding to this, test and find the perfect one for you..

    Cheers
    R.

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

    From Member Directory NOT! I have this solution! (Check the code up)

    Is from BuddyPress WIDGETS the big problem!

    Please!

    #148131
     Roader
    Participant

    Now I go to try this… and I tell you later. https://buddydev.com/buddypress/hiding-users-on-buddypress-based-site/

    My friend Radu, you know, WordPress needs a lot of Security… and BuddyPress MORE!

    #148140
     Roader
    Participant

    FULL CODE:::

    // Exclude Admins 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, separated by comma

    $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 );

    #148141
     Roader
    Participant
    COPY CODE
    <strong>FULL CODE:::</strong>
    
    // Exclude Admins 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, separated by comma
        
        
        $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 );
    
    
    #148142
     Roader
    Participant

    And thanks Radu for the Link 😉

    #148144
     Roader
    Participant

    OTHER CODE::::

    COPY CODE
    // 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');
    
    
Viewing 18 posts - 1 through 18 (of 18 total)

You must be logged in to reply to this topic.

Log in with your credentials

Forgot your details?