Change the default-view of Media Library in 3.5?

There were two minor mistakes in my previous answer:

  1. I forgot to trigger the change event for the parent.
  2. I called the function on every AJAX call, making other selections impossible.

Here is the fixed code:

<?php
/**
 * Plugin Name: Pre-select post specific attachments
 */

add_action( 'admin_footer-post-new.php', 'wpse_76048_script' );
add_action( 'admin_footer-post.php', 'wpse_76048_script' );

function wpse_76048_script()
{
    ?>
<script>
jQuery(function($) {
    var called = 0;
    $('#wpcontent').ajaxStop(function() {
        if ( 0 == called ) {
            $('[value="uploaded"]').attr( 'selected', true ).parent().trigger('change');
            called = 1;
        }
    });
});
</script>
    <?php
}

Leave a Comment