admin管理员组文章数量:1122832
I have a function to add EXIF information to an image after the image is uploaded to a website. How do I get the EXIF information to be automatically added to the image after the image is uploaded or added to the post?
I have tried some hooks like the following to check for failed photo uploads and started executing the function to add EXIF info but it doesn't work. add_attachment
, wp_handle_upload
and wp_handle_upload_prefilter
. Whenever an image is uploaded through adding to the post, it gives an error that the image could not be uploaded.
Below is an example of my code. Every time I select an image to add to a post, I get a message like this. Please help me. Thank you very much!
An error occurred in the upload. Please try again later.
function custom_to_all_image($upload) {
if (wp_attachment_is_image($attachment_id)) {
//my function
}
return $upload;
}
add_filter( 'wp_handle_upload', 'custom', 10, 2 );
I have a function to add EXIF information to an image after the image is uploaded to a website. How do I get the EXIF information to be automatically added to the image after the image is uploaded or added to the post?
I have tried some hooks like the following to check for failed photo uploads and started executing the function to add EXIF info but it doesn't work. add_attachment
, wp_handle_upload
and wp_handle_upload_prefilter
. Whenever an image is uploaded through adding to the post, it gives an error that the image could not be uploaded.
Below is an example of my code. Every time I select an image to add to a post, I get a message like this. Please help me. Thank you very much!
An error occurred in the upload. Please try again later.
function custom_to_all_image($upload) {
if (wp_attachment_is_image($attachment_id)) {
//my function
}
return $upload;
}
add_filter( 'wp_handle_upload', 'custom', 10, 2 );
Share
Improve this question
edited May 3, 2023 at 13:18
Kelvin Ngo
asked May 2, 2023 at 16:29
Kelvin NgoKelvin Ngo
113 bronze badges
7
|
Show 2 more comments
1 Answer
Reset to default 1Update: Edited code to make it work
function proccess_to_all_image($file) {
$file_path = $file['file'];
$mime_type = $file['type'];
$id = attachment_url_to_postid($file['url']);
if (preg_match('/^image\/[a-z\-]+$/i', $mime_type)) {
*//call to function here*
}
return $file;
}
add_filter( 'wp_handle_upload', 'proccess_to_all_image', 10, 2);
本文标签: plugin developmentHow to add extra EXIF data when images are uploaded
版权声明:本文标题:plugin development - How to add extra EXIF data when images are uploaded? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300254a1930748.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
echo
on image upload as those happen during AJAX calls and there'd be no way to see your output, it'd also break the AJAX response! That's why the post editor says image could not be uploaded. What are you trying to do that requires this? It sounds like an X Y problem were you asked how to implement your fix not how to solve the problem. I read the initial few sentences that try to explain this but it didn't make much sense. What does reprocessing do? Are you trying to optimise images? Making your Q more specific will get you more/better answers – Tom J Nowell ♦ Commented May 2, 2023 at 16:55