Skip to content

Commit

Permalink
some fixies and phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
geckod22 committed Nov 12, 2024
1 parent a811cbc commit d9bd0df
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
13 changes: 7 additions & 6 deletions includes/CacheTypes/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
use function NewfoldLabs\WP\Module\Performance\getCacheLevel;
use function WP_Forge\WP_Htaccess_Manager\removeMarkers;

/**
* Browser cache class
*/
class Browser extends CacheBase {


/**
* The file marker name.
*
Expand All @@ -24,7 +25,7 @@ class Browser 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 Down Expand Up @@ -97,21 +98,21 @@ public static function addRules( $cacheLevel ) {
$rules[] = "{$tab}ExpiresByType {$fileType} \"access plus {$expiration}\"";
}
}
$rules[] = '</IfModule>';

$cache_exclusion_parameters = array_map( 'trim', explode( ',', get_option( CacheExclusionController::OPTION_CACHE_EXCLUSION ) ) );

// Add the cache exclusion rules.
$rules[] = '<IfModule mod_rewrite.c>';
$rules[] = 'RewriteEngine On';
foreach ( $cache_exclusion_parameters as $param ) {
if ( ! empty( $param ) ) {
$rules[] = "RewriteCond %{REQUEST_URI} !{$param} [NC]";
}
}
$rules[] = 'RewriteRule .* - [E=Cache-Control:no-cache]';

// Add the end of the rules about cache exclusion.

$rules[] = '</IfModule>';
// Add the end of the rules about cache exclusion.

$htaccess = new htaccess( self::MARKER );

Expand Down
19 changes: 7 additions & 12 deletions includes/CacheTypes/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
use function NewfoldLabs\WP\Module\Performance\shouldCachePages;
use function WP_Forge\WP_Htaccess_Manager\removeMarkers;

/**
* Page cache class
*/
class File extends CacheBase implements Purgeable {



/**
* The directory where cached files live.
*
Expand All @@ -36,7 +36,7 @@ class File extends CacheBase implements Purgeable {
/**
* Whether or not the code for this cache type should be loaded.
*
* @param Container $container
* @param Container $container the container.
*
* @return bool
*/
Expand Down Expand Up @@ -89,11 +89,6 @@ public static function addRules() {
$base = wp_parse_url( home_url( '/' ), PHP_URL_PATH );
$path = str_replace( get_home_path(), '/', self::CACHE_DIR );

$exclude_conditions = '';
foreach ( $this->exclusions() as $exclude ) {
$exclude_conditions .= "RewriteCond %{REQUEST_URI} !^/{$exclude} [NC]\n";
}

$content = <<<HTACCESS
<IfModule mod_rewrite.c>
RewriteEngine On
Expand All @@ -103,7 +98,7 @@ public static function addRules() {
RewriteCond %{QUERY_STRING} !.*=.*
RewriteCond %{HTTP_COOKIE} !(wordpress_test_cookie|comment_author|wp\-postpass|wordpress_logged_in|wptouch_switch_toggle|wp_woocommerce_session_) [NC]
RewriteCond %{HTTP:Cache-Control} ^((?!no-cache).)*$
{$exclude_conditions}RewriteCond %{DOCUMENT_ROOT}{$path}/$1/_index.html -f
RewriteCond %{DOCUMENT_ROOT}{$path}/$1/_index.html -f
RewriteRule ^(.*)\$ {$path}/$1/_index.html [L]
</IfModule>
HTACCESS;
Expand Down Expand Up @@ -261,7 +256,7 @@ public function shouldCache() {
* @return array
*/
protected function exclusions() {
$default = array( 'cart', 'checkout', 'wp-admin', '@', '%', ':', ';', '&', '=', '.', rest_get_url_prefix();
$default = array( 'cart', 'checkout', 'wp-admin', '@', '%', ':', ';', '&', '=', '.', rest_get_url_prefix() );
$cache_exclusion_option = array_map( 'trim', explode( ',', get_option( CacheExclusionController::OPTION_CACHE_EXCLUSION ) ) );
return array_merge( $default, $cache_exclusion_option );
}
Expand Down Expand Up @@ -292,7 +287,7 @@ public function purgeAll() {
/**
* Purge a specific URL from the cache.
*
* @param string $url
* @param string $url the url to purge.
*/
public function purgeUrl( $url ) {
$path = $this->getStoragePathForRequest();
Expand Down

0 comments on commit d9bd0df

Please sign in to comment.