How to Automatically Insert Into Post when uploading Media in WordPress

This is how I did it:

First, in your plugin, force the basic uploader. If you want the flash uploader, sorry.

add_filter( 'flash_uploader', '_force_html_uploader' );

function _force_html_uploader( $flash ) {
    remove_action('post-html-upload-ui', 'media_upload_html_bypass' );
    return false;
}

Then tell WP to put a JavaScript in the Media Uploader’s <head>:

add_action('media_upload_tabs', '_media_upload_auto_insert_js');

function _media_upload_auto_insert_js(){
    ?>?php%20bloginfo('stylesheet_directory');%20?/js/upload.js<?php
}

Then, in that JavaScript file, when the page is loaded with the button to Insert Into Post, click it for them!

uploads.js

jQuery(document).ready(function(){
    if(jQuery(".savesend input")){
        jQuery(".savesend input").click();
    }
});

Leave a Reply