From 0939baf385a083a747ef267d6a2cc4ae2b7a1914 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 20 Nov 2024 16:01:55 +0000 Subject: [PATCH 1/5] added sub menu Performance link in settings --- includes/Performance.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/includes/Performance.php b/includes/Performance.php index ac50c2f..8ce0db1 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -2,9 +2,6 @@ namespace NewfoldLabs\WP\Module\Performance; -use NewfoldLabs\WP\Module\Performance\CacheTypes\Browser; -use NewfoldLabs\WP\Module\Performance\CacheTypes\File; -use NewfoldLabs\WP\Module\Performance\CacheTypes\Skip404; use NewfoldLabs\WP\ModuleLoader\Container; /** @@ -77,6 +74,8 @@ public function __construct( Container $container ) { add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 ); } + add_action( 'admin_menu', array( $this, 'add_sub_menu_page' ) ); + $container->set( 'cachePurger', $cachePurger ); $container->set( 'hasMustUsePlugin', file_exists( WPMU_PLUGIN_DIR . '/endurance-page-cache.php' ) ); @@ -105,10 +104,8 @@ function () { /** * Add hooks. - * - * @param Container $container the container */ - public function hooks( Container $container ) { + public function hooks() { add_action( 'admin_init', array( $this, 'registerSettings' ), 11 ); @@ -149,11 +146,9 @@ function () { * @hooked action_scheduler_retention_period * @see ActionScheduler_QueueCleaner::delete_old_actions() * - * @param int $retention_period Minimum scheduled age in seconds of the actions to be deleted. - * * @return int New retention period in seconds. */ - public function nfd_asr_default( $retention_period ) { + public function nfd_asr_default() { return 5 * constant( 'DAY_IN_SECONDS' ); } @@ -292,4 +287,19 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) { ); } } + + /** + * Add performance menu in WP/Settings + */ + public function add_sub_menu_page() { + $brand = $this->container->get( 'plugin' )['id']; + add_options_page( + __( 'Performance', 'newfold-performance-module' ), + __( 'Performance', 'newfold-performance-module' ), + 'manage_options', + admin_url( "admin.php?page=$brand#/performance" ), + null, + 5 + ); + } } From 28e091542c1265126e8ac33e4df2ade074f60b77 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Thu, 21 Nov 2024 12:06:01 +0000 Subject: [PATCH 2/5] remove old settings option in WP > Settings page --- includes/Performance.php | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/includes/Performance.php b/includes/Performance.php index 8ce0db1..c3c9253 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -69,10 +69,7 @@ public function __construct( Container $container ) { $cacheManager = new CacheManager( $container ); $cachePurger = new CachePurgingService( $cacheManager->getInstances() ); - // Ensure that purgeable cache types are enabled before showing the UI. - if ( $cachePurger->canPurge() ) { - add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 ); - } + add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 ); add_action( 'admin_menu', array( $this, 'add_sub_menu_page' ) ); @@ -107,8 +104,6 @@ function () { */ public function hooks() { - add_action( 'admin_init', array( $this, 'registerSettings' ), 11 ); - new OptionListener( self::OPTION_CACHE_LEVEL, array( $this, 'onCacheLevelChange' ) ); /** @@ -203,39 +198,6 @@ public function onCacheLevelChange( $cacheLevel ) { } } - /** - * Register settings - */ - public function registerSettings() { - - global $wp_settings_fields; - - $section_name = self::SETTINGS_SECTION; - - add_settings_section( - $section_name, - '' . esc_html__( 'Caching', 'newfold-performance-module' ) . '', - '__return_false', - 'general' - ); - - add_settings_field( - self::OPTION_CACHE_LEVEL, - __( 'Cache Level', 'newfold-performance-module' ), - __NAMESPACE__ . '\\getCacheLevelDropdown', - 'general', - $section_name - ); - - register_setting( 'general', self::OPTION_CACHE_LEVEL ); - - // 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', 'endurance_cache_level' ); - } - } - /** * Add options to the WordPress admin bar. * From 88e2d9de72fb0f757f05ddb620a46add736c14e6 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Tue, 26 Nov 2024 12:28:04 +0000 Subject: [PATCH 3/5] added also the dynamic from Press7-78 --- includes/Performance.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Performance.php b/includes/Performance.php index c3c9253..c58fda6 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -239,12 +239,13 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) { ); } + $brand = $this->container->get( 'plugin' )['id']; $wp_admin_bar->add_node( array( 'id' => 'nfd_purge_menu-cache_settings', 'title' => __( 'Cache Settings', 'newfold-module-performance' ), 'parent' => 'nfd_purge_menu', - 'href' => admin_url( 'options-general.php#' . Performance::SETTINGS_ID ), + 'href' => admin_url( "admin.php?page=$brand#/performance" ), ) ); } From 03d7538ed5f2dcf9e0b15978a13b00c4bde0c3b3 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Mon, 2 Dec 2024 13:22:21 +0000 Subject: [PATCH 4/5] fixed epc settings still showing in hostgator --- includes/CacheTypes/Skip404.php | 38 ++++++--------------------------- includes/Performance.php | 19 ++++++++++++++++- 2 files changed, 25 insertions(+), 32 deletions(-) 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. From dbf12eb0ca17f2c8918cc4623b6dfd2b7c224775 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 18 Dec 2024 09:42:13 +0000 Subject: [PATCH 5/5] move menu to tools --- includes/Performance.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Performance.php b/includes/Performance.php index 6aeb2cf..05081d2 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -273,7 +273,7 @@ public function adminBarMenu( \WP_Admin_Bar $wp_admin_bar ) { */ public function add_sub_menu_page() { $brand = $this->container->get( 'plugin' )['id']; - add_options_page( + add_management_page( __( 'Performance', 'newfold-performance-module' ), __( 'Performance', 'newfold-performance-module' ), 'manage_options',