Skip to content

Instantly share code, notes, and snippets.

@aliboy08
Created September 13, 2024 10:31
Show Gist options
  • Save aliboy08/4810a71488eb8a5487fcafa2ae638595 to your computer and use it in GitHub Desktop.
Save aliboy08/4810a71488eb8a5487fcafa2ae638595 to your computer and use it in GitHub Desktop.
plugin disabler
<?php
/*
Plugin Name: FF Plugin Disabler
Description: Disable selected plugins for optimization
Version: 2.0
Author: Five by Five
Author URI: https://www.fivebyfive.com.au/
*/
if( strpos( $_SERVER['REQUEST_URI'], '/wp-admin/' ) !== false ) return; // front-end only
$GLOBALS['plugin_activate_run_once'] = 0;
add_filter( 'option_active_plugins', function( $plugins ){
if( $GLOBALS['plugin_activate_run_once'] ) return $plugins;
$GLOBALS['plugin_activate_run_once'] = 1;
if( $_SERVER['REQUEST_URI'] == '/' ) {
return ff_disable_plugins_home( $plugins );
}
return $plugins;
});
function ff_disable_plugins_home( $plugins ) {
$disable_plugins = [
];
$is_ajax = isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) === 'xmlhttprequest';
if( defined('DOING_AJAX') && DOING_AJAX ) {
$is_ajax = true;
}
if( !$is_ajax ) {
// $disable_plugins[] = '';
}
foreach ( $disable_plugins as $plugin ) {
$k = array_search( $plugin, $plugins );
if( false !== $k ){
unset( $plugins[$k] );
}
}
// echo '<pre>'. print_r( $plugins, true ) .'</pre>';
return $plugins;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment