• I having this annoying problem, need to hide the Administrator for the other users at the user list…like in the image:
    https://drive.google.com/file/d/0Bzqs439iIKtxSGlWLXNTbVp2Wmc/edit?usp=sharing

    so..i need the shop manager just see hes own account or the other clientes future accounts, but not the administrator account.

    I tried all things saw online but nothing works, like:

    add_action(‘pre_user_search’,’yoursite_pre_user_search’);
    function yoursite_pre_user_search($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);
    }
    }

    please im pretty newby,someone can help me?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter mucheroni

    (@mucheroni)

    version is 3.9.1

    Moderator bcworkz

    (@bcworkz)

    You’re actually very close, it’s just a matter of sorting out the syntax errors. For that, I’m not of much help, mySQL is not something I am strong at. Here is my guess at the correct syntax:
    $user_search->query_where = str_replace('WHERE 1=1', "$wpdb->users.ID!=1",$user_search->query_where);

    This assumes the one and only administrator’s ID is 1, which may be true for many sites, but you should confirm your site’s specifics. A more robust approach would be to query for all users with admin roles, then implode the resulting IDs into a comma delimited list, say into $admin_ids, then the WHERE query becomes this;
    $user_search->query_where = str_replace('WHERE 1=1', "$wpdb->users.ID NOT IN ($admin_ids)",$user_search->query_where);

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Hide Admin from user list’ is closed to new replies.