REST API Guard
The WordPress REST API is public by default and shares a good deal of information about your site with anyone who asks. REST API Guard makes it easy to decide who can see what. Out of the box, the plugin: Blocks anonymous access to the users endpoint ( /wp/v2/users ) so usernames aren’t exposed. Blo
The WordPress REST API is public by default and shares a good deal of information about your site with anyone who asks. REST API Guard makes it easy to decide who can see what.
Out of the box, the plugin:
- Blocks anonymous access to the users endpoint ( /wp/v2/users ) so usernames aren’t exposed.
- Blocks anonymous access to the REST API index ( / ) and namespace endpoints ( /wp/v2 ) so visitors can’t list your plugins and post types.
It can also:
- Block all anonymous access to the REST API.
- Allow anonymous access only to specific routes (allowlist), or block specific routes (denylist).
- Require anonymous requests to include a JSON Web Token (JWT).
- Let users authenticate with a JWT tied to their account.
- Generate, list, and revoke tokens from the settings page or WP-CLI.
Every option is available on the settings page (Settings → REST API Guard) and as a filter for configuring the plugin in code. A setting controlled by a filter is shown as read-only on the settings page.
Restrict access to user information
Anonymous access to /wp/v2/users is blocked by default. To allow it:
add_filter( 'rest_api_guard_allow_user_access', '__return_true' );
Restrict access to the index and namespace endpoints
Anonymous access to the index ( / ) and namespace ( /wp/v2 ) endpoints is blocked by default. To allow it:
add_filter( 'rest_api_guard_allow_index_access', '__return_true' ); add_filter( 'rest_api_guard_allow_namespace_access', '__return_true' );
Block all anonymous access
add_filter( 'rest_api_guard_prevent_anonymous_access', '__return_true' );
Allow anonymous access to specific routes (allowlist)
When an allowlist is set, anonymous requests to any route not on the list are denied. The allowlist takes priority over the denylist. Use * as a wildcard.
add_filter( 'rest_api_guard_anonymous_requests_allowlist', fn () => [ '/wp/v2/posts*', '/custom-namespace/v1/public/*', ] );