Last active
December 6, 2024 06:15
-
-
Save aliboy08/4810a71488eb8a5487fcafa2ae638595 to your computer and use it in GitHub Desktop.
plugin disabler
This file contains hidden or 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: 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 | |
class FF_Plugin_Disabler { | |
public $done = false; | |
public $disable_plugins_homepage = []; | |
function init(){ | |
add_filter( 'option_active_plugins', function($plugins){ | |
if( $this->done ) return $plugins; | |
$this->done = true; | |
if( $_SERVER['REQUEST_URI'] === '/' && $this->disable_plugins_homepage ) { | |
if( defined('DOING_AJAX') ) return $plugins; | |
foreach( $plugins as $index => $plugin ) { | |
if( in_array($plugin, $this->disable_plugins_homepage) ) { | |
unset($plugins[$index]); | |
} | |
} | |
} | |
return $plugins; | |
}); | |
} | |
} | |
$disabler = new FF_Plugin_Disabler(); | |
$disabler->init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment