I’m working on a front-end uploader using WP’s own media-uploading functions. All is well, except that I just want to simplify some UI things, like removing tabs and unnecessary information for my users. Most importantly, I’d like to magically close the Upload Thickbox once the uploads are done and the files are crunched.
I’m aware of the add_attachment
hook and I’m already using it to do some ImageMagick handling, but it fires every time a file is uploaded, so this is kind of too much.
Seaching through core, I got to wp-includes/js/swfupload/handlers.dev.js and around line 232 there’s this:
function uploadComplete(fileObj) {
// If no more uploads queued, enable the submit button
if ( swfu.getStats().files_queued == 0 ) {
jQuery('#cancel-upload').prop('disabled', true);
jQuery('#insert-gallery').prop('disabled', false);
}
}
This is precisely where I want to hook so that, instead of enabling the submit button, I’d just fire TB_close()
.
Can this be done in any way?
This was solved as simply as:
Hooking a custom .js script to the media-upload thickbox, so that it runs inside the iFrame:
Use the script to replace the default Save button with a custom one, and call
self.parent.tb_remove
from that: