How WordPress media access control works

Learn how WordPress media access control works across two layers: backend Media Library visibility, and frontend file URL protection. In this guide, I'll cover code fixes and plugin options, and help you decide which approach suits your site.
WordPress treats every uploaded file as public by default. Anything stored in wp-content/uploads/ has a direct URL that anyone can visit without logging in. This predictable path leads straight to your file 😬
This creates two separate problems that need two separate solutions:
- Backend visibilityWhich logged-in users see which files inside the admin Media Library.
- Frontend file protectionWhether someone with a direct URL can download the actual file.
Most guides cover one side and ignore the other. I'm going to cover both: admin restriction, URL blocking, search engine indexing, and authenticated downloads. By the end, you'll know exactly which tools to combine for your specific use case.
Restricting backend Media Library visibility
WordPress media access control starts with role capabilities. The upload_files capability controls who can access the Media Library at all.
Authors, Editors, and Administrators have this capability by default. Contributors and Subscribers do not. Without upload_files, a user has zero access to the Media Library menu. They can't upload files or browse the media modal at all. You would need to explicitly grant upload_files via code or a role-editor plugin for these roles to see anything.
However, it's not ideal because every user with the upload_files capability sees all media items. WordPress doesn't filter by author out of the box. An Author sees uploads from every other Author, Editor, and Administrator on the site. On a multi-author blog with 20 contributors, every Author sees every image, PDF, and video uploaded by all 19 other users.
The code fix
The most common solution is the ajax_query_attachments_args filter. Add it to your child theme's functions.php or a code snippets plugin like WPCode.
The snippet checks current_user_can('edit_others_posts'). If false, it sets the author query parameter to the current user's ID. Only their own uploads appear in the Media Library grid.
Editors and Admins retain full access because they have the edit_others_posts capability. Authors do not, so they only see their own files.
The limitation of backend media file access filters
The filter I mentioned above only fires on the wp_ajax_query_attachments AJAX endpoint. REST API requests to /wp/v2/media bypass it entirely. It doesn't cover custom blocks or headless setups that query the REST API.
The more robust approach is to filter all three query paths:
ajax_query_attachments_argsfor the media modal AJAX requests.pre_get_postsfor the main Media Library screen in wp-admin.rest_attachment_queryfor REST-based attachment requests (including modern editor flows that use REST under the hood).
Why restricting the Media Library doesn't protect your files
Every file uploaded to WordPress lives in wp-content/uploads/ at a predictable URL. WordPress organizes uploads into year/month subdirectories by default, per the wp_upload_dir() documentation. A typical URL looks like this: yourdomain.com/wp-content/uploads/2025/03/filename.pdf.
That URL works for anyone, whether or not they're logged in or restricted in the admin.
The WordPress hosting handbook states that the uploads directory must remain web-accessible for the site to function. This is by design. However, it means that absolutely anyone can paste a known or guessed URL into their browser and download the file. This applies to both real users and search engine bots or AI crawlers. As a result, you can easily find your private media files being indexed in search engines 😱
Backend restriction is a method of dashboard organization rather than security.
In the next section, we'll talk about the second layer: preventing access to the actual file URLs.
Preventing direct frontend file access
There's a choice of four approaches for blocking public access to files in wp-content/uploads/. Which approach you can use depends first on whether your web server is Apache or NGINX.
Approach 1: Protect media files in Document Library Pro
If your documents are in a document library, Document Library Pro protects the files itself. You don't need a second plugin for the file layer. Tick 'Protect media files' under Documents → Settings → Access Control on the Advanced plan.
The files attached to your protected documents then move out of wp-content/uploads/ and into a private folder (uploads/dlp-protected-files) that the web server won't serve. Every download runs through the plugin instead. Document Library Pro checks the visitor against the document's own access rules before it sends the file.
The setting is off by default. On Apache, the plugin writes the server rules itself. If your site runs on Nginx, the settings page shows you a rule to add to your server configuration first, which your host can add for you. For the full setup, see protecting your document library.
Approach 2: .htaccess rules
Custom rules in wp-content/uploads/.htaccess intercept file requests at the web server level. The rules can block access outright or route requests through a PHP authentication script.
A basic rule might deny all direct access to PDF files. A more advanced setup rewrites requests through a PHP gatekeeper. That script checks login status or user role before serving the file.
This works well on Apache servers, because it works without adding a plugin.
These rules require maintenance across WordPress and server updates. A core update or migration can break custom .htaccess rules. And they only work on Apache. If your host runs NGINX (for example, Kinsta or WP Engine), .htaccess files are ignored entirely. You would need to configure NGINX server blocks directly, which requires server-level access that many managed hosts don't provide.
Approach 3: Plugin-based protection

