From 91a1fcac746f8c783f775dadf580c16df5cdf7a7 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 6 Nov 2024 13:27:21 +0000 Subject: [PATCH 01/42] possible cache fix on option update --- includes/Performance.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/Performance.php b/includes/Performance.php index ac50c2f..8d2c9c2 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -200,7 +200,11 @@ public function onCacheLevelChange( $cacheLevel ) { */ $responseHeaderManager = $this->container->get( 'responseHeaderManager' ); $responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', absint( $cacheLevel ) ); - + + Browser::maybeAddRules( $cacheLevel ); + File::maybeAddRules( $cacheLevel ); + Skip404::maybeAddRules( $cacheLevel ); + // Remove the old option from EPC, if it exists if ( $this->container->get( 'hasMustUsePlugin' ) && absint( get_option( 'endurance_cache_level', 0 ) ) ) { update_option( 'endurance_cache_level', 0 ); From b3a6f4992a0ad09a8638af3b03c627d15e7b6d39 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 6 Nov 2024 14:10:21 +0000 Subject: [PATCH 02/42] added restApi class to update the option --- includes/Performance.php | 4 +- includes/RestApi/CacheSettings.php | 112 +++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 includes/RestApi/CacheSettings.php diff --git a/includes/Performance.php b/includes/Performance.php index 8d2c9c2..4fa5d13 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -200,11 +200,11 @@ public function onCacheLevelChange( $cacheLevel ) { */ $responseHeaderManager = $this->container->get( 'responseHeaderManager' ); $responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', absint( $cacheLevel ) ); - + Browser::maybeAddRules( $cacheLevel ); File::maybeAddRules( $cacheLevel ); Skip404::maybeAddRules( $cacheLevel ); - + // Remove the old option from EPC, if it exists if ( $this->container->get( 'hasMustUsePlugin' ) && absint( get_option( 'endurance_cache_level', 0 ) ) ) { update_option( 'endurance_cache_level', 0 ); diff --git a/includes/RestApi/CacheSettings.php b/includes/RestApi/CacheSettings.php new file mode 100644 index 0000000..894de2a --- /dev/null +++ b/includes/RestApi/CacheSettings.php @@ -0,0 +1,112 @@ +container = $container; + } + + /** + * Registers rest routes for PluginsController class. + * + * @return void + */ + public function register_routes() { + \register_rest_route( + $this->namespace, + $this->rest_base . '/settings', + array( + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_settings' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ), + ) + ); + \register_rest_route( + $this->namespace, + $this->rest_base . '/update', + array( + array( + 'methods' => \WP_REST_Server::CREATABLE, + 'callback' => array( $this, 'update_settings' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ), + ) + ); + } + + /** + * Get the settings + * + * @return \WP_REST_Response + */ + public function get_settings() { + return new \WP_REST_Response( + array( + 'settings' => get_option( 'cache_exlusion', '' ), + ), + 200 + ); + } + + /** + * Update the settings + * + * @param \WP_REST_Request $request the request. + * @return \WP_REST_Response + */ + public function update_settings( \WP_REST_Request $request ) { + $cache_exlusion = $request->get_param( 'cache_exlusion' ); + if ( update_option( 'cache_exlusion', $cache_exlusion ) ) { + return new \WP_REST_Response( + array( + 'result' => true, + ), + 200 + ); + } + + return new \WP_REST_Response( + array( + 'result' => false, + ), + 400 + ); + } +} From e3c3fb6b69a8403a7f5f77ddcfaee55cd2614f9d Mon Sep 17 00:00:00 2001 From: Alessio Torrisi Date: Wed, 6 Nov 2024 16:20:20 +0100 Subject: [PATCH 03/42] New: Cache Exclusion option --- components/cacheExclusion/index.js | 63 +++++++++++++++++++++++++++ components/performance/defaultText.js | 5 +++ components/performance/index.js | 7 +++ 3 files changed, 75 insertions(+) create mode 100644 components/cacheExclusion/index.js diff --git a/components/cacheExclusion/index.js b/components/cacheExclusion/index.js new file mode 100644 index 0000000..71eaf05 --- /dev/null +++ b/components/cacheExclusion/index.js @@ -0,0 +1,63 @@ +import { Button, Container, TextareaField } from "@newfold/ui-component-library"; + +const CacheExclusion = ({ methods, constants }) => { + + const [ currentValue, setCurrentValue ] = methods.useState(constants.store.cacheExclusion); + const [ isEdited, setIsEdited ] = methods.useState(false); + const [ cacheExclusion, setCacheExclusion ] = methods.useState(constants.store.cacheExclusion); + + + const handleCacheExclusionChange = (e) => { + if( e.target.value !== cacheExclusion ) { + setIsEdited(true); + }else{ + setIsEdited(false); + } + setCurrentValue( e.target.value ); + } + + + const handlingSaveButton = () => { + methods.newfoldSettingsApiFetch( + { cacheExclusion: currentValue }, + methods.setError, (response) => { + setCacheExclusion( currentValue ) + methods.makeNotice( + "disable-old-posts-comments-notice", + constants.text.cacheExclusionSaved, + null, + "success", + 5000 + ); + setIsEdited(false); + } + ); + + }; + + return ( + + + + + + + ); +;} + +export default CacheExclusion; \ No newline at end of file diff --git a/components/performance/defaultText.js b/components/performance/defaultText.js index 2603b96..0f61643 100644 --- a/components/performance/defaultText.js +++ b/components/performance/defaultText.js @@ -22,6 +22,11 @@ const defaultText = { clearCacheDescription: __('We automatically clear your cache as you work (creating content, changing settings, installing plugins and more). But you can manually clear it here to be confident it is fresh.', 'wp-module-performance'), clearCacheNoticeTitle: __('Cache cleared', 'wp-module-performance'), clearCacheTitle: __('Clear Cache', 'wp-module-performance'), + clearCacheTitle: __('Clear Cache', 'wp-module-performance'), + cacheExclusionTitle: __( 'Exclude from cache', 'wp-module-performance' ), + cacheExclusionDescription: __( 'This setting controls what pages pass a “no-cache” header so that page caching and browser caching is not used.', 'wp-module-performance' ), + cacheExclusionSaved: __( 'Cache Exclusion saved', 'wp-module-performance' ), + cacheExclusionSaveButton: __( 'Save', 'wp-module-performance' ), }; export default defaultText; \ No newline at end of file diff --git a/components/performance/index.js b/components/performance/index.js index e6d7483..ed480e2 100644 --- a/components/performance/index.js +++ b/components/performance/index.js @@ -1,6 +1,7 @@ import { Container } from '@newfold/ui-component-library'; import { default as CacheSettings } from '../cacheSettings/'; import { default as ClearCache } from '../clearCache/'; +import { default as CacheExclusion } from '../cacheExclusion/'; import { default as defaultText } from './defaultText'; /** @@ -45,6 +46,12 @@ const Performance = ({methods, constants, Components, ...props}) => { Components={Components} /> + + + Date: Thu, 7 Nov 2024 11:43:18 +0000 Subject: [PATCH 04/42] register the api and add the value to runtime --- includes/CacheManager.php | 50 ++++++++++++++++++- ...tings.php => CacheExclusionController.php} | 14 +++--- 2 files changed, 56 insertions(+), 8 deletions(-) rename includes/RestApi/{CacheSettings.php => CacheExclusionController.php} (85%) diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 38da5eb..3503f55 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -3,6 +3,7 @@ namespace NewfoldLabs\WP\Module\Performance; use NewfoldLabs\WP\Module\Performance\CacheTypes\CacheBase; +use NewfoldLabs\WP\Module\Performance\RestApi\CacheExclusionController; use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\Collection\Collection; @@ -15,13 +16,60 @@ class CacheManager { */ protected $container; + /** + * Array map of API controllers. + * + * @var array + */ + protected $controllers = array( + 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\CacheExclusionController', + ); + /** * Constructor. * - * @param string[] $supportedCacheTypes Cache types supported by the plugin + * @param string[] $supportedCacheTypes Cache types supported by the plugin */ public function __construct( Container $container ) { $this->container = $container; + + add_action( 'rest_api_init', array( $this, 'register_routes' ) ); + add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) ); + } + + /** + * Register API routes. + */ + public function register_routes() { + foreach ( $this->controllers as $Controller ) { + /** + * Get an instance of the WP_REST_Controller. + * + * @var $instance \WP_REST_Controller + */ + $instance = new $Controller( $this->container ); + $instance->register_routes(); + } + } + + /** + * Add values to the runtime object. + * + * @param array $sdk The runtime object. + * + * @return array + */ + public function add_to_runtime( $sdk ) { + return array_merge( $sdk, array( 'cacheExclusion' => get_option( 'cache_exclusion', $this->defaultCacheExclusions() ) ) ); + } + + /** + * Return defaul exclusions. + * + * @return array + */ + public function defaultCacheExclusions() { + return join( ',', [ 'cart', 'checkout', 'wp-admin', rest_get_url_prefix() ] ); } /** diff --git a/includes/RestApi/CacheSettings.php b/includes/RestApi/CacheExclusionController.php similarity index 85% rename from includes/RestApi/CacheSettings.php rename to includes/RestApi/CacheExclusionController.php index 894de2a..a128bca 100644 --- a/includes/RestApi/CacheSettings.php +++ b/includes/RestApi/CacheExclusionController.php @@ -6,9 +6,9 @@ use NewfoldLabs\WP\ModuleLoader\Container; /** - * Class CacheSettings + * Class CacheExclusionController */ -class CacheSettings { +class CacheExclusionController { /** @@ -23,7 +23,7 @@ class CacheSettings { * * @var string */ - protected $rest_base = '/cachesettings'; + protected $rest_base = '/cacheexclusion'; /** * Container loaded from the brand plugin. @@ -79,7 +79,7 @@ public function register_routes() { public function get_settings() { return new \WP_REST_Response( array( - 'settings' => get_option( 'cache_exlusion', '' ), + 'settings' => get_option( 'cache_exclusion', '' ), ), 200 ); @@ -92,8 +92,8 @@ public function get_settings() { * @return \WP_REST_Response */ public function update_settings( \WP_REST_Request $request ) { - $cache_exlusion = $request->get_param( 'cache_exlusion' ); - if ( update_option( 'cache_exlusion', $cache_exlusion ) ) { + $cache_exclusion = $request->get_param( 'cache_exclusion' ); + if ( update_option( 'cache_exclusion', $cache_exclusion ) ) { return new \WP_REST_Response( array( 'result' => true, @@ -104,7 +104,7 @@ public function update_settings( \WP_REST_Request $request ) { return new \WP_REST_Response( array( - 'result' => false, + 'result' => false, ), 400 ); From 449116b1f1d963d43c416567b6546dd7e5d5df7d Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Thu, 7 Nov 2024 11:50:44 +0000 Subject: [PATCH 05/42] fixed string --- includes/RestApi/CacheExclusionController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/RestApi/CacheExclusionController.php b/includes/RestApi/CacheExclusionController.php index a128bca..6527c45 100644 --- a/includes/RestApi/CacheExclusionController.php +++ b/includes/RestApi/CacheExclusionController.php @@ -79,7 +79,7 @@ public function register_routes() { public function get_settings() { return new \WP_REST_Response( array( - 'settings' => get_option( 'cache_exclusion', '' ), + 'cacheExclusion' => get_option( 'cache_exclusion', '' ), ), 200 ); @@ -92,7 +92,7 @@ public function get_settings() { * @return \WP_REST_Response */ public function update_settings( \WP_REST_Request $request ) { - $cache_exclusion = $request->get_param( 'cache_exclusion' ); + $cache_exclusion = $request->get_param( 'cacheExclusion' ); if ( update_option( 'cache_exclusion', $cache_exclusion ) ) { return new \WP_REST_Response( array( From 9a7cd89fa06b153de1e3d8dfae8a6fb95b7d3013 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Thu, 7 Nov 2024 11:55:59 +0000 Subject: [PATCH 06/42] moved getDefaultCacheExclusions function to functions file --- includes/CacheManager.php | 13 +++---------- includes/RestApi/CacheExclusionController.php | 4 +++- includes/functions.php | 9 +++++++++ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 3503f55..8ed4ac8 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -7,6 +7,8 @@ use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\Collection\Collection; +use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions; + class CacheManager { /** @@ -60,16 +62,7 @@ public function register_routes() { * @return array */ public function add_to_runtime( $sdk ) { - return array_merge( $sdk, array( 'cacheExclusion' => get_option( 'cache_exclusion', $this->defaultCacheExclusions() ) ) ); - } - - /** - * Return defaul exclusions. - * - * @return array - */ - public function defaultCacheExclusions() { - return join( ',', [ 'cart', 'checkout', 'wp-admin', rest_get_url_prefix() ] ); + return array_merge( $sdk, array( 'cacheExclusion' => get_option( 'cache_exclusion', getDefaultCacheExclusions() ) ) ); } /** diff --git a/includes/RestApi/CacheExclusionController.php b/includes/RestApi/CacheExclusionController.php index 6527c45..f352afa 100644 --- a/includes/RestApi/CacheExclusionController.php +++ b/includes/RestApi/CacheExclusionController.php @@ -5,6 +5,8 @@ use NewfoldLabs\WP\Module\ECommerce\Permissions; use NewfoldLabs\WP\ModuleLoader\Container; +use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions; + /** * Class CacheExclusionController */ @@ -79,7 +81,7 @@ public function register_routes() { public function get_settings() { return new \WP_REST_Response( array( - 'cacheExclusion' => get_option( 'cache_exclusion', '' ), + 'cacheExclusion' => get_option( 'cache_exclusion', getDefaultCacheExclusions() ), ), 200 ); diff --git a/includes/functions.php b/includes/functions.php index 4133e84..49a8310 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2,6 +2,15 @@ namespace NewfoldLabs\WP\Module\Performance; +/** + * Return defaul exclusions. + * + * @return array + */ +function getDefaultCacheExclusions() { + return join( ',', [ 'cart', 'checkout', 'wp-admin', rest_get_url_prefix() ] ); +} + /** * Get the current cache level. * From ddb7674910eda6c0f5f57fbe85152544492598be Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Thu, 7 Nov 2024 14:41:50 +0000 Subject: [PATCH 07/42] updated js component --- components/cacheExclusion/index.js | 70 +++++++++++++++++------------- includes/CacheManager.php | 1 - 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/components/cacheExclusion/index.js b/components/cacheExclusion/index.js index 71eaf05..ee50b1b 100644 --- a/components/cacheExclusion/index.js +++ b/components/cacheExclusion/index.js @@ -1,11 +1,11 @@ import { Button, Container, TextareaField } from "@newfold/ui-component-library"; const CacheExclusion = ({ methods, constants }) => { - - const [ currentValue, setCurrentValue ] = methods.useState(constants.store.cacheExclusion); const [ isEdited, setIsEdited ] = methods.useState(false); - const [ cacheExclusion, setCacheExclusion ] = methods.useState(constants.store.cacheExclusion); - + const [ isError, setIsError ] = methods.useState(false); + const [ isSaved, setIsSaved ] = methods.useState(false); + const [ cacheExclusion, setCacheExclusion ] = methods.useState(methods.NewfoldRuntime.sdk.cacheExclusion); + const apiUrl = methods.NewfoldRuntime.createApiUrl("/newfold-ecommerce/v1/cacheexclusion/update"); const handleCacheExclusionChange = (e) => { if( e.target.value !== cacheExclusion ) { @@ -13,28 +13,36 @@ const CacheExclusion = ({ methods, constants }) => { }else{ setIsEdited(false); } - setCurrentValue( e.target.value ); + setCacheExclusion( e.target.value ); } - const handlingSaveButton = () => { - methods.newfoldSettingsApiFetch( - { cacheExclusion: currentValue }, - methods.setError, (response) => { - setCacheExclusion( currentValue ) - methods.makeNotice( - "disable-old-posts-comments-notice", - constants.text.cacheExclusionSaved, - null, - "success", - 5000 - ); - setIsEdited(false); - } - ); - + methods.apiFetch({ + url: apiUrl, + method: "POST", + data: {cacheExclusion: cacheExclusion} + }).then((result)=>{ + setIsSaved(true); + }).catch((error) => { + setIsError(error.message); + }); }; + methods.useUpdateEffect(() => { + methods.setStore({ + ...constants.store, + CacheExclusion: cacheExclusion, + }); + + methods.makeNotice( + "cache-exlusion-notice", + constants.text.cacheExclusionTitle, + !isError ? constants.text.cacheExclusionSaved : isError, + !isError ? "success" : "error", + 5000 + ); + }, [ isSaved, isError]); + return ( { id="cache-exclusion" name="cache-xxclusion" onChange={ handleCacheExclusionChange } - value={currentValue} + value={cacheExclusion} /> - + {isEdited && + + } diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 8ed4ac8..a32b2af 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -3,7 +3,6 @@ namespace NewfoldLabs\WP\Module\Performance; use NewfoldLabs\WP\Module\Performance\CacheTypes\CacheBase; -use NewfoldLabs\WP\Module\Performance\RestApi\CacheExclusionController; use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\Collection\Collection; From 6b56ef18703ccc0198d13e4c7cda661fe581039c Mon Sep 17 00:00:00 2001 From: Alessio Torrisi Date: Fri, 8 Nov 2024 15:11:44 +0100 Subject: [PATCH 08/42] Tweak: show "save" button only if the current value has been edited --- components/cacheExclusion/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/cacheExclusion/index.js b/components/cacheExclusion/index.js index ee50b1b..31bded6 100644 --- a/components/cacheExclusion/index.js +++ b/components/cacheExclusion/index.js @@ -4,6 +4,7 @@ const CacheExclusion = ({ methods, constants }) => { const [ isEdited, setIsEdited ] = methods.useState(false); const [ isError, setIsError ] = methods.useState(false); const [ isSaved, setIsSaved ] = methods.useState(false); + const [ currentValue, setCurrentValue ] = methods.useState(methods.NewfoldRuntime.sdk.cacheExclusion); const [ cacheExclusion, setCacheExclusion ] = methods.useState(methods.NewfoldRuntime.sdk.cacheExclusion); const apiUrl = methods.NewfoldRuntime.createApiUrl("/newfold-ecommerce/v1/cacheexclusion/update"); @@ -13,16 +14,17 @@ const CacheExclusion = ({ methods, constants }) => { }else{ setIsEdited(false); } - setCacheExclusion( e.target.value ); + setCurrentValue( e.target.value ); } const handlingSaveButton = () => { methods.apiFetch({ url: apiUrl, method: "POST", - data: {cacheExclusion: cacheExclusion} + data: {cacheExclusion: currentValue} }).then((result)=>{ setIsSaved(true); + setCacheExclusion(currentValue); }).catch((error) => { setIsError(error.message); }); @@ -52,7 +54,7 @@ const CacheExclusion = ({ methods, constants }) => { id="cache-exclusion" name="cache-xxclusion" onChange={ handleCacheExclusionChange } - value={cacheExclusion} + value={currentValue} /> {isEdited && + + ); +}; - return ( - - - - - ); -;} - -export default ClearCache; \ No newline at end of file +export default ClearCache; diff --git a/includes/burstSafetyModeFunctions.php b/includes/burstSafetyModeFunctions.php index 8de058d..6cc03cc 100644 --- a/includes/burstSafetyModeFunctions.php +++ b/includes/burstSafetyModeFunctions.php @@ -1,4 +1,4 @@ -addHeader( 'X-Newfold-Cache-Level', 3 ); } } elseif ( $newfold_burst_safety_mode ) { $cache_level = get_option( 'newfold_burst_safety_mode_site_cache_level' ); $browser = new Browser(); $browser::maybeAddRules( $cache_level ); - if( function_exists( 'getSkip404Option' ) && ! getSkip404Option() ) { - $skip404 = new Skip404(); - $skip404::maybeAddRules( false ); - } - $responseHeaderManager = new ResponseHeaderManager(); - $responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', $cache_level ); + if ( function_exists( 'getSkip404Option' ) && ! getSkip404Option() ) { + $skip404 = new Skip404(); + $skip404::maybeAddRules( false ); + } + $responseHeaderManager = new ResponseHeaderManager(); + $responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', $cache_level ); delete_option( 'newfold_burst_safety_mode' ); delete_option( 'newfold_burst_safety_mode_site_cache_level' ); } From 8e3902db86ca30330ca1931e377088da3cf929d5 Mon Sep 17 00:00:00 2001 From: Alessio Torrisi Date: Tue, 7 Jan 2025 09:05:25 +0100 Subject: [PATCH 29/42] Fix: phpcs issue --- includes/Performance.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Performance.php b/includes/Performance.php index 2d168bc..d2debd7 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -93,7 +93,7 @@ public function __construct( Container $container ) { $container->set( 'hasMustUsePlugin', file_exists( WPMU_PLUGIN_DIR . '/endurance-page-cache.php' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); if ( Permissions::is_authorized_admin() || Permissions::rest_is_authorized_admin() ) { new RestAPI(); @@ -334,7 +334,7 @@ public function add_to_runtime( $sdk ) { 'jetpack_boost_minify_css' => get_option( 'jetpack_boost_status_minify-css', array() ), 'jetpack_boost_minify_css_excludes' => implode( ',', get_option( 'jetpack_boost_ds_minify_css_excludes', array( 'admin-bar', 'dashicons', 'elementor-app' ) ) ), 'install_token' => PluginInstaller::rest_get_plugin_install_hash(), - 'skip404' => (bool) get_option( 'newfold_skip_404_handling', false ), + 'skip404' => (bool) get_option( 'newfold_skip_404_handling', false ), ); return array_merge( $sdk, array( 'performance' => $values ) ); From 4348cf66759bc39115837cc6e95f79ac0c41fb54 Mon Sep 17 00:00:00 2001 From: Alessio Torrisi Date: Tue, 7 Jan 2025 09:31:50 +0100 Subject: [PATCH 30/42] Fix: phpcs issue on undefined WordPress function --- includes/BurstSafetyMode/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/BurstSafetyMode/init.php b/includes/BurstSafetyMode/init.php index 7118599..e78bded 100644 --- a/includes/BurstSafetyMode/init.php +++ b/includes/BurstSafetyMode/init.php @@ -7,8 +7,8 @@ use NewfoldLabs\WP\Module\Performance\ResponseHeaderManager; -$newfold_burst_safety_mode = (bool) get_option( 'newfold_burst_safety_mode', false ); -$newfold_cache_level = (int) get_option( 'newfold_cache_level', 0 ); +$newfold_burst_safety_mode = function_exists( 'get_option' ) ? (bool) get_option( 'newfold_burst_safety_mode', false ) : false; +$newfold_cache_level = function_exists( 'newfold_cache_level' ) ? (int) get_option( 'newfold_cache_level', 0 ) : 0; // Check if Performance feature is enabled and it's necessary reset the cache options if ( class_exists( 'NewfoldLabs\WP\Module\Performance\PerformanceFeatureHooks' ) ) { From 64a02550a581112eedaef75414b8f51740153f58 Mon Sep 17 00:00:00 2001 From: Alessio Torrisi Date: Tue, 7 Jan 2025 09:34:07 +0100 Subject: [PATCH 31/42] Fix: phpcs issue yoda condition --- includes/burstSafetyModeFunctions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/burstSafetyModeFunctions.php b/includes/burstSafetyModeFunctions.php index 6cc03cc..53cb68c 100644 --- a/includes/burstSafetyModeFunctions.php +++ b/includes/burstSafetyModeFunctions.php @@ -10,7 +10,7 @@ $site_skip404 = (bool) get_option( 'newfold_skip_404_handling', true ); if ( defined( 'BURST_SAFETY_MODE' ) && BURST_SAFETY_MODE ) { - if ( $newfold_burst_safety_mode === false ) { + if ( false === $newfold_burst_safety_mode ) { $current_level = get_option( Performance::OPTION_CACHE_LEVEL ); update_option( 'newfold_burst_safety_mode', true ); update_option( 'newfold_burst_safety_mode_site_cache_level', $current_level ); From 0375f6350d21c631a3c731aec4931d21ff3db63a Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Tue, 7 Jan 2025 11:19:26 +0000 Subject: [PATCH 32/42] fixed 500 error --- includes/Performance.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Performance.php b/includes/Performance.php index 4aa21da..db2680e 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -123,7 +123,6 @@ function () { */ public function hooks() { - add_action( 'admin_init', array( $this, 'registerSettings' ), 11 ); add_action( 'admin_init', array( $this, 'remove_epc_settings' ), 99 ); new OptionListener( self::OPTION_CACHE_LEVEL, array( $this, 'onCacheLevelChange' ) ); @@ -156,6 +155,8 @@ function () { add_filter( 'action_scheduler_cleanup_batch_size', array( $this, 'nfd_as_cleanup_batch_size' ) ); } + + /** * Remove EPC Settings if needed * From 3056fb6e528210f0529d9c0abddbef6c039b783c Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Tue, 7 Jan 2025 11:30:53 +0000 Subject: [PATCH 33/42] fix input name --- components/cacheExclusion/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/cacheExclusion/index.js b/components/cacheExclusion/index.js index 49fdacc..85b1929 100644 --- a/components/cacheExclusion/index.js +++ b/components/cacheExclusion/index.js @@ -53,7 +53,7 @@ const CacheExclusion = ({ methods, constants }) => { > Date: Tue, 7 Jan 2025 14:13:01 +0000 Subject: [PATCH 34/42] js lint --- components/cacheExclusion/index.js | 141 ++++++++++++++++------------- 1 file changed, 76 insertions(+), 65 deletions(-) diff --git a/components/cacheExclusion/index.js b/components/cacheExclusion/index.js index 85b1929..36abf48 100644 --- a/components/cacheExclusion/index.js +++ b/components/cacheExclusion/index.js @@ -1,78 +1,89 @@ -import { Button, Container, TextareaField } from "@newfold/ui-component-library"; +import { + Button, + Container, + TextareaField, +} from '@newfold/ui-component-library'; -const CacheExclusion = ({ methods, constants }) => { - const [ isEdited, setIsEdited ] = methods.useState(false); - const [ isError, setIsError ] = methods.useState(false); - const [ isSaved, setIsSaved ] = methods.useState(false); - const [ currentValue, setCurrentValue ] = methods.useState(methods.NewfoldRuntime.sdk.cacheExclusion); - const [ cacheExclusion, setCacheExclusion ] = methods.useState(methods.NewfoldRuntime.sdk.cacheExclusion); - const apiUrl = methods.NewfoldRuntime.createApiUrl("/newfold-ecommerce/v1/cacheexclusion/update"); +const CacheExclusion = ( { methods, constants } ) => { + const [ isEdited, setIsEdited ] = methods.useState( false ); + const [ isError, setIsError ] = methods.useState( false ); + const [ isSaved, setIsSaved ] = methods.useState( false ); + const [ currentValue, setCurrentValue ] = methods.useState( + methods.NewfoldRuntime.sdk.cacheExclusion + ); + const [ cacheExclusion, setCacheExclusion ] = methods.useState( + methods.NewfoldRuntime.sdk.cacheExclusion + ); + const apiUrl = methods.NewfoldRuntime.createApiUrl( + '/newfold-ecommerce/v1/cacheexclusion/update' + ); - const handleCacheExclusionChange = (e) => { - if( e.target.value !== currentValue ) { - setIsEdited(true); - }else{ - setIsEdited(false); - } - setCurrentValue( e.target.value ); - } + const handleCacheExclusionChange = ( e ) => { + if ( e.target.value !== currentValue ) { + setIsEdited( true ); + } else { + setIsEdited( false ); + } + setCurrentValue( e.target.value ); + }; - const handlingSaveButton = () => { - methods.apiFetch({ - url: apiUrl, - method: "POST", - data: {cacheExclusion: currentValue} - }).then((result)=>{ - setIsSaved(true); - setCacheExclusion(currentValue); - setIsEdited(false) - }).catch((error) => { - setIsError(error.message); - }); - }; + const handlingSaveButton = () => { + methods + .apiFetch( { + url: apiUrl, + method: 'POST', + data: { cacheExclusion: currentValue }, + } ) + .then( () => { + setIsSaved( true ); + setCacheExclusion( currentValue ); + setIsEdited( false ); + } ) + .catch( ( error ) => { + setIsError( error.message ); + } ); + }; - methods.useUpdateEffect(() => { - methods.setStore({ - ...constants.store, - CacheExclusion: cacheExclusion, - }); + methods.useUpdateEffect( () => { + methods.setStore( { + ...constants.store, + CacheExclusion: cacheExclusion, + } ); - methods.makeNotice( - "cache-exlusion-notice", - constants.text.cacheExclusionTitle, - !isError ? constants.text.cacheExclusionSaved : isError, - !isError ? "success" : "error", - 5000 - ); - }, [ isSaved, isError]); + methods.makeNotice( + 'cache-exlusion-notice', + constants.text.cacheExclusionTitle, + ! isError ? constants.text.cacheExclusionSaved : isError, + ! isError ? 'success' : 'error', + 5000 + ); + }, [ isSaved, isError ] ); - return ( - - + - {isEdited && + label={ constants.text.cacheExclusionTitle } + /> + { isEdited && ( - } - - - - ); -;} + ) } + + ); +}; -export default CacheExclusion; \ No newline at end of file +export default CacheExclusion; From ccfdb13f7a1a4bb84c37b25d96a3819a7bbc2ef8 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Tue, 7 Jan 2025 14:23:56 +0000 Subject: [PATCH 35/42] lint performance folder js files --- components/performance/defaultText.js | 11 +++++++---- components/performance/index.js | 12 ++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/components/performance/defaultText.js b/components/performance/defaultText.js index c7ba654..365cc40 100644 --- a/components/performance/defaultText.js +++ b/components/performance/defaultText.js @@ -66,10 +66,13 @@ const defaultText = { ), clearCacheNoticeTitle: __( 'Cache cleared', 'wp-module-performance' ), clearCacheTitle: __( 'Clear Cache', 'wp-module-performance' ), - cacheExclusionTitle: __( 'Exclude from cache', 'wp-module-performance' ), - cacheExclusionDescription: __( 'This setting controls what pages pass a “no-cache” header so that page caching and browser caching is not used.', 'wp-module-performance' ), - cacheExclusionSaved: __( 'Cache Exclusion saved', 'wp-module-performance' ), - cacheExclusionSaveButton: __( 'Save', 'wp-module-performance' ), + cacheExclusionTitle: __( 'Exclude from cache', 'wp-module-performance' ), + cacheExclusionDescription: __( + 'This setting controls what pages pass a “no-cache” header so that page caching and browser caching is not used.', + 'wp-module-performance' + ), + cacheExclusionSaved: __( 'Cache Exclusion saved', 'wp-module-performance' ), + cacheExclusionSaveButton: __( 'Save', 'wp-module-performance' ), // Image Optimization imageOptimizationSettingsTitle: __( 'Image Optimization', diff --git a/components/performance/index.js b/components/performance/index.js index 79a833a..bb74e93 100644 --- a/components/performance/index.js +++ b/components/performance/index.js @@ -57,12 +57,12 @@ const Performance = ( { methods, constants, Components, ...props } ) => { Components={ Components } /> - - - + + + Date: Tue, 7 Jan 2025 15:36:40 +0100 Subject: [PATCH 36/42] Tweak: removed unused packages --- package-lock.json | 2 +- package.json | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 13360f7..57c29d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "name": "@newfold-labs/wp-module-performance", "license": "GPL-2.0-or-later", "dependencies": { - "@newfold-labs/wp-module-runtime": "^1.0.0", + "@newfold-labs/wp-module-runtime": "^1.0.12", "@newfold/ui-component-library": "^1.1.0", "html-react-parser": "^5.1.18" }, diff --git a/package.json b/package.json index f6dac48..e900646 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,8 @@ "William Earnhardt (https://wearnhardt.com)" ], "dependencies": { - "@heroicons/react": "^2.0.18", "@newfold/ui-component-library": "^1.1.0", "@newfold-labs/wp-module-runtime": "^1.0.12", - "@tailwindcss/forms": "^0.5.8", "html-react-parser": "^5.1.18" }, "devDependencies": { From 4a188658e6832a47fe5e94667a1b4936a6f334a8 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 8 Jan 2025 08:20:50 +0000 Subject: [PATCH 37/42] refactoring of codes --- components/cacheExclusion/index.js | 2 +- includes/CacheManager.php | 43 ------------------- includes/CacheTypes/Browser.php | 6 +-- includes/CacheTypes/File.php | 4 +- includes/Performance.php | 4 +- includes/RestApi/CacheExclusionController.php | 36 +++------------- includes/RestApi/RestApi.php | 1 + 7 files changed, 14 insertions(+), 82 deletions(-) diff --git a/components/cacheExclusion/index.js b/components/cacheExclusion/index.js index 36abf48..74697b0 100644 --- a/components/cacheExclusion/index.js +++ b/components/cacheExclusion/index.js @@ -15,7 +15,7 @@ const CacheExclusion = ( { methods, constants } ) => { methods.NewfoldRuntime.sdk.cacheExclusion ); const apiUrl = methods.NewfoldRuntime.createApiUrl( - '/newfold-ecommerce/v1/cacheexclusion/update' + '/newfold-performance/v1/cache-exclusion/update' ); const handleCacheExclusionChange = ( e ) => { diff --git a/includes/CacheManager.php b/includes/CacheManager.php index 1acc296..cb74238 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -5,13 +5,8 @@ use NewfoldLabs\WP\Module\Performance\CacheTypes\CacheBase; use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\Collection\Collection; -use NewfoldLabs\WP\Module\Performance\RestApi\CacheExclusionController; - -use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions; class CacheManager { - - /** * Dependency injection container. * @@ -19,15 +14,6 @@ class CacheManager { */ protected $container; - /** - * Array map of API controllers. - * - * @var array - */ - protected $controllers = array( - 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\CacheExclusionController', - ); - /** * Constructor. * @@ -35,35 +21,6 @@ class CacheManager { */ public function __construct( Container $container ) { $this->container = $container; - - add_action( 'rest_api_init', array( $this, 'register_routes' ) ); - add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) ); - } - - /** - * Register API routes. - */ - public function register_routes() { - foreach ( $this->controllers as $Controller ) { - /** - * Get an instance of the WP_REST_Controller. - * - * @var $instance \WP_REST_Controller - */ - $instance = new $Controller( $this->container ); - $instance->register_routes(); - } - } - - /** - * Add values to the runtime object. - * - * @param array $sdk The runtime object. - * - * @return array - */ - public function add_to_runtime( $sdk ) { - return array_merge( $sdk, array( 'cacheExclusion' => get_option( CacheExclusionController::OPTION_CACHE_EXCLUSION, getDefaultCacheExclusions() ) ) ); } /** diff --git a/includes/CacheTypes/Browser.php b/includes/CacheTypes/Browser.php index 26e2b64..bfd31e9 100644 --- a/includes/CacheTypes/Browser.php +++ b/includes/CacheTypes/Browser.php @@ -6,7 +6,7 @@ use NewfoldLabs\WP\Module\Performance\Performance; use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\WP_Htaccess_Manager\htaccess; -use NewfoldLabs\WP\Module\Performance\RestApi\CacheExclusionController; +use NewfoldLabs\WP\Module\Performance\CacheExclusion; use function NewfoldLabs\WP\Module\Performance\getCacheLevel; use function WP_Forge\WP_Htaccess_Manager\removeMarkers; @@ -40,7 +40,7 @@ public function __construct() { new OptionListener( Performance::OPTION_CACHE_LEVEL, array( __CLASS__, 'maybeAddRules' ) ); - new OptionListener( CacheExclusionController::OPTION_CACHE_EXCLUSION, array( __CLASS__, 'exclusionChange' ) ); + new OptionListener( CacheExclusion::OPTION_CACHE_EXCLUSION, array( __CLASS__, 'exclusionChange' ) ); add_filter( 'newfold_update_htaccess', array( $this, 'onRewrite' ) ); } @@ -100,7 +100,7 @@ public static function addRules( $cacheLevel ) { } $rules[] = ''; - $cache_exclusion_parameters = array_map( 'trim', explode( ',', get_option( CacheExclusionController::OPTION_CACHE_EXCLUSION ) ) ); + $cache_exclusion_parameters = array_map( 'trim', explode( ',', get_option( CacheExclusion::OPTION_CACHE_EXCLUSION ) ) ); // Add the cache exclusion rules. $rules[] = ''; diff --git a/includes/CacheTypes/File.php b/includes/CacheTypes/File.php index a7b6cb0..d1048c5 100644 --- a/includes/CacheTypes/File.php +++ b/includes/CacheTypes/File.php @@ -6,7 +6,7 @@ use NewfoldLabs\WP\Module\Performance\OptionListener; use NewfoldLabs\WP\Module\Performance\Performance; use NewfoldLabs\WP\ModuleLoader\Container; -use NewfoldLabs\WP\Module\Performance\RestApi\CacheExclusionController; +use NewfoldLabs\WP\Module\Performance\CacheExclusion; use WP_Forge\WP_Htaccess_Manager\htaccess; use wpscholar\Url; @@ -257,7 +257,7 @@ public function shouldCache() { */ protected function exclusions() { $default = array( 'cart', 'checkout', 'wp-admin', '@', '%', ':', ';', '&', '=', '.', rest_get_url_prefix() ); - $cache_exclusion_option = array_map( 'trim', explode( ',', get_option( CacheExclusionController::OPTION_CACHE_EXCLUSION ) ) ); + $cache_exclusion_option = array_map( 'trim', explode( ',', get_option( CacheExclusion::OPTION_CACHE_EXCLUSION ) ) ); return array_merge( $default, $cache_exclusion_option ); } diff --git a/includes/Performance.php b/includes/Performance.php index db2680e..43c4bba 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -9,6 +9,7 @@ use NewfoldLabs\WP\Module\Performance\RestApi\RestApi; use Automattic\Jetpack\Current_Plan; +use Automattic\Jetpack\Status\Cache; use NewfoldLabs\WP\Module\Performance\Data\Constants; /** @@ -83,6 +84,7 @@ public function __construct( Container $container ) { add_action( 'admin_menu', array( $this, 'add_sub_menu_page' ) ); new LinkPrefetch( $container ); + new CacheExclusion( $container ); $container->set( 'cachePurger', $cachePurger ); @@ -155,8 +157,6 @@ function () { add_filter( 'action_scheduler_cleanup_batch_size', array( $this, 'nfd_as_cleanup_batch_size' ) ); } - - /** * Remove EPC Settings if needed * diff --git a/includes/RestApi/CacheExclusionController.php b/includes/RestApi/CacheExclusionController.php index 267fdbc..b84da03 100644 --- a/includes/RestApi/CacheExclusionController.php +++ b/includes/RestApi/CacheExclusionController.php @@ -3,7 +3,7 @@ namespace NewfoldLabs\WP\Module\Performance\RestApi; use NewfoldLabs\WP\Module\ECommerce\Permissions; -use NewfoldLabs\WP\ModuleLoader\Container; +use NewfoldLabs\WP\Module\Performance\CacheExclusion; use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions; @@ -11,45 +11,19 @@ * Class CacheExclusionController */ class CacheExclusionController { - - - /** * REST namespace * * @var string */ - protected $namespace = 'newfold-ecommerce/v1'; + protected $namespace = 'newfold-performance/v1'; /** * REST base * * @var string */ - protected $rest_base = '/cacheexclusion'; - - /** - * Container loaded from the brand plugin. - * - * @var Container - */ - protected $container; - - /** - * Option used to store all pages should be excluded from cache. - * - * @var string - */ - const OPTION_CACHE_EXCLUSION = 'newfold_cache_exclusion'; - - /** - * Constructor - * - * @param Container $container the container. - */ - public function __construct( Container $container ) { - $this->container = $container; - } + protected $rest_base = '/cache-exclusion'; /** * Registers rest routes for PluginsController class. @@ -89,7 +63,7 @@ public function register_routes() { public function get_settings() { return new \WP_REST_Response( array( - 'cacheExclusion' => get_option( self::OPTION_CACHE_EXCLUSION, getDefaultCacheExclusions() ), + 'cacheExclusion' => get_option( CacheExclusion::OPTION_CACHE_EXCLUSION, getDefaultCacheExclusions() ), ), 200 ); @@ -103,7 +77,7 @@ public function get_settings() { */ public function update_settings( \WP_REST_Request $request ) { $cache_exclusion = $request->get_param( 'cacheExclusion' ); - if ( update_option( self::OPTION_CACHE_EXCLUSION, $cache_exclusion ) ) { + if ( update_option( CacheExclusion::OPTION_CACHE_EXCLUSION, $cache_exclusion ) ) { return new \WP_REST_Response( array( 'result' => true, diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index 5351667..6380712 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -15,6 +15,7 @@ final class RestApi { protected $controllers = array( 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\LinkPrefetchController', 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\JetpackController', + 'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\CacheExclusionController', ); /** From 0a1d3826ba097bdec5900186b938da269676e008 Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 8 Jan 2025 08:28:22 +0000 Subject: [PATCH 38/42] adding CacheExclusion Class --- includes/CacheExclusion.php | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 includes/CacheExclusion.php diff --git a/includes/CacheExclusion.php b/includes/CacheExclusion.php new file mode 100644 index 0000000..3dde4ea --- /dev/null +++ b/includes/CacheExclusion.php @@ -0,0 +1,48 @@ +container = $container; + + add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) ); + } + /** + * Add values to the runtime object. + * + * @param array $sdk The runtime object. + * + * @return array + */ + public function add_to_runtime( $sdk ) { + return array_merge( $sdk, array( 'cacheExclusion' => get_option( self::OPTION_CACHE_EXCLUSION, getDefaultCacheExclusions() ) ) ); + } +} \ No newline at end of file From f5ae0a2b219e4a473205f4e18b731653a3cfe16b Mon Sep 17 00:00:00 2001 From: Armando Liccardo Date: Wed, 8 Jan 2025 08:53:49 +0000 Subject: [PATCH 39/42] change function name to snake case and minor changes for phpcs --- includes/CacheExclusion.php | 8 +++----- includes/CacheManager.php | 8 ++++++-- includes/CacheTypes/File.php | 2 +- includes/Performance.php | 5 ++--- includes/RestApi/CacheExclusionController.php | 4 ++-- includes/functions.php | 4 ++-- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/includes/CacheExclusion.php b/includes/CacheExclusion.php index 3dde4ea..39d8977 100644 --- a/includes/CacheExclusion.php +++ b/includes/CacheExclusion.php @@ -3,9 +3,7 @@ use NewfoldLabs\WP\ModuleLoader\Container; -use NewfoldLabs\WP\Module\Performance\RestApi\CacheExclusionController; - -use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions; +use function NewfoldLabs\WP\Module\Performance\get_default_cache_exclusions; /** * Cache Exclusion Class @@ -43,6 +41,6 @@ public function __construct( Container $container ) { * @return array */ public function add_to_runtime( $sdk ) { - return array_merge( $sdk, array( 'cacheExclusion' => get_option( self::OPTION_CACHE_EXCLUSION, getDefaultCacheExclusions() ) ) ); + return array_merge( $sdk, array( 'cacheExclusion' => get_option( self::OPTION_CACHE_EXCLUSION, get_default_cache_exclusions() ) ) ); } -} \ No newline at end of file +} diff --git a/includes/CacheManager.php b/includes/CacheManager.php index cb74238..28cf7cf 100644 --- a/includes/CacheManager.php +++ b/includes/CacheManager.php @@ -5,7 +5,9 @@ use NewfoldLabs\WP\Module\Performance\CacheTypes\CacheBase; use NewfoldLabs\WP\ModuleLoader\Container; use WP_Forge\Collection\Collection; - +/** + * Cache Manager Class + */ class CacheManager { /** * Dependency injection container. @@ -17,7 +19,7 @@ class CacheManager { /** * Constructor. * - * @param string[] $supportedCacheTypes Cache types supported by the plugin + * @param Container $container the container */ public function __construct( Container $container ) { $this->container = $container; @@ -79,6 +81,8 @@ public function getInstances() { $map = $collection->only( $this->enabledCacheTypes() ); foreach ( $map as $type => $class ) { /** + * CacheBase instance. + * * @var CacheBase $class */ if ( $class::shouldEnable( $this->container ) ) { diff --git a/includes/CacheTypes/File.php b/includes/CacheTypes/File.php index d1048c5..60d9ef9 100644 --- a/includes/CacheTypes/File.php +++ b/includes/CacheTypes/File.php @@ -50,7 +50,7 @@ public static function shouldEnable( Container $container ) { public function __construct() { new OptionListener( Performance::OPTION_CACHE_LEVEL, array( __CLASS__, 'maybeAddRules' ) ); - new OptionListener( CacheExclusionController::OPTION_CACHE_EXCLUSION, array( __CLASS__, 'exclusionChange' ) ); + new OptionListener( CacheExclusion::OPTION_CACHE_EXCLUSION, array( __CLASS__, 'exclusionChange' ) ); add_action( 'init', array( $this, 'maybeGeneratePageCache' ) ); add_action( 'newfold_update_htaccess', array( $this, 'onRewrite' ) ); diff --git a/includes/Performance.php b/includes/Performance.php index 1ed2ffc..d395ae5 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -308,7 +308,7 @@ public function add_sub_menu_page() { ); } - /* + /** * Enqueue scripts and styles in admin */ public function enqueue_scripts() { @@ -317,8 +317,7 @@ public function enqueue_scripts() { wp_enqueue_style( 'wp-module-performance-styles' ); } - /* - + /** * Add to Newfold SDK runtime. * * @param array $sdk SDK data. diff --git a/includes/RestApi/CacheExclusionController.php b/includes/RestApi/CacheExclusionController.php index b84da03..ce056f4 100644 --- a/includes/RestApi/CacheExclusionController.php +++ b/includes/RestApi/CacheExclusionController.php @@ -5,7 +5,7 @@ use NewfoldLabs\WP\Module\ECommerce\Permissions; use NewfoldLabs\WP\Module\Performance\CacheExclusion; -use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions; +use function NewfoldLabs\WP\Module\Performance\get_default_cache_exclusions; /** * Class CacheExclusionController @@ -63,7 +63,7 @@ public function register_routes() { public function get_settings() { return new \WP_REST_Response( array( - 'cacheExclusion' => get_option( CacheExclusion::OPTION_CACHE_EXCLUSION, getDefaultCacheExclusions() ), + 'cacheExclusion' => get_option( CacheExclusion::OPTION_CACHE_EXCLUSION, get_default_cache_exclusions() ), ), 200 ); diff --git a/includes/functions.php b/includes/functions.php index 770a54a..7b76a38 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -7,8 +7,8 @@ * * @return array */ -function getDefaultCacheExclusions() { - return join( ',', [ 'cart', 'checkout', 'wp-admin', rest_get_url_prefix() ] ); +function get_default_cache_exclusions() { + return join( ',', array( 'cart', 'checkout', 'wp-admin', rest_get_url_prefix() ) ); } /** From ece783421d7ae8d7a18180987ad6e6900d5db659 Mon Sep 17 00:00:00 2001 From: Alessio Torrisi Date: Wed, 8 Jan 2025 12:27:48 +0100 Subject: [PATCH 40/42] Fix: wrong name used for Browser.php file --- includes/BurstSafetyMode/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/BurstSafetyMode/init.php b/includes/BurstSafetyMode/init.php index e78bded..41fbe35 100644 --- a/includes/BurstSafetyMode/init.php +++ b/includes/BurstSafetyMode/init.php @@ -34,7 +34,7 @@ 'htaccess' => BLUEHOST_PLUGIN_DIR . 'vendor/wp-forge/wp-htaccess-manager/includes/htaccess.php', 'htaccess_functions' => BLUEHOST_PLUGIN_DIR . 'vendor/wp-forge/wp-htaccess-manager/includes/functions.php', 'skip404' => BLUEHOST_PLUGIN_DIR . 'vendor/newfold-labs/wp-module-performance/includes/BurstSafetyMode/Skip404.php', - 'browser' => BLUEHOST_PLUGIN_DIR . 'vendor/newfold-labs/wp-module-performance/includes/BurstSafetyMode/browser.php', + 'browser' => BLUEHOST_PLUGIN_DIR . 'vendor/newfold-labs/wp-module-performance/includes/BurstSafetyMode/Browser.php', 'response_header_manager' => BLUEHOST_PLUGIN_DIR . 'vendor/newfold-labs/wp-module-performance/includes/BurstSafetyMode/ResponseHeaderManager.php', ); From 037d17c4766058286b291f83971dd32e0d9b0030 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Wed, 8 Jan 2025 20:24:39 +0530 Subject: [PATCH 41/42] Some formatting related fixes --- includes/BurstSafetyMode/Browser.php | 1 + includes/BurstSafetyMode/Skip404.php | 9 +++++---- includes/BurstSafetyMode/init.php | 7 ++++--- includes/burstSafetyModeFunctions.php | 1 + 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/includes/BurstSafetyMode/Browser.php b/includes/BurstSafetyMode/Browser.php index 9bbba02..6f97d3b 100644 --- a/includes/BurstSafetyMode/Browser.php +++ b/includes/BurstSafetyMode/Browser.php @@ -1,5 +1,6 @@ addRules(); @@ -19,8 +20,8 @@ public function __construct() { /** - * Add our rules to the .htacces file. - */ + * Add our rules to the .htacces file. + */ public static function addRules() { $content = << diff --git a/includes/BurstSafetyMode/init.php b/includes/BurstSafetyMode/init.php index 41fbe35..df5572e 100644 --- a/includes/BurstSafetyMode/init.php +++ b/includes/BurstSafetyMode/init.php @@ -28,8 +28,7 @@ delete_option( 'newfold_burst_safety_mode' ); } -} else { - if ( ! $newfold_burst_safety_mode ) { +} elseif ( ! $newfold_burst_safety_mode ) { $files_to_include = array( 'htaccess' => BLUEHOST_PLUGIN_DIR . 'vendor/wp-forge/wp-htaccess-manager/includes/htaccess.php', 'htaccess_functions' => BLUEHOST_PLUGIN_DIR . 'vendor/wp-forge/wp-htaccess-manager/includes/functions.php', @@ -53,5 +52,7 @@ } update_option( 'newfold_burst_safety_mode', true ); - } } + + +vendor / bin / phpcbf --standard = phpcs . xml - s 'bootstrap.php' 'includes/BurstSafetyMode/Browser.php' 'includes/BurstSafetyMode/ResponseHeaderManager.php' 'includes/BurstSafetyMode/Skip404.php' 'includes/BurstSafetyMode/init.php' 'includes/CacheExclusion.php' 'includes/CacheManager.php' 'includes/CacheTypes/Browser.php' 'includes/CacheTypes/File.php' 'includes/Performance.php' 'includes/RestApi/CacheExclusionController.php' 'includes/RestApi/RestApi.php' 'includes/RestApi/SettingsController.php' 'includes/burstSafetyModeFunctions.php' 'includes/functions.php' diff --git a/includes/burstSafetyModeFunctions.php b/includes/burstSafetyModeFunctions.php index 53cb68c..62ef02c 100644 --- a/includes/burstSafetyModeFunctions.php +++ b/includes/burstSafetyModeFunctions.php @@ -1,5 +1,6 @@ Date: Wed, 8 Jan 2025 20:52:16 +0530 Subject: [PATCH 42/42] Fix error --- includes/BurstSafetyMode/init.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/includes/BurstSafetyMode/init.php b/includes/BurstSafetyMode/init.php index df5572e..2447e2e 100644 --- a/includes/BurstSafetyMode/init.php +++ b/includes/BurstSafetyMode/init.php @@ -23,8 +23,8 @@ $skip404::maybeAddRules( false ); } - $responseHeaderManager = new ResponseHeaderManager(); - $responseHeaderManager->addHeader( 'X-Newfold-Cache-Level', $newfold_cache_level ); + $response_header_manager = new ResponseHeaderManager(); + $response_header_manager->addHeader( 'X-Newfold-Cache-Level', $newfold_cache_level ); delete_option( 'newfold_burst_safety_mode' ); } @@ -37,9 +37,9 @@ 'response_header_manager' => BLUEHOST_PLUGIN_DIR . 'vendor/newfold-labs/wp-module-performance/includes/BurstSafetyMode/ResponseHeaderManager.php', ); - foreach ( $files_to_include as $path ) { - if ( file_exists( $path ) ) { - require_once $path; + foreach ( $files_to_include as $file_path ) { + if ( file_exists( $file_path ) ) { + require_once $file_path; } } @@ -53,6 +53,3 @@ update_option( 'newfold_burst_safety_mode', true ); } - - -vendor / bin / phpcbf --standard = phpcs . xml - s 'bootstrap.php' 'includes/BurstSafetyMode/Browser.php' 'includes/BurstSafetyMode/ResponseHeaderManager.php' 'includes/BurstSafetyMode/Skip404.php' 'includes/BurstSafetyMode/init.php' 'includes/CacheExclusion.php' 'includes/CacheManager.php' 'includes/CacheTypes/Browser.php' 'includes/CacheTypes/File.php' 'includes/Performance.php' 'includes/RestApi/CacheExclusionController.php' 'includes/RestApi/RestApi.php' 'includes/RestApi/SettingsController.php' 'includes/burstSafetyModeFunctions.php' 'includes/functions.php'