Created
May 11, 2023 15:02
-
-
Save code-flow/90ce0592d8a27de8aa613bb08db433a9 to your computer and use it in GitHub Desktop.
Deactivate WordPress Plugins in the frontend if they're not needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Plugin-Deactivate-Test | |
Version: 1.0.0 | |
*/ | |
// Place this file in wp-content/mu-plugins/ | |
add_filter( 'option_active_plugins', 'mu_deactivate_unnecessary_plugins' ); | |
function mu_deactivate_unnecessary_plugins( $plugin_list ) { | |
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { | |
return $plugin_list; | |
} | |
$current_url = esc_url_raw( $_SERVER['REQUEST_URI'] ); | |
if ( str_contains( $current_url, '/wp-admin' ) || str_contains( $current_url, '/wp-login.php' ) ) { | |
return $plugin_list; | |
} | |
if ( str_contains( $current_url, '/' . rest_get_url_prefix() ) ) { | |
return $plugin_list; | |
} | |
// ... (some other rules) | |
unset( $plugin_list[2], $plugin_list[3], $plugin_list[4] ); // <-- deactivate a bunch of plugin of your choice for testing purposes | |
return $plugin_list; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment