WordPress 3.5 Media Manager – Reorder Selectbox items on Media Library Tab [duplicate]

I was able to answer this via help from a great plugin editor.

This solution doesn’t reorder the select box but instead forces it to only load the “Uploaded to this Post” media by default. I used some of the JS from this post to get the select box to change.

I had some help from the great Sewpafly who develops Post Thumbnail Editor Plugin. he shared a great piece of JS that prevents the load of All Media Items and forces it to load only images Uploaded to this Post by default.

admin.js

jQuery(function($) {
    var called = 0;
    $('#wpcontent').ajaxStop(function() {
        if ( 0 == called ) {
            $('[value="uploaded"]').attr( 'selected', true ).parent().trigger('change');
            called = 1;
        }
    });
  var oldPost = wp.media.view.MediaFrame.Post;
    wp.media.view.MediaFrame.Post = oldPost.extend({
        initialize: function() {
            oldPost.prototype.initialize.apply( this, arguments );
            this.states.get('insert').get('library').props.set('uploadedTo', wp.media.view.settings.post.id);
        }
    });
});

functions.php

add_action('admin_enqueue_scripts', 'add_admin_js');
function add_admin_js(){
  wp_enqueue_script('admin_js', get_bloginfo( 'template_directory' ) . '/javascripts/admin.js'); 
}

As a Gist

I dropped that into a JS file and called it in functions.php with the admin_enqueue_scripts.

Works brilliantly. Hopefully the fine wordpress folks fix this in a upcoming update, but for now Sewpafly has the best solution I’ve found. Thanks again buddy. Hope this helps some other fine folks out there.

Leave a Comment