Skip to content

Commit

Permalink
Merge pull request #194 from Automattic/rebuild_in_cache_dir_only
Browse files Browse the repository at this point in the history
wp_cache_rebuild_or_delete() - make sure file is in cache_path
  • Loading branch information
donnchawp committed Feb 8, 2017
2 parents 41d95cc + 4d4f161 commit f447a47
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions wp-cache-phase2.php
Expand Up @@ -824,9 +824,21 @@ function prune_super_cache( $directory, $force = false, $rename = false ) {
}

function wp_cache_rebuild_or_delete( $file ) {
global $cache_rebuild_files;
if( strpos( $file, '?' ) !== false )
global $cache_rebuild_files, $cache_path;
static $rp_cache_path = '';

if ( $rp_cache_path == '' ) {
$rp_cache_path = trailingslashit( realpath( $cache_path ) );
}

if ( strpos( $file, '?' ) !== false )
$file = substr( $file, 0, strpos( $file, '?' ) );
$file = realpath( $file );
if ( substr( $file, 0, strlen( $rp_cache_path ) ) != $rp_cache_path ) {
wp_cache_debug( "rebuild_or_gc quitting because file is not in cache_path: $file" );
return false;
}

if( $cache_rebuild_files && substr( $file, -14 ) != '.needs-rebuild' ) {
if( @rename($file, $file . '.needs-rebuild') ) {
@touch( $file . '.needs-rebuild' );
Expand Down

0 comments on commit f447a47

Please sign in to comment.