fictioneer/mu-plugins/fictioneer_001_fast_requests.php

103 lines
2.9 KiB
PHP
Raw Normal View History

2023-08-21 11:40:14 +02:00
<?php
/**
* Plugin Name: Fictioneer Fast Requests
* Description: Skips plugins for faster requests.
* Version: 1.0
* Author: Tetrakern
* Author URI: https://github.com/Tetrakern
* Donate link: https://ko-fi.com/tetrakern
* License: GNU General Public License v3.0 or later
* License URI: http://www.gnu.org/licenses/gpl.html
*/
// Check if AJAX request
if (
( defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
isset( $_REQUEST['fcn_fast_ajax'] ) &&
strpos( $_REQUEST['action'] ?? '', 'fictioneer_ajax' ) === 0 &&
strpos( $_REQUEST['action'] ?? '', '_comment' ) === false
2023-08-21 11:40:14 +02:00
) {
add_filter( 'option_active_plugins', 'fictioneer_exclude_plugins' );
}
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
2023-08-24 02:37:15 +02:00
// Check REST Request
if ( strpos( $request_uri, 'wp-json/fictioneer/' ) !== false ) {
add_filter( 'option_active_plugins', 'fictioneer_exclude_plugins' );
}
/**
* Filters the list of active plugins
*
* @since 1.0.0
*
* @param array $plugins An array of active plugin paths.
*
* @return array Filtered array of active plugins.
*/
function fictioneer_exclude_plugins( $plugins ) {
// Setup
$allow_list = array(
'fictioneer-email-subscriptions/fictioneer-email-subscriptions.php'
);
// Remove not allowed plugins
foreach ( $plugins as $index => $plugin ) {
if ( ! in_array( $plugin, $allow_list ) ) {
unset( $plugins[ $index ] );
}
}
// Continue filter
return $plugins;
}
// Check if AJAX comment request
if (
get_option( 'fictioneer_enable_fast_ajax_comments' ) &&
( defined( 'DOING_AJAX' ) && DOING_AJAX ) &&
strpos( $_REQUEST['action'] ?? '', 'fictioneer_ajax' ) === 0 &&
strpos( $_REQUEST['action'] ?? '', '_comment' ) !== false
) {
2023-08-24 02:37:15 +02:00
add_filter( 'option_active_plugins', 'fictioneer_exclude_plugins_while_commenting' );
2023-08-21 11:40:14 +02:00
}
/**
2023-08-24 02:37:15 +02:00
* Filters the list of active plugins when commenting
2023-08-21 11:40:14 +02:00
*
* @since 1.0.0
*
* @param array $plugins An array of active plugin paths.
*
* @return array Filtered array of active plugins.
*/
2023-08-24 02:37:15 +02:00
function fictioneer_exclude_plugins_while_commenting( $plugins ) {
2023-08-21 11:40:14 +02:00
// Setup
$allow_list = array(
2023-08-24 02:37:15 +02:00
'w3-total-cache/w3-total-cache.php', // W3 Total Cache
'wp-super-cache/wp-cache.php', // WP Super Cache
'wp-rocket/wp-rocket.php', // WP Rocket
'litespeed-cache/litespeed-cache.php', // LiteSpeed Cache
'wp-fastest-cache/wpFastestCache.php', // WP Fastest Cache
'cache-enabler/cache-enabler.php', // Cache Enabler
'hummingbird-performance/wp-hummingbird.php', // Hummingbird Optimize Speed, Enable Cache
'wp-optimize/wp-optimize.php', // WP-Optimize - Clean, Compress, Cache
'sg-cachepress/sg-cachepress.php', // SG Optimizer (SiteGround)
'breeze/breeze.php', // Breeze (by Cloudways)
'nitropack/nitropack.php' // NitroPack
2023-08-21 11:40:14 +02:00
);
// Remove not allowed plugins
foreach ( $plugins as $index => $plugin ) {
if ( ! in_array( $plugin, $allow_list ) ) {
unset( $plugins[ $index ] );
}
}
// Continue filter
return $plugins;
}