Skip to content

Instantly share code, notes, and snippets.

@mihdan
Last active June 1, 2023 02:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mihdan/47f4d1064824a175303dc990b09653f2 to your computer and use it in GitHub Desktop.
Save mihdan/47f4d1064824a175303dc990b09653f2 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Mihdan: Disable Plugins For REST API
* Description: Отключить все плагины при запросах REST API для увеличения скорости ответов
* Version: 1.0
* Author: Mikhail Kobzarev
* Author URI: https://www.kobzarev.com/
*/
if ( false !== strpos( $_SERVER['REQUEST_URI'], '/wp-json' ) ) {
/**
* Отключает плагины, оставляя нужные
*
* @param array $plugins список плагинов
*
* @return array
*/
function mihdan_disable_plugins_for_rest_api( $plugins ) {
$allowed = array(
'mihdan-cabinet/mihdan-cabinet.php',
'mihdan-loadmore/mihdan-loadmore.php',
'mihdan-statistics/mihdan-statistics.php',
);
$plugins = array_intersect( $plugins, $allowed );
return $plugins;
}
add_filter( 'option_active_plugins', 'mihdan_disable_plugins_for_rest_api' );
}
// eof;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment