Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9075175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:48:39+00:00 2026-06-16T18:48:39+00:00

Hi I have this code in my functions.php and its working well when the

  • 0

Hi I have this code in my functions.php and its working well when the editor is viewing the Media library: http://example.com/wp-admin/upload.php

add_action('pre_get_posts','users_own_attachments');

function users_own_attachments( $wp_query_obj ) {

global $current_user, $pagenow;

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

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

if( !current_user_can('delete_users') )
    $wp_query_obj->set('author', $current_user->ID );

return;
}

The above code will prevent other editors from viewing the images uploaded by other editors in the media library. Only the administrator can see all images uploaded. The editor can only see the images uploaded by themselves (not others).

Now here is the issue, when creating or editing a post, WordPress has an “Add Media” button that will allow users to upload images to their gallery. But the code above does not work when the user will upload via “Add Media” popup. They can still see the images uploaded by other editors.

How is it possible to modify the above code so that it will still work when users are viewing images via the “Add Media” popup and not the media library? Thank you so much for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:48:40+00:00Added an answer on June 16, 2026 at 6:48 pm

    I have my answers here: https://wordpress.stackexchange.com/questions/78084/prevent-other-editors-from-viewing-images-of-other-editors-in-add-media-popup

    The strategy is to add a conditional tag that will check if the user is viewing the add media popup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');
I have this code: function submitTwice(f){ f.action = 'http://mydomain.com/threevideopage.php'; f.target='name'; f.submit(); } I left
For Example if i have my code like this (php): <?php somefunc(1); function somefunc($a)
Hi I have a problem here This is my code, its working when I
this is function.php of a wordpress theme that NOD32 says this code have a
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have the following jquery code: jQuery(function(){ jQuery(select#rooms).change(function(){ var options = ''; jQuery.getJSON(/admin/selection.php,{id: jQuery(this).val(),
This is the PHP code I have. function decrypt($s_input, $s_key, $s_iv) { $s_decrypted =
I have written this code outside all functions: int l, k; for (l =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.