WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to restrict authors ability to see files uploaded by other users because this causes no end of trouble, since they can change captions etc.

I tried this code from here How to hide media uploads by other users in the Media menu?

function users_own_attachments( $wp_query_obj ) {

    global $current_user, $pagenow;

    if( !is_a( $current_user, 'WP_User') )

    if( 'upload.php' != $pagenow )

    if( !current_user_can('delete_pages') )
        $wp_query_obj->set('author', $current_user->id );


This only works on the media screen, not when you select a file on a post to actually upload.

I also tried the second solution, but it's causing issues with my autocomplete search function and I can't figure out why.

Is there a way to stop authors seeing others files when they're making a post?

share|improve this question

Not tested, but maybe you can just extend the $pagenow check?

Instead of …

if( 'upload.php' != $pagenow )

… try …

if( ! in_array( $pagenow, array ( 'upload.php', 'post-new.php', 'post.php' ) ) )

That should cover the post editor screens too.

share|improve this answer
Tested that, doesn't work unfortunately. – andy Apr 28 '13 at 0:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.