Hide a user from WordPress

You’re wanting to hide a user from WordPress in three places:

  1. The user list in the admin
  2. The count above that user list
  3. The user’s author archive on the front-end

As you mentioned, you’ve already solved item 1 and you’ve included the code for that. So, I’ll provide the solutions for items 2 and 3.

The user you want to hide is an administrator with a user ID of 1, so I’m working on that assumption. I’ve also assumed it’s the only administrator user there. For anyone who comes across this answer later, you’ll need to modify the code accordingly if you want to hide a different user/user group.

Modifying the user counts

Unfortunately the count_users() function isn’t filterable. But, the user counts are shown within the hyperlinks to the different user views, which are output by the WP_List_Table::views() function. These views are filterable using a dynamic filter, views_{$this->screen->id}, which on the users page, translates to views_users.

So, we’re going to hook into this filter and do two things: remove the Administrator view completely, and decrease the count by 1 in the All view. We’ll only do this if the currently logged in user isn’t our superuser (ID === 1).

add_filter( 'views_users', 'wpse230495_modify_user_views' );

function wpse230495_modify_user_views( $views ) {

  if( get_current_user_id() === 1 ) { return $views; } // bow out if we're user number 1

  // filter the 'all' count and remove 1 from it
  $views['all'] = preg_replace_callback(
    '/\(([0-9]+)\)/',
     function( $matches ){ return '(' . ( $matches[1] - 1 ) . ')'; },
     $views['all']
  );

  // filter the 'administrator' count and remove 1 from it
  $views['administrator'] = preg_replace_callback(
    '/\(([0-9]+)\)/',
     function( $matches ){ return '(' . ( $matches[1] - 1 ) . ')'; },
     $views['administrator']
  );

  // alternatively, uncomment next line if you want to remove Administrator view completely
  // unset( $views["administrator"] );

  return $views;

}

Hiding a user’s author archive on the front-end

This is a bit simpler. All we’re going to do here is hook into the template_redirect action to redirect a visitor back to the home page if they try to access the author archive of our privileged user.

add_action( 'template_redirect', 'wpse230495_author_archive_redirect' );

function wpse230495_author_archive_redirect() {
   if( is_author() && get_the_author_meta('ID') === 1 ) {
       wp_redirect( home_url(), 301 );
       exit;
   }
}

The above code blocks are tested on WordPress 4.5.3 (albeit with only one user in my test install – if your results vary do let me know!).