Custom attachments uploader code. Almost there!

1) The attachment_fields_to_save filter does not get applied, even though I can see the echo’d text inside the media-upload.php window. I know this because the _imageTop meta only gets written to the database when I comment out the if(isset) check

Try to exchange $_GET with $_POST and see if it works. If so, you need to check for $_POST as well.

2) After the images have been uploaded, I have to click on “Save all changes” to get the _imageTop meta to save to the database. Ideally, I’d like the data saved immediately after the upload, without having to click “Save all changes”. This is probably due to the fact that the attachment_fields_to_save handler only fires on the “Save all changes” hook. Nevertheless, I’d like to figure out how to get it to fire when the images have been uploaded.

If it does not get fired, the only thing you can do is to fire it your own, e.g. call the hook function directly. If that is not possible (e.g. you have not code that is executed so you can’t execute your additional code then), you need to look for another action you can hook into, e.g. one that get’s fired after the upload. There probably is some hook when the image get’s saved in the media library. You could then store your custom post field as well (!) into the database. Just to have it saved. I dunno if WP is able to handle that with it’s revision system, so you need to try.

3) I want to remove the “insert into post” link from the screen.

I do not know how this can be done from the top of my head, you should check the core code if there is something you can override with/by a hook.

Leave a Comment