Created
November 24, 2014 16:01
-
-
Save alanyoshida/d3c5b3b09dc99d74cdc9 to your computer and use it in GitHub Desktop.
Wordpress Snippet - Media Upload Selected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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