By default, WordPress allows authors to view all the images in the media library of your site. This can become problematic if you have a lot of guest writers. We'll show you how to limit access to the WordPress Media Library to a user's own downloads.

Why restrict access to the media library?

WordPress allows authors to manipulate all files in the media library. They can also see uploaded images by an administrator, an editor or other authors.

Say you create a new article to announce the imminence of a product or a deal. The authors and those invited from your site will be allowed to consult the images that you have downloaded on this article in the media library.

Your downloads will also be visible in the “Add Media” pop-up that users see when they add images to their own posts.

For many websites, this may not be a big deal. However, if you use a website multi-author, you have the possibility to modify it.

Let's take a look at the easiest way to restrict access to the media library to a user's own downloads.

Method 1: Restrict access to the media library using an extension

This method is very easy and is recommended to all users.

The first thing to do would be to install and activate the extension Restrict Media Library. For more details, consult our guide explaining step by step the installation of a WordPress extension.

Restrict media access

This extension works without configuration, and there are no parameters to configure.

Upon activation, the extension filters the query from the media library to see if the user in question is an administrator or publisher. If the user's role does not match any of them, it will only show the user's downloads.

Users with administrator or publisher roles will be able to see all media downloads as usual.

Method 2: Manually restrict access to the media library

The first method should work for most websites because it limits access to the media library and allows only the administrator and publisher to view all media downloads.

However, if you want to add a custom user role or just do not want to use an extension, you can try this method instead. It uses the same code used by the extension but you can modify it to suit your needs.

This method requires you to add code to your WordPress files. If you've never done so before, then review our guide explaining how to copy and paste code on WordPress.

You will need to add the following code to your WordPress file " function.php Or a site-specific extension.

This code uses the function " current_user_can To check if the user has the ability to activate extensions or edit other users' posts. If this is not the case, this changes the query used to display the media files and the limit to the ID (login) of the user.

We hope this article has helped you learn how to restrict access to the WordPress Media Library to a user's own downloads. You can also limit authors to their own posts in the WordPress admin area.