Limit Public WordPress Author Data in the REST API
Test whether /wp-json/wp/v2/users exposes public author profiles, then restrict that exact route with a reversible must-use plugin while keeping authenticated requests working.
The short answer
WordPress can expose public author display names, profile links and slugs through /wp-json/wp/v2/users. The default public response does not include the login username; that field belongs to the authenticated edit context. If your site does not need a public author endpoint, use a small must-use plugin that returns 401 only for /wp/v2/users and its child routes, then test anonymous requests, wp-admin, the editor and public integrations.

Reading options
On this page
- What the WordPress REST API actually is
- Before you start
- Find out what your site shares today
- Choose how much to restrict
- Option A: restrict only the users route
- Option B: require login for every REST request
- Install the file your way
- How to check it worked
- Troubleshooting
- Rollback in one move
- A worked example (made-up scenario)
- Pro tips, security notes and when to get help
- The one message worth forwarding
- Reader questions
- Sources & further reading
Before you start
You need administrator access, a tested files-and-database backup, file access through cPanel/SFTP/SSH, an anonymous curl test, and a list of public forms, headless front ends or apps that may use the REST API. Test on staging first when available.
Yes, you can stop anonymous visitors reading your public author list through the WordPress REST API without switching the whole API off. One small must-use plugin file answers logged-out requests to the users route with a 401, while authenticated WordPress requests can keep working. Undoing it means moving that one file out of the must-use plugins folder.
On many WordPress sites, /wp-json/wp/v2/users returns public author display names, profile links and slugs. The default public response does not include the account's username; WordPress exposes that field only in the authenticated edit context. A public slug can still help account enumeration when it happens to match a login name, so test your own site and restrict the route only when your publishing model does not need a public author endpoint. By the end of this guide you will be able to test the route, choose how much to restrict, install the change through cPanel, SFTP or WP-CLI, prove it worked, and know what it might break.
What the WordPress REST API actually is
The REST API is a set of web addresses under /wp-json/ that return your content as JSON (plain structured text that programs read easily) instead of as a web page. Posts, pages, media and users each have their own address, called a route.
Think of it as the service hatch at the back of a restaurant. Diners use the front door, which is your theme. Staff and suppliers use the hatch. Bricking it up would stop the kitchen, but you would not pin the staff rota to the outside of it either.
WordPress depends on that hatch. The official REST API FAQ is blunt: "You should not disable the REST API; doing so will break WordPress Admin functionality that depends on the API being active." So the job is to decide who gets served at the hatch.
The Users reference says the default context is view, and in that context a reply can include id, name, url, description, link, slug, avatar_urls and meta. Fields such as username, email, roles and capabilities are listed for the authenticated edit context only. The core users controller allows the collection to be read in view context, while plugins and custom code can change the response, so test your own site instead of assuming that a returned slug is the login username.
Before you start
Tick these off before you touch any file.
- An administrator account, so you can check wp-admin afterwards.
- File access through cPanel > Files > File Manager, an SFTP client such as FileZilla, or SSH with WP-CLI.
- A fresh, tested backup of files and database. If you lack one, follow how to back up your site in cPanel with an offsite copy and a test restore first.
- A staging copy of the site if your host offers one.
- A terminal on your own computer with
curlinstalled. - About 30 minutes, including time to test forms and the editor.
Heads up: back up before you create, edit or delete any file here. A must-use plugin runs on every request, so one typo can take the whole site down until the file is removed.
Find out what your site shares today
Step 1: Test what anonymous visitors can see
Run this from a terminal, not from a browser where you are logged in. curl sends no WordPress cookies, so it sees what a stranger sees, and the -i option, which the curl manual describes as "Show response headers in the output", prints the status line above the body.
This command asks your site for its user list as an anonymous visitor.
curl -i https://example.com/wp-json/wp/v2/usersIf the list is public, the first line shows 200 and the body is a JSON array. A trimmed example looks like this.
HTTP/2 200
content-type: application/json; charset=UTF-8
[{"id":1,"name":"Sam Example","url":"","description":"","link":"https://example.com/author/sam/","slug":"sam","avatar_urls":{...}}]If you see 401 or 403 instead, something already restricts this route. Find out what before adding a second rule on top.
Quick tip: the public slug is not automatically the login username. If an administrator confirms that a slug and login name are identical, the public route does reveal one credential identifier; changing that login safely is a separate account-migration task.
Step 2: Test the fallback address
Sites without pretty permalinks serve the API through a query string. The Routes and Endpoints page shows the pattern as ?rest_route= followed by the route.
This command requests the same users route through that query-string address.
curl -i "https://example.com/?rest_route=/wp/v2/users"You should get the same status as Step 1. Note both results for later.
Step 3: Find which features depend on the REST API
Before restricting anything, find out who else uses the hatch.
- Open your site in a private window, so you are logged out.
- Open Chrome DevTools with Control+Shift+J, or Command+Option+J on a Mac, and click the Network tab.
- Type
wp-jsoninto the Filter box. - Reload, then use the site like a visitor: submit a form, search, open any booking or map widget.
- Read the Status column. Every row is a public feature calling the REST API while logged out.
The Chrome DevTools Network reference explains the Filter box and Status column. Also list outside services that read your site: an uptime monitor, a mobile app, a headless front end (a separate site that pulls WordPress content over the API). Ask whether each one calls /wp-json/ and whether it logs in.
Why this matters: a login-only rule can break public form plugins, headless front ends and monitoring tools if they call the API while logged out. Ten minutes here tells you which camp you are in before your visitors do.
Choose how much to restrict
Option A, users route only. Logged-out requests to anything under /wp/v2/users get a 401, and every other route stays public. Forms and headless front ends are left alone. Start here if you are unsure.
Option B, login for everything. This is the official FAQ code. Every logged-out REST request gets a 401. It suits intranets, fully private membership sites, or sites where Step 3 found no public REST traffic.
Why wp-admin keeps working
Both options check is_user_logged_in(). When you are logged in, wp-admin sends your login cookie plus a nonce (a short-lived token proving the request came from your own admin screen) with each API call.
The Authentication handbook page calls cookie authentication "the standard authentication method included with WordPress". The nonce uses the action wp_rest and travels as a _wpnonce parameter or in the X-WP-Nonce header. If no nonce is provided, "the API will set the current user to 0, turning the request into an unauthenticated request, even if you’re logged into WordPress."
So your admin screens pass, because they send the nonce. A stranger, or another site riding on a cookie alone, counts as logged out.
Option A: restrict only the users route
Step 4: Understand the hook
Option A uses the rest_pre_dispatch filter. Its hook reference allows "hijacking the request before dispatching by returning a non-empty" value, with null meaning "to not hijack the request". The request's get_route() method returns the route that was asked for.
WordPress runs its authentication checks before it dispatches, so is_user_logged_in() already reflects the nonce rules above. The code lowercases the route because WordPress matches routes case-insensitively, visible as the @i flag in WP_REST_Server::match_request_to_handler().
Step 5: Create the must-use plugin file
The Must Use Plugins page says these files live in wp-content/mu-plugins, load before normal plugins, and "cannot be disabled from wp-admin". WordPress only loads PHP files sitting directly in that folder.
Name the file rest-hide-users.php. This complete file returns a 401 to logged-out requests for any users route and lets everything else through.
<?php
/*
* Plugin Name: REST API Hide Users
* Description: Logged-out visitors get a 401 from the wp/v2/users routes. Delete this file to undo.
*/
add_filter( 'rest_pre_dispatch', function( $result, $server, $request ) {
// Another plugin already answered this request, so step aside.
if ( null !== $result ) {
return $result;
}
// WordPress matches routes without caring about letter case.
$route = strtolower( $request->get_route() );
if ( preg_match( '#^/wp/v2/users(?:/|$)#i', $route ) && ! is_user_logged_in() ) {
return new WP_Error(
'rest_not_logged_in',
__( 'You are not currently logged in.' ),
array( 'status' => 401 )
);
}
return $result;
}, 10, 3 );The regular expression matches only /wp/v2/users and its child routes, avoiding accidental matches such as /wp/v2/usersomething. The 10, 3 tells WordPress to pass all three arguments. The error code and message match the official FAQ, so tools see a familiar reply.
Quick tip: <?php must be the very first thing in the file, with no blank line or space before it.
Option B: require login for every REST request
Step 6: Use the official FAQ code exactly
This code comes from the REST API FAQ section "Require Authentication for All Requests". At the time of writing (17 November 2026), that page was last updated on 14 October 2026.
The hook reference for this filter explains the logic: "null should be returned to indicate another authentication method should check instead," and a callback "can return true to indicate that the authentication method was used, and it succeeded."
Name this file rest-require-login.php. Here is the FAQ code copied exactly, with only a plugin header added so it shows a name in wp-admin.
<?php
/*
* Plugin Name: REST API Require Login
* Description: Blocks all anonymous REST API requests. Delete this file to undo.
*/
add_filter( 'rest_authentication_errors', function( $result ) {
// If a previous authentication check was applied,
// pass that result along without modification.
if ( true === $result || is_wp_error( $result ) ) {
return $result;
}
// No authentication has been performed yet.
// Return an error if user is not logged in.
if ( ! is_user_logged_in() ) {
return new WP_Error(
'rest_not_logged_in',
__( 'You are not currently logged in.' ),
array( 'status' => 401 )
);
}
// Our custom authentication check should have no effect
// on logged-in requests
return $result;
});Heads up: install Option A or Option B, never both. Two files make troubleshooting much harder.
Install the file your way
Variant 1: cPanel File Manager
- Open cPanel > Files > File Manager, then open the
public_htmlfolder and itswp-contentfolder. If WordPress lives elsewhere, open that site's folder instead. - If
mu-pluginsis missing, click + Folder, typemu-pluginsin New Folder Name: and click Create New Folder. - Open
mu-plugins, click + File, type the file name in New File Name: and click Create New File. - Select the file and click Edit. If an encoding dialog appears, confirm it and click Edit to continue.
- Paste the full code, save, and close the editor.
The cPanel File Manager documentation covers each button.
Variant 2: SFTP with FileZilla
- Create the file locally in a code editor, not a word processor, so no smart quotes sneak in.
- In FileZilla's Quickconnect bar, enter
sftp://example.com, your username, password and port 22, then connect. The FileZilla usage guide shows the bar. - In the remote pane, open your site folder, then
wp-content, and createmu-pluginsif needed. - Drag the file from the local pane into
mu-plugins.
Make sure it sits directly inside mu-plugins, not in a folder within it. That detail causes most "it does nothing" reports.
Variant 3: SSH and WP-CLI
This command, taken from the wp eval documentation, prints your content folder path when run from the WordPress directory.
wp eval 'echo WP_CONTENT_DIR;'You will see something like /home/example/public_html/wp-content. This command creates mu-plugins inside it, and does nothing if it already exists.
mkdir -p /home/example/public_html/wp-content/mu-pluginsUpload or create the file there, then run PHP's syntax check, which the PHP command line manual describes as "Syntax check but do not execute the given PHP code."
php -l /home/example/public_html/wp-content/mu-plugins/rest-hide-users.phpYou want No syntax errors detected and the file name. If you see Errors parsing, fix the file before loading any page.
This command, from the wp plugin list documentation, lists only must-use plugins.
wp plugin list --status=must-useYour file should appear with the status must-use. No Apache or Nginx change is needed for the plugin itself.
How to check it worked
Step 7: Repeat the anonymous tests
Run the Step 1 command again from your terminal to request the user list as a stranger.
curl -i https://example.com/wp-json/wp/v2/usersYou should now see a 401 with the error body WordPress uses for REST errors.
HTTP/2 401
content-type: application/json; charset=UTF-8
{"code":"rest_not_logged_in","message":"You are not currently logged in.","data":{"status":401}}Repeat Step 2 with ?rest_route=/wp/v2/users and try /wp-json/wp/v2/users/1. Both should return 401.
With Option A, confirm the rest of the API is still public. This command fetches posts as a stranger and should still return 200.
curl -i https://example.com/wp-json/wp/v2/postsWith Option B, that request returns 401 too, which is the intent.
Step 8: Check wp-admin
- Log in to wp-admin in a normal window.
- Open Plugins and look for the Must-Use section. Your file should be listed by its header name.
- Open Users and confirm the account list loads.
- Open Tools > Site Health and check the Status tab for new critical issues.
Step 9: Check the block editor
The editor's packages include @wordpress/api-fetch, which its package docs describe as a "Utility to make WordPress REST API requests". That makes the editor a good real-world test.
- Open Posts, start a new post, and type a title and a paragraph.
- Change the author, category and tags in the post settings.
- Insert an image from the media library.
- Save the draft, reload, and confirm everything is still there.
Then repeat the Step 3 Network session in a private window and confirm your public features still return 200.
Troubleshooting
Problem: a public form stops working
Symptom: visitors click submit and nothing happens or a generic error appears. DevTools shows 401 beside a wp-json request.
Cause: the form submits through the REST API and Option B blocks logged-out visitors.
Fix: delete rest-require-login.php, install rest-hide-users.php from Option A, and retest in a private window.
Problem: a monitoring tool or app reports 401
Symptom: an uptime monitor, mobile app or headless front end starts failing with "You are not currently logged in."
Cause: it reads the API anonymously, and your rule now refuses that.
Fix: if it only needs public content, use Option A. Otherwise give it an Application Password for a low-privilege account. The Authentication handbook says these shipped in WordPress 5.6, are generated from Users > Edit User, and are sent over https with Basic Auth.
Problem: Application Password requests still get 401
Symptom: the tool sends correct credentials and is still refused.
Cause: the official FAQ notes that in CGI environments the web server may strip the Authorization header.
Fix: for Apache, the FAQ gives this block for a configuration file or .htaccess.
<IfModule mod_setenvif>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
</IfModule>For Nginx, the FAQ gives this line for the server's fastcgi section. On shared hosting, ask your host to add it.
fastcgi_pass_header Authorization;Problem: the file does nothing
Symptom: curl still returns 200 with your users, and no Must-Use section appears under Plugins.
Cause: the file is in a subfolder, lacks the .php extension, or WPMU_PLUGIN_DIR in wp-config.php points the folder somewhere else.
Fix: move the file directly into mu-plugins, check the extension, and search wp-config.php for WPMU_PLUGIN_DIR. Clear any page or CDN cache, since a cached 200 can hide the change.
Problem: the site shows an error after saving
Symptom: every page, wp-admin included, shows an error message or a blank page.
Cause: a syntax error, often a missing semicolon, a smart quote, or text before <?php. WP-CLI will not rescue you, because its docs note that "mu-plugins are still loaded" even with --skip-plugins.
Fix: remove the file. In File Manager, select it, click Delete, then Confirm; it moves to Trash, where it no longer runs. Over SSH, this command removes it after asking you to confirm.
rm -i /home/example/public_html/wp-content/mu-plugins/rest-hide-users.phpThe site should recover on the next reload. Fix the file locally, run php -l, and upload again.
Rollback in one move
Delete the file from wp-content/mu-plugins by any method above. To park it instead, rename it so it no longer ends in .php, which this command does in place.
mv /home/example/public_html/wp-content/mu-plugins/rest-hide-users.php /home/example/public_html/wp-content/mu-plugins/rest-hide-users.php.offRun the Step 1 test again to confirm the list is back.
A worked example (made-up scenario)
This is invented to show the decision. A small bakery site has three authors and a catering form. Step 1 shows all three, with slugs matching their login names.
Step 3 shows the form posting to wp-json while logged out, which rules out Option B. The owner installs Option A through cPanel and gets 401 on both users tests and 200 on posts, and the form still sends. Total time: about 20 minutes.
Pro tips, security notes and when to get help
Treat this as one layer. Your theme may still print author names and archive links on every post. Strong unique passwords and two-factor login matter more than hiding the list.
Must-use plugins get no update notices. The official page says they "will not appear in update notifications," so review the file after major upgrades. If you use auto-updates, pair them with a safe backup plan for WordPress auto-updates.
Name files clearly. Anyone opening mu-plugins in two years should know what rest-hide-users.php does without reading it.
Password guessing hits servers too. If you run a VPS, see how to protect SSH with Fail2ban.
Ask your host or a developer when you have no file access, the site is a multisite network, a headless front end or app depends on the API, the Authorization header fix needs server access you lack, or staging and production behave differently.
The one message worth forwarding
Copy this to your developer or host and change the address.
Hi, please add a must-use plugin to example.com that returns 401 to logged-out requests for /wp-json/wp/v2/users and /?rest_route=/wp/v2/users, using the rest_pre_dispatch filter and is_user_logged_in(), without disabling the rest of the REST API. Please take a backup first and check which public features call wp-json while logged out. Afterwards, confirm with curl -i that the users route returns 401, /wp-json/wp/v2/posts still returns 200, and the block editor still saves drafts. Rollback is deleting the one file in wp-content/mu-plugins.The takeaway: test the users route from outside, close just that route with one must-use file, and keep the rest of the API open unless nothing public depends on it.
Reader questions
How many users does the endpoint return in one request?
The Users reference gives per_page a default of 10 and page a default of 1. Anyone collecting names simply pages through the results until they run out.
Does the REST API ever return a user's password?
No. The Users reference describes the password field as "never included" in responses.
In what order do several must-use plugins load?
The Must Use Plugins page says PHP loads them in alphabetical order, before normal plugins. Name files with that in mind if one must run before another.
Do activation hooks run for a must-use plugin?
No. The official Must Use Plugins page says activation hooks are not executed for plugins placed in that folder, so test any plugin that relies on them before moving it there.
Why does WordPress not block other websites from reading the REST API?
The REST API FAQ explains that WordPress uses nonces for CSRF protection instead of tightening CORS, and does not verify the Origin header. Public endpoints can therefore be read from any site, which is why restricting sensitive routes matters.
Which WordPress version added the rest_authentication_errors filter?
The code reference lists it as introduced in WordPress 4.4.0, so any current site supports the official FAQ code.
Was this guide helpful?
Help us make the next update better.
Sources & further reading
- WordPress REST API Handbook: Users reference
- WordPress REST API Handbook: Frequently Asked Questions
- WordPress REST API Handbook: Authentication
- Code Reference: rest_authentication_errors hook
- Code Reference: rest_pre_dispatch hook
- Advanced Administration: Must Use Plugins
- WordPress REST API Handbook: Routes and Endpoints
- WP-CLI: wp plugin list
- cPanel Docs: File Manager
- Chrome DevTools: Network features reference
What changed
Corrected the article's central claim: WordPress public view context exposes author profile data and slugs, not the username field by default. Tightened the code to match only /wp/v2/users and child routes, clarified conditional account-enumeration risk, and added original accessible media.
Originally published . About our editorial updates.



