Last active
June 1, 2023 02:43
-
-
Save mihdan/47f4d1064824a175303dc990b09653f2 to your computer and use it in GitHub Desktop.
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: 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