images - Is there a hook which fires after all thumbnails are generated?

I want to upload the image and all generated thumbnails to another server (as backup). I only found add_attachment, but

I want to upload the image and all generated thumbnails to another server (as backup). I only found add_attachment, but this is fired right after the image was uploaded and the postmeta table was updated.

I want to wait until all thumbnail sizes are generated and then take the files and upload them to the other server. Is there any hook which matches my expectations?

I want to upload the image and all generated thumbnails to another server (as backup). I only found add_attachment, but this is fired right after the image was uploaded and the postmeta table was updated.

I want to wait until all thumbnail sizes are generated and then take the files and upload them to the other server. Is there any hook which matches my expectations?

Share Improve this question edited Feb 9, 2017 at 23:08 JHoffmann 1,87014 silver badges18 bronze badges asked Feb 9, 2017 at 23:04 sydevsydev 1231 silver badge10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 8

Thumbnails in WordPress can be generated by using wp_generate_attachment_metadata(), this function fires a filter after generating all the thumbnails wp_generate_attachment_metadata and the filter provides $metadata and $attachment_id to the hooked functions.

You can hook your custom function to this filter.

$metadata : Attachment metadata. What you need is $metadata['sizes']['<size-name>'], the <size-name> is the name of thumbnail size added by add_image_size() or the default ones. e.g.

$metadata[sizes] => Array
       (
           [thumbnail] => Array
               (
                   [file] => example_image-150x150.jpg
                   [width] => 150
                   [height] => 150
                   [mime-type] => image/jpeg
               )
           [medium] => Array
               (
                   [file] => example_image-4-300x194.jpg
                   [width] => 300
                   [height] => 194
                   [mime-type] => image/jpeg
               )
           [mysize] => Array
               (
                   [file] => example_image-4-400x400.jpg
                   [width] => 400
                   [height] => 400
                   [mime-type] => image/jpeg
               )
       )

from here you can know which sizes exist for the certain attachment, and only upload those sizes/thumbnails.

To get those thumbnails use a function like wp_get_attachment_image_src($id, $size_name) to retrieve the thumbnail urls.

(Optional) : Install the Force Regenerate Thumbnails plugin to rerun the wp_generate_attachment_metadata() for previously uploaded images too.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745318870a4622348.html

相关推荐

  • images - Is there a hook which fires after all thumbnails are generated?

    I want to upload the image and all generated thumbnails to another server (as backup). I only found add_attachment, but

    9小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信