Request a Quote
Customer Focused
Web Services

Hide a WP user account

October 20, 2021
Code Category:

Basically hides a user account unless you're the user account. Used on a project where I had to allow other Admin users, but I didn't want them messing with my account.

    Hide the Fotan user account on the Dashboard Users screen from everyone but me. 
function yoursite_pre_user_query($user_search) {
  global $current_user;
  $username = $current_user->user_login;

  if ($username != 'fotan') { 
    global $wpdb;
    $user_search->query_where = str_replace('WHERE 1=1',
      "WHERE 1=1 AND {$wpdb->users}.user_login != 'fotan'",$user_search->query_where);
Give us a call (541) 784-5711

Start a converstation

©2022 Fotan Web Design