updated plugin W3 Total Cache
version 2.7.1
This commit is contained in:
@ -274,11 +274,19 @@ class Cache_File extends Cache_Base {
|
||||
*/
|
||||
function flush( $group = '' ) {
|
||||
@set_time_limit( $this->_flush_timelimit );
|
||||
$flush_dir = $group ?
|
||||
$this->_cache_dir . DIRECTORY_SEPARATOR . $group .
|
||||
DIRECTORY_SEPARATOR :
|
||||
$this->_flush_dir;
|
||||
Util_File::emptydir( $flush_dir, $this->_exclude );
|
||||
|
||||
if ( 'sitemaps' === $group ) {
|
||||
$config = Dispatcher::config();
|
||||
$sitemap_regex = $config->get_string( 'pgcache.purge.sitemap_regex' );
|
||||
$this->_flush_based_on_regex( $sitemap_regex );
|
||||
} else {
|
||||
$flush_dir = $group ?
|
||||
$this->_cache_dir . DIRECTORY_SEPARATOR . $group .
|
||||
DIRECTORY_SEPARATOR :
|
||||
$this->_flush_dir;
|
||||
Util_File::emptydir( $flush_dir, $this->_exclude );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -453,4 +461,38 @@ class Cache_File extends Cache_Base {
|
||||
$fp = @fopen( $path, $mode );
|
||||
return $fp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush cache based on regex
|
||||
*
|
||||
* @since 2.7.1
|
||||
*
|
||||
* @param string $regex
|
||||
*/
|
||||
private function _flush_based_on_regex( $regex ) {
|
||||
if ( Util_Environment::is_wpmu() && ! Util_Environment::is_wpmu_subdomain() ) {
|
||||
$domain = get_home_url();
|
||||
$parsed = parse_url( $domain );
|
||||
$host = $parsed['host'];
|
||||
$path = isset( $parsed['path'] ) ? '/' . trim( $parsed['path'], '/' ) : '';
|
||||
$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . DIRECTORY_SEPARATOR . $host . $path;
|
||||
} else {
|
||||
$flush_dir = W3TC_CACHE_PAGE_ENHANCED_DIR . DIRECTORY_SEPARATOR . Util_Environment::host();
|
||||
}
|
||||
|
||||
$dir = @opendir( $flush_dir );
|
||||
if ( $dir ) {
|
||||
while ( ( $entry = @readdir( $dir ) ) !== false ) {
|
||||
if ( '.' === $entry || '..' === $entry ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( preg_match( '~' . $regex . '~', basename( $entry ) ) ) {
|
||||
Util_File::rmdir( $flush_dir . DIRECTORY_SEPARATOR . $entry );
|
||||
}
|
||||
}
|
||||
|
||||
@closedir( $dir );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user