public static _delete_generated_if_image ( integer $post_id ) | ||
$post_id | integer | an attachment post id |
public static function _delete_generated_if_image($post_id)
{
if (wp_attachment_is_image($post_id)) {
$attachment = new Image($post_id);
if ($attachment->file_loc) {
ImageHelper::delete_generated_files($attachment->file_loc);
}
}
}
/** * Deletes all resized versions of an image when the source is deleted * or its meta data is regenerated */ protected static function add_actions() { add_action('delete_attachment', function ($post_id) { \Timber\ImageHelper::_delete_generated_if_image($post_id); }); add_filter('wp_generate_attachment_metadata', function ($metadata, $post_id) { \Timber\ImageHelper::_delete_generated_if_image($post_id); return $metadata; }, 10, 2); }