Skip to content

Commit

Permalink
changed rule for cache exclusion in browser class + sanitize
Browse files Browse the repository at this point in the history
  • Loading branch information
geckod22 committed Jan 8, 2025
1 parent f5ae0a2 commit e25aff5
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions includes/CacheTypes/Browser.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,16 @@ public static function addRules( $cacheLevel ) {
}
$rules[] = '</IfModule>';

$cache_exclusion_parameters = array_map( 'trim', explode( ',', get_option( CacheExclusion::OPTION_CACHE_EXCLUSION ) ) );
$cache_exclusion_parameters = array_map( 'trim', explode( ',', sanitize_text_field( get_option( CacheExclusion::OPTION_CACHE_EXCLUSION ) ) ) );
$cache_exclusion_parameters = implode( '|', $cache_exclusion_parameters );

// 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]';
$rules[] = "RewriteCond %{REQUEST_URI} ^/({$cache_exclusion_parameters}) [NC]";
$rules[] = 'Header set Cache-Control "no-cache, no-store, must-revalidate"';
$rules[] = 'Header set Pragma "no-cache"';
$rules[] = 'Header set Expires 0';
$rules[] = '</IfModule>';
// Add the end of the rules about cache exclusion.

Expand Down

0 comments on commit e25aff5

Please sign in to comment.