The Prevent Direct Access (PDA) plugin rewrites file URLs through a PHP handler. The handler checks permissions before serving each file. Use it for the files attached to products, posts, pages or any other post type outside a document library.
PDA relies on .htaccess rewrites internally. NGINX users need separate server block configuration, but PDA still supports NGINX with the right setup.
The free version protects unlimited files and blocks search engine indexing. The paid version adds expiring links (limited by time and click count), folder-level protection, and WooCommerce integration.
Approach 4: Signed URLs via cloud storage
This approach moves files off wp-content/uploads/ entirely. Instead, they go to a private Amazon S3 bucket, DigitalOcean Spaces, or Google Cloud Storage.
It works like this: WordPress requests a signed URL from the cloud provider. That URL contains a cryptographic signature and expires after a set time. The WP Offload Media plugin from Delicious Brains handles this integration.
Signed URLs work natively via S3 pre-signed URLs without requiring CloudFront. However, CloudFront is an optional (and recommended) layer that adds CDN edge delivery and supports its own signed URL format.
This is the architecturally strongest option. It removes the public URL problem at the source. The tradeoff is more setup complexity and ongoing cloud hosting costs.
Stopping Google from indexing private WordPress files
Files that are never linked from any page can still appear in Google search results.
Search engines discover files through several vectors:
- External sites linking directly to the file URL.
- Sitemaps that include media attachment URLs.
- Google crawling known /wp-content/uploads/ paths.
The primary countermeasure is the X-Robots-Tag: noindex HTTP response header. Unlike a robots.txt disallow (which only prevents crawling), X-Robots-Tag prevents indexing even when Google finds the URL from another source.
How Document Library Pro handles this
The Document Library Pro plugin is a popular method for providing front-end access to media library files. This is much more convenient than finding files via the backend media library, and lets your users benefit from its searchable and filterable interface. The built-in access controls give you full access over who can access the files in the library - either globally, per category, or per file or document.

