WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 1 down vote accepted

This was solved as simply as:

  1. Hooking a custom .js script to the media-upload thickbox, so that it runs inside the iFrame:

    function admin_styles_scripts_media_upload() {
        wp_register_script('mediajs', get_template_directory_uri().'/js/button.js', array('jquery'), true);
  2. Use the script to replace the default Save button with a custom one, and call self.parent.tb_remove from that:

    jQuery(document).ready(function() {
        jQuery('<a href="#" id="back_to_admin" class="button">Voltar para Edição</a>').insertAfter('.ml-submit');   
        jQuery('#back_to_admin').live('click',function() {
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.