最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugin development - Hook after attachment added and cropped

programmeradmin0浏览0评论

I am looking for hook, that fires right after image uploaded, cropped for thumbnails and data posted to database.

I need it for image optimization after uploading.

I tried add_attachment and it fires before image cropping and my code stuck. Help please!

I am looking for hook, that fires right after image uploaded, cropped for thumbnails and data posted to database.

I need it for image optimization after uploading.

I tried add_attachment and it fires before image cropping and my code stuck. Help please!

Share Improve this question asked Jan 24, 2022 at 12:43 DennyDenny 212 bronze badges 2
  • How about wp_handle_upload it's a filter that fires after a file is being uploaded – Buttered_Toast Commented Jan 24, 2022 at 12:53
  • This filter fires before image cropped and added to database. – Denny Commented Jan 24, 2022 at 23:10
Add a comment  | 

1 Answer 1

Reset to default 1

There is to filters needed for optimizing all images, that will be uploaded:

add_filter('wp_handle_upload', 'random_function', 10, 2);
add_filter('image_make_intermediate_size', 'rand_function2', 10, 1);

function random_function($array, $string) {
// Some random action with main image
return $array
}

function rand_function2($file) {
// Some random action with cropped images
return $file
}
发布评论

评论列表(0)

  1. 暂无评论