Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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);
        wp_enqueue_script('mediajs');
    
    }
    add_action('admin_print_scripts-media-upload-popup','admin_styles_scripts_media_upload');
    ?>
    
  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('.savebutton.ml-submit').detach();
        jQuery('a.toggle').live("remove");
    
        jQuery('#back_to_admin').live('click',function() {
    
            parent.uploadedImages();
            self.parent.tb_remove();
    
    });
    
    });
    
share|improve this answer
add comment

Your Answer

 
discard

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.