Skip to content

Commit

Permalink
fixed epc settings still showing in hostgator
Browse files Browse the repository at this point in the history
  • Loading branch information
geckod22 committed Dec 2, 2024
1 parent 88e2d9d commit 03d7538
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 32 deletions.
38 changes: 7 additions & 31 deletions includes/CacheTypes/Skip404.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand All @@ -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
*/
Expand All @@ -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' ) );
}

/**
Expand All @@ -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();
Expand Down Expand Up @@ -124,5 +101,4 @@ public static function onActivation() {
public static function onDeactivation() {
self::removeRules();
}

}
19 changes: 18 additions & 1 deletion includes/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );

/**
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 03d7538

Please sign in to comment.