After you have uploaded an attachment in WordPress using the media upload screen, is there a hook or filter I can run after the image has been uploaded where I can get the path to the uploaded image so I can analyse it?
I am building a plugin that will analyse an image after it has been uploaded and then tag the image with the average colour it finds in the image. The only problem is I don’t know what hook I can use that will fire right after the image has uploaded and then a way I can get the path to the newly uploaded file.
Any help would be gratefully appreciated.
Turns out I solved my own question with help from a colleague. The two filters that get called after media is uploaded or when media is being edited are; ‘add_attachment’ and ‘edit_attachment’. Here is the code I am using, I then check to see if the attachment is an image (code omitted from example).
Obviously I’ve omitted some stuff that isn’t relevant to the question. But that code gets called right after you’ve uploaded or edited an attachment.
you have two filters you can use:
attachment_fields_to_save
which gets two paramaters ( $post, $attachment)
so :
and
media_send_to_editor
which gets 3 paramaters ( $html, $send_id, $attachment) and fires after you click the send to editor so once again you can use $attachment.HTML Markup:
Uploading the image: