Created
March 6, 2014 14:07
-
-
Save Arty2/9390440 to your computer and use it in GitHub Desktop.
Raw utility to remove all thumbnails files from WordPress's upload directory. Edit as necessary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* raw utility to delete deprecated thumbnail files | |
* to move into a plugin at some point | |
*/ | |
// comment following line and move to WordPress root | |
if ( !defined('ABSPATH') ) die; | |
function files($base) { | |
$root = scandir($base); | |
foreach($root as $dir) { | |
if ( $dir === '.' || $dir === '..') { | |
continue; | |
} | |
if ( is_file("$base/$dir") ) { | |
$result[] = "$base/$dir"; | |
continue; | |
} | |
foreach( files("$base/$dir") as $dir) { | |
$result[]=$dir; | |
} | |
} | |
return $result; | |
} | |
$uploads = '/media'; // by default: /wp-content/uploads | |
$files = files( dirname(__FILE__) . $uploads ); | |
$thumbnails = array(); | |
foreach ($files as $key => $file ) { | |
if ( 1 == preg_match('#-\d+x\d+\.#', $file) ) { | |
$thumbnails[] = $file; | |
// uncomment following line to delete files | |
// unlink($file); | |
} | |
} | |
echo '<pre>'; | |
print_r($thumbnails); | |
echo '</pre>'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment