protected static process_delete_generated_files ( string $filename, string $ext, string $dir, string $search_pattern, string $match_pattern = null ) | ||
$filename | string | ex: my-pic |
$ext | string | ex: jpg |
$dir | string | var/www/wp-content/uploads/2015/ |
$search_pattern | string | pattern of files to pluck from |
$match_pattern | string | pattern of files to go forth and delete |
protected static function process_delete_generated_files($filename, $ext, $dir, $search_pattern, $match_pattern = null)
{
$searcher = '/' . $filename . $search_pattern;
foreach (glob($dir . $searcher) as $found_file) {
$regexdir = str_replace('/', '\\/', $dir);
$pattern = '/' . $regexdir . '\\/' . $filename . $match_pattern . $ext . '/';
$match = preg_match($pattern, $found_file);
if (!$match_pattern || $match) {
unlink($found_file);
}
}
}