From 9a7cd89fa06b153de1e3d8dfae8a6fb95b7d3013 Mon Sep 17 00:00:00 2001
From: Armando Liccardo
Date: Thu, 7 Nov 2024 11:55:59 +0000
Subject: [PATCH] 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.
*