Last active
June 26, 2017 17:54
-
-
Save Yehonal/fb4fae6110cc1177f1a72d57e1a9b12f to your computer and use it in GitHub Desktop.
[WORDPRESS] Useful filter that allows to exclude specific plugins from a specified ajax action improving performances
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
/** | |
* Useful filter that allows to exclude specific plugins from a specified ajax action improving performances | |
* Depending on quantity of active plugin, it can extremely speedup your ajax calls | |
* NOTE: to exclude plugins from specific pages improving website response please use Plugin Organizer https://it.wordpress.org/plugins/plugin-organizer/ | |
*/ | |
add_filter('option_active_plugins', function ($plugins) { | |
if (!defined('DOING_AJAX') || !DOING_AJAX) | |
return $plugins; | |
// CONFIGURATION: | |
// action (regex string) => plugins | |
// examples: | |
$whitelist_plugins = array( | |
"/ap_ajax/" => array( | |
"anspress-question-answer/anspress-question-answer.php", | |
"mycred/mycred.php" | |
), | |
// simple-press | |
"/^spForum(.*)/" => array( | |
"simple-press/sp-control.php", | |
"mycred/mycred.php" | |
), | |
); | |
$global_whitelist = array( | |
"wp-performance-pack/wp-performance-pack.php", | |
"plugin-organizer/plugin-organizer.php" | |
); | |
// CONFIGURATION END | |
$wt = null; | |
$action = ""; | |
if ((isset($_POST["action"]) && $action = $_POST["action"]) || (isset($_GET["action"]) && $action = $_GET["action"])) { | |
foreach ($whitelist_plugins as $key => $value) { | |
if (preg_match($key,$action)) | |
$wt = $value; | |
} | |
} | |
if ($wt) { | |
foreach ($plugins as $key => $plugin) { | |
if (in_array($plugin, $wt) || in_array($plugin, $global_whitelist)) | |
continue; | |
unset($plugins[$key]); | |
} | |
} | |
return $plugins; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment