← Back to Blog

Force Hide All Users in UsersWP

This solution completely hides all users from member directories while preserving their original settings.

Implementation

class Force_Hide_UsersWP_Users {
    public function __construct() {
        add_filter('get_user_metadata', [$this, 'force_hide'], 10, 4);
        add_filter('uwp_get_excluded_users_list', [$this, 'exclude_all']);
    }

    public function force_hide($value, $user_id, $meta_key, $single) {
        if (in_array($meta_key, ['uwp_hide_from_listing', 'uwp_make_profile_private'])) {
            return 1;
        }
        return $value;
    }

    public function exclude_all($excluded) {
        $all_users = get_users(['fields' => 'ID', 'number' => -1]);
        return array_merge($excluded, $all_users);
    }
}
new Force_Hide_UsersWP_Users();

What It Does

  1. Forces uwp_hide_from_listing and uwp_make_profile_private to be enabled for all users
  2. Adds all users to the excluded list
  3. Preserves original database values

Simply add to your theme's functions.php or a custom plugin.