Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View admin.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
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);
}
});
});
View admin.js
1 2 3 4
add_action('admin_enqueue_scripts', 'add_admin_js');
function add_admin_js(){
wp_enqueue_script('admin_js', get_bloginfo( 'template_directory' ) . '/javascripts/admin.js');
}

Mind that you don't have wp.media always availible. I've surrounded everything with if(wp.media){}

If you are creating functions.php from scratch remember to put <?php at the beginning. If in addition you are using a child theme functions.php should be:
<?php
add_action('admin_enqueue_scripts', 'add_admin_js');
function add_admin_js(){
wp_enqueue_script('admin_js', get_stylesheet_directory_uri() . '/javascripts/admin.js');
}
which will ensure that we are redirected to the correct folder in the child theme.

nkmail commented

radiokills, can you put your code in full here, please. I got "Uncaught ReferenceError: wp is not defined " in my case, so javascripts stop working (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.