Skip to content

Commit

Permalink
moved getDefaultCacheExclusions function to functions file
Browse files Browse the repository at this point in the history
  • Loading branch information
geckod22 committed Nov 7, 2024
1 parent 449116b commit 9a7cd89
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
13 changes: 3 additions & 10 deletions includes/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use NewfoldLabs\WP\ModuleLoader\Container;
use WP_Forge\Collection\Collection;

use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions;

class CacheManager {

/**
Expand Down Expand Up @@ -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() ) ) );
}

/**
Expand Down
4 changes: 3 additions & 1 deletion includes/RestApi/CacheExclusionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use NewfoldLabs\WP\Module\ECommerce\Permissions;
use NewfoldLabs\WP\ModuleLoader\Container;

use function NewfoldLabs\WP\Module\Performance\getDefaultCacheExclusions;

/**
* Class CacheExclusionController
*/
Expand Down Expand Up @@ -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
);
Expand Down
9 changes: 9 additions & 0 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9a7cd89

Please sign in to comment.