1

I would like to hook into the wp.Uploader and get the FileList object containing the file to be uploaded. So far I've been able to extend the uploader using the code below, but I can't quite seem to find the "before upload" hook.

$.extend( wp.Uploader.prototype, {
  success : function( file_attachment ){
    console.log( file_attachment );
  }
});
0

You can't hook it directly as wp.Uploader doesn't expose it but you can use its init() to hook its internal pluploader instance:

add_action( 'admin_print_footer_scripts', function () {
    ?>
    <script type="text/javascript">
    (function ($) {
        if (typeof wp.Uploader === 'function') {
            $.extend( wp.Uploader.prototype, {
                init : function() { // plupload 'PostInit'
                    this.uploader.bind('BeforeUpload', function(file) {
                        console.log('BeforeUpload file=%o', file);
                    });
                },
                success : function( file_attachment ) { // plupload 'FileUploaded'
                    console.log( file_attachment );
                }
            });
        }
    })(jQuery);
    </script>
    <?php
}, 100 );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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