Timber\ImageHelper::delete_generated_files PHP Method

delete_generated_files() static public method

Deletes the auto-generated files for resize and letterboxing created by Timber
static public delete_generated_files ( string $local_file )
$local_file string ex: /var/www/wp-content/uploads/2015/my-pic.jpg or: http://example.org/wp-content/uploads/2015/my-pic.jpg
    static function delete_generated_files($local_file)
    {
        if (URLHelper::is_absolute($local_file)) {
            $local_file = URLHelper::url_to_file_system($local_file);
        }
        $info = pathinfo($local_file);
        $dir = $info['dirname'];
        $ext = $info['extension'];
        $filename = $info['filename'];
        self::process_delete_generated_files($filename, $ext, $dir, '-[0-9999999]*', '-[0-9]*x[0-9]*-c-[a-z]*.');
        self::process_delete_generated_files($filename, $ext, $dir, '-lbox-[0-9999999]*', '-lbox-[0-9]*x[0-9]*-[a-zA-Z0-9]*.');
        self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg.*');
        self::process_delete_generated_files($filename, 'jpg', $dir, '-tojpg-[0-9999999]*');
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Deletes all resized versions of an image when the source is deleted
  */
 protected static function add_actions()
 {
     add_action('delete_attachment', function ($post_id) {
         $post = get_post($post_id);
         $image_types = array('image/jpeg', 'image/png', 'image/gif', 'image/jpg');
         if (in_array($post->post_mime_type, $image_types)) {
             $attachment = new Image($post_id);
             if ($attachment->file_loc) {
                 ImageHelper::delete_generated_files($attachment->file_loc);
             }
         }
     });
 }
All Usage Examples Of Timber\ImageHelper::delete_generated_files