Skip to content

How to lock uploads to show only “Uploaded to this post” in media panel

This will lock uploads to “Uploaded to this post” and will not show “All media items” or other options in WordPress 3.5 media panels.

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 }

 

3 thoughts on “How to lock uploads to show only “Uploaded to this post” in media panel

  1. Jeff says:

    Hi Ünsal, Thanks for this code snippet. This has really helped me. Do you think it is possible to set the media panel so that instead of showing only images uploaded to the post, it shows only images uploaded by the user currently editing the post/page? I’m trying to get myself up and running on backbone so I can understand the WP Core files a little better. So far I get the basic concepts and the way the new media uploader is set up is pretty impressive.

    Thanks!

    Reply
    • Avatar of Ünsal Korkmaz
      Ünsal Korkmaz says:

      This snippet is a javascript trick to forcing to choose “Uploaded to this post”. Your question needs a different approach which i am a beginner about backbone.js too :-/

      Reply
      • Jeff says:

        Sounds good. I’ll see how far I get and let you know if I can figure out a way of doing this. Time to dig in!  : )

        Reply

Leave a Reply

Your email address will not be published. Required fields are marked *