Timber\ImageHelper::process_delete_generated_files PHP Method

process_delete_generated_files() protected static method

So if passed a value like my-pic.jpg, this function will delete my-pic-500x200-c-left.jpg, my-pic-400x400-c-default.jpg, etc. keeping these here so I know what the hell we're matching $match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/$filename-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $found_file); $match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/arch-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $filename);
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);
            }
        }
    }