When you restrict access to documents, the plugin automatically adds noindex/nofollow meta tags and X-Robots-Tag headers to protected documents. It also removes those pages from sitemaps provided by SEO plugins like Yoast and AIOSEO.
This applies to document pages and protected categories managed by Document Library Pro. It does not cover raw file URLs in wp-content/uploads/. As Barn2's documentation notes, there is no absolute guarantee that protected content won't appear in search results.
For the files themselves (the PDF or image in /uploads/), tick 'Protect media files' under Documents → Settings → Access Control. Protected files move into a private folder that the web server won't serve, so there's no public URL left for a crawler to index.
A common mistake with robots.txt
Do not combine robots.txt Disallow with noindex meta tags on the same resource. If crawling is blocked, Google can't read the noindex tag. For file-level protection, use X-Robots-Tag (delivered in the HTTP response header before any HTML parsing). Or make sure the page is crawlable so the noindex meta tag can be seen.
Organizations handling HR records, legal agreements or client deliverables should treat search engine exposure as a compliance concern.
Setting up private file downloads for a membership or team site
Here is the full workflow: restrict documents behind a gate, capture leads or require login, protect file URLs, and handle link expiration.
Step 1: Control who sees which documents
Document Library Pro Advanced restricts access at the library, category, or individual document level. You can apply different rules at each level, which means one category might be public while another is locked to logged-in users only.
Access options include:
- User roles (for example, restrict HR documents to administrators only).
- Specific users (grant access to specific people).
- Passwords (share a password with a group without requiring accounts).
- Author-only visibility (each user sees only their own uploads).
Step 2: Gate downloads without requiring user accounts
Not every site wants to force visitors into creating an account. That adds friction and can reduce downloads significantly. Document Library Pro Advanced includes built-in lead capture as an alternative. Visitors enter their name and email before downloading. You collect contact information without managing user accounts.
For CRM or mailing list integration, connect via WP Fusion or Zapier. Captured leads sync automatically to your email marketing platform. Developer documentation covers both integration options.
Step 3: Protect the underlying file URLs
Document Library Pro controls which documents appear on the frontend. On its own, it does not block direct file URL access. Someone with the URL can still download the file, even if they can't see it in the document library.
For example, a user copies a download link and shares it in a Slack channel. Everyone with that link can download the file, whether they have a site account or not.
To close that off, tick 'Protect media files' under Documents → Settings → Access Control. Every download then runs through the same access rules as the document itself, so the Slack link only works for the people those rules allow.
Step 4: Handle the persistent-link problem
Static download links remain valid indefinitely once shared. For sites with lapsing memberships, this leaves files reachable after access ends. A former member can keep downloading files months after their access expires. They might also forward the link to others who never had an account.
Three solutions handle this:
- Document Library Pro file protectionThe plugin checks every download against the document's access rules as it happens, so a link stops working as soon as someone loses access.
- PDA Gold expiring linksSet click limits or time limits on each download URL. After the limit is reached, the link stops working.
- CloudFront signed URLsEach URL expires automatically based on your configured time window. This is the strongest option because the expiration is enforced at the CDN level, outside WordPress entirely.
For a document library, the first option needs no extra plugin. On other post types, PDA Gold's expiring links are the simpler path. Signed URLs via CloudFront suit high-security environments or sites already using AWS infrastructure.
Choosing the right WordPress media access control approach
| Use case | Backend tool | Frontend tool | Search engine exclusion | Link expiration |
|---|---|---|---|---|
| Multi-author blog (dashboard tidiness only) | Code snippet | None needed | N/A | N/A |
| Members/staff document site | Document Library Pro | Document Library Pro file protection | Auto-noindex for protected categories | Access checked on every download |
| Complex editorial role hierarchy | PublishPress Permissions | PDA Gold or .htaccess (Apache only) | Manual X-Robots-Tag configuration | PDA Gold or signed URLs |
| Paid digital products with expiring downloads | WooCommerce downloadable products | PDA Gold or S3 + CloudFront signed URLs | PDA Gold auto-blocking | Signed URLs (strongest) |
Check whether your host runs Apache or NGINX before choosing any .htaccess-based approach.
For document libraries, one plugin covers both sides. Document Library Pro handles access control, lead capture and search engine exclusion for the content layer. The 'Protect media files' setting locks the files themselves.
Outside a document library, you still need two tools: One for the backend layer and one for the frontend layer. Neither replaces the other. For products, posts and pages, pair a role-based backend restriction with Prevent Direct Access so both layers are covered.
FAQs about WordPress media access control
What are the best plugins for protecting media files and preventing hotlinking?
Document Library Pro Advanced covers both layers for a document library. It controls who can see and download documents from the frontend. Ticking 'Protect media files' also moves the files out of the public uploads folder, so the direct URLs stop working. For files attached to products, posts, pages or any other post type, PDA Gold handles file-URL protection and hotlink prevention. It blocks direct access to files in wp-content/uploads/ and prevents other sites from embedding your files.
How does PublishPress Permissions handle media file restrictions?
PublishPress Permissions offers six granular controls under Settings → Media Library:
- Toggle visibility of other users' unattached uploads.
- Allow viewing files attached to readable posts.
- Allow viewing files attached to editable posts.
- Allow editing files attached to editable posts.
- Prevent editing uploads on non-editable posts.
- Let users always edit their own attachments.
Admins retain full access regardless of settings. These are backend controls only. They do not affect direct file URL access.
Can I use custom code instead of a plugin?
Yes. The ajax_query_attachments_args filter is lightweight and avoids plugin overhead. It works well for simple multi-author sites that just need dashboard tidiness.
However, it only filters the admin AJAX grid view. REST API requests are not covered. Any block editor or headless setup that queries attachments via REST bypasses the filter entirely. The code also requires maintenance across WordPress updates, so you need someone comfortable with PHP to keep it working long-term.
For anything beyond basic author-based filtering, a plugin like PublishPress Permissions gives you more granular control without writing custom code.
Do WordPress media restriction plugins work on multisite?
It varies by plugin. PublishPress Permissions and PDA Gold offer multisite support in their premium tiers. Document Library Pro also works on multisite installations.
Multisite adds complexity because each sub-site has its own uploads directory and its own set of user roles. Permission cascades between network-level and site-level roles involve additional configuration. That falls outside this article's scope, but check each plugin's documentation for multisite-specific setup instructions.