0

What I am trying to do is -

1) User clicks "Add Media"

2) Select an image

3) Image uploads finishes

4) Now it should insert into post automatically without pressing "Insert into post".

Anywhere to hook, and click the "Insert into post" using jquery.

Any clues ?

  • The code for the media library is not fun to work with - trust me. – Seamus Leahy Nov 1 '14 at 22:30
  • you're right, I am looking for any hack though. – user2119554 Nov 2 '14 at 4:52
3

The hook for doing stuff after an upload is the reset event on wp.Uploader.queue triggered by the pluploader when it's finished (see line 249 in "wp-includes/js/plupload/wp-plupload.js"). Here's one hack to use this to do an auto-insert after an upload:

function wpse167143_admin_footer() {
?>
<script>
jQuery( document ).ready(function() {
    typeof wp.Uploader !== 'undefined' && wp.Uploader.queue.on( 'reset', function () {
        // From the primary toolbar (".media-toolbar-primary")
        // get the insert button view (".media-button-insert")
        // and execute its click (as specified in its options).
        wp.media.frame.toolbar.get('primary').get('insert').options.click();
    } );
});
</script>
<?php
}
add_action( 'admin_footer' , 'wpse167143_admin_footer' );

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.