/**
* TOTAL SITE LOCKDOWN
* 1. Protects specific security plugins from deactivation.
* 2. Blocks ALL new plugin installations and searches globally.
* 3. Removes "Deactivate" from Bulk Actions.
*/
// --- 1. PROTECT SPECIFIC PLUGINS FROM DEACTIVATION ---
add_filter( 'plugin_action_links', 'lock_essential_plugin_deactivation', 10, 2 );
function lock_essential_plugin_deactivation( $actions, $plugin_file ) {
// List of plugins from your images (Wordfence, Activity Log, Site Editor)
$protected_plugins = array(
'wordfence/wordfence.php',
'wp-security-audit-log/wp-security-audit-log.php',
'wp-site-editor/wp-site-editor.php'
);
if ( in_array( $plugin_file, $protected_plugins ) && isset( $actions['deactivate'] ) ) {
unset( $actions['deactivate'] );
}
return $actions;
}
// --- 2. DISABLE BULK DEACTIVATION ---
add_filter( 'bulk_actions-plugins', 'disable_bulk_plugin_deactivation' );
function disable_bulk_plugin_deactivation( $actions ) {
unset( $actions['deactivate-selected'] );
return $actions;
}
// --- 3. GLOBAL INSTALLATION LOCK (HIDES ADD NEW & BLOCKS API) ---
// Remove "Add New" from the Sidebar Menu
add_action( 'admin_menu', 'remove_plugin_install_menu', 999 );
function remove_plugin_install_menu() {
remove_submenu_page( 'plugins.php', 'plugin-install.php' );
}
// Block the Plugin API (Stops all searches and installation attempts)
add_filter( 'plugins_api', 'block_all_plugin_installations', 10, 3 );
function block_all_plugin_installations( $res, $action, $args ) {
return new WP_Error( 'locked', 'Security Policy: Plugin installation is disabled on this site.' );
}
// Hide the "Add New" button on the main Plugins page via CSS
add_action( 'admin_head', 'hide_add_new_plugin_ui' );
function hide_add_new_plugin_ui() {
echo '';
}
Our Work - Book Construction Skip to content