Skip to content

Instantly share code, notes, and snippets.

@alanyoshida
Created November 24, 2014 16:01
Show Gist options
  • Save alanyoshida/d3c5b3b09dc99d74cdc9 to your computer and use it in GitHub Desktop.
Save alanyoshida/d3c5b3b09dc99d74cdc9 to your computer and use it in GitHub Desktop.
Wordpress Snippet - Media Upload Selected
<?php
/*
Plugin Name: Media Upload Selected - Snippet
Description: Show by default the Midia uploaded from the selected post on insert midia.
Version: 0.1
License: GPL
*/
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
}
add_action( 'admin_footer-post-new.php', 'firmasite_mediapanel_lock_uploaded' );
add_action( 'admin_footer-post.php', 'firmasite_mediapanel_lock_uploaded' );
function firmasite_mediapanel_lock_uploaded() { ?>
<script type="text/javascript">
jQuery(document).on("DOMNodeInserted", function(){
// Lock uploads to "Uploaded to this post"
jQuery('select.attachment-filters [value="uploaded"]').attr( 'selected', true ).parent().trigger('change');
});
</script>
<?php }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment