Hide admin in users directory

5.66K viewsGeneral
1

You can add following codes to your themes function.php file for hiding Admin only in AP/BP users directory:

add_action(‘pre_user_query’,'ap_pre_user_query'); 
function ap_pre_user_query($user_search) { 
	$user = wp_get_current_user();
	if ($user->ID!=1) { 
		// Is not administrator, remove administrator 
		global $wpdb; 
		$user_search->query_where = str_replace(‘WHERE 1=1′, “WHERE 1=1 AND {$wpdb->users}.ID<>1″,$user_search->query_where); 
	}
}
1

I just found this code below that worked for me. (http://www.trickspanda.com/2014/04/hide-specific-admin-user-list-wordpress/)

add_action(‘pre_user_query’,’ap_pre_user_query’);
function ap_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;

if ($username == ‘<YOUR USERNAME>‘) {

}

else {
global $wpdb;
$user_search->query_where = str_replace(‘WHERE 1=1’,
“WHERE 1=1 AND {$wpdb->users}.user_login != ‘<YOUR USERNAME>‘”,$user_search->query_where);
}
}

Thanks for your sharing… 🙂

You are viewing 1 out of 2 answers, click here to view all answers.