diff --git a/includes/CacheTypes/Skip404.php b/includes/CacheTypes/Skip404.php index fc3c55d..de9a5e1 100644 --- a/includes/CacheTypes/Skip404.php +++ b/includes/CacheTypes/Skip404.php @@ -10,6 +10,9 @@ use function WP_Forge\WP_Htaccess_Manager\addContent; use function WP_Forge\WP_Htaccess_Manager\removeMarkers; +/** + * Skip404 Class + */ class Skip404 extends CacheBase { /** @@ -20,7 +23,7 @@ class Skip404 extends CacheBase { /** * Whether or not the code for this cache type should be loaded. * - * @param Container $container + * @param Container $container the container. * * @return bool */ @@ -33,35 +36,9 @@ public static function shouldEnable( Container $container ) { */ public function __construct() { - new OptionListener( Performance::OPTION_SKIP_404, [ __CLASS__, 'maybeAddRules' ] ); - - add_filter( 'newfold_update_htaccess', [ $this, 'onUpdateHtaccess' ] ); - add_action( 'admin_init', [ $this, 'registerSettings' ], 11 ); - } - - /** - * Register our setting to the main performance settings section. - */ - public function registerSettings() { - - global $wp_settings_fields; - - add_settings_field( - Performance::OPTION_SKIP_404, - __( 'Skip WordPress 404 Handling For Static Files', 'newfold-performance-module' ), - 'NewfoldLabs\\WP\\Module\\Performance\\getSkip404InputField', - 'general', - Performance::SETTINGS_SECTION - ); - - register_setting( 'general', Performance::OPTION_SKIP_404 ); - - // Remove the setting from EPC if it exists - TODO: Remove when no longer using EPC - if ( $this->container->get( 'hasMustUsePlugin' ) ) { - unset( $wp_settings_fields['general']['epc_settings_section'] ); - unregister_setting( 'general', 'epc_skip_404_handling' ); - } + new OptionListener( Performance::OPTION_SKIP_404, array( __CLASS__, 'maybeAddRules' ) ); + add_filter( 'newfold_update_htaccess', array( $this, 'onUpdateHtaccess' ) ); } /** @@ -80,7 +57,7 @@ public function onUpdateHtaccess() { /** * Conditionally add or remove .htaccess rules based on option value. * - * @param bool|null $shouldSkip404Handling + * @param bool|null $shouldSkip404Handling if should skip 404 handling. */ public static function maybeAddRules( $shouldSkip404Handling ) { (bool) $shouldSkip404Handling ? self::addRules() : self::removeRules(); @@ -124,5 +101,4 @@ public static function onActivation() { public static function onDeactivation() { self::removeRules(); } - } diff --git a/includes/Performance.php b/includes/Performance.php index c58fda6..6aeb2cf 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -103,7 +103,7 @@ function () { * Add hooks. */ public function hooks() { - + add_action( 'admin_init', array( $this, 'removeEPC_settings' ), 99 ); new OptionListener( self::OPTION_CACHE_LEVEL, array( $this, 'onCacheLevelChange' ) ); /** @@ -134,6 +134,23 @@ function () { add_filter( 'action_scheduler_cleanup_batch_size', array( $this, 'nfd_as_cleanup_batch_size' ) ); } + /** + * Remove EPC Settings if needed + * + * @return void + */ + public function removeEPC_settings() { + global $wp_settings_fields, $wp_settings_sections; + //phpcs:ignore + // Remove the setting from EPC if it exists - TODO: Remove when no longer using EPC + if ( $this->container->get( 'hasMustUsePlugin' ) ) { + unset( $wp_settings_fields['general']['epc_settings_section'] ); + unset( $wp_settings_sections['general']['epc_settings_section'] ); + unregister_setting( 'general', 'endurance_cache_level' ); + unregister_setting( 'general', 'epc_skip_404_handling' ); + } + } + /** * Update the default action scheduler retention period to 5 days instead of 30. * The actions scheduler table tends to grow to gigantic sizes and this should help.