WP_CLI
FileCache::prune()
Remove all cached files except for the newest version of one.
Method of the class: FileCache{}
No Hooks.
Return
true|false
.
Usage
$FileCache = new FileCache(); $FileCache->prune();
FileCache::prune() FileCache::prune code WP-CLI 2.8.0-alpha
public function prune() { if ( ! $this->enabled ) { return false; } /** @var Finder $finder */ $finder = $this->get_finder()->sortByName(); $files_to_delete = []; foreach ( $finder as $file ) { $pieces = explode( '-', $file->getBasename( $file->getExtension() ) ); $timestamp = end( $pieces ); // No way to compare versions, do nothing. if ( ! is_numeric( $timestamp ) ) { continue; } $basename_without_timestamp = str_replace( '-' . $timestamp, '', $file->getBasename() ); // There's a file with an older timestamp, delete it. if ( isset( $files_to_delete[ $basename_without_timestamp ] ) ) { unlink( $files_to_delete[ $basename_without_timestamp ] ); } $files_to_delete[ $basename_without_timestamp ] = $file->getRealPath(); } return true; }