Discover, trust, install: FAIR 1.0 is here
Disable WP REST API
Version: 2.6.5
Description
This plugin does one thing: disables the WP REST API for visitors who are not logged into WordPress. No configuration required.
This plugin works with only 22 short lines of code (less than 2KB). So it is super lightweight, fast, and effective.
Features
- Disable REST/JSON for visitors (not logged in)
- Disables REST header in HTTP response for all users
- Disables REST links in HTML head for all users
- 100% plug-and-play, set-it-and-forget solution
The fast, simple way to prevent abuse of your site’s REST/JSON API
How does it work? That depends on which version of WordPress you are using..
WordPress v4.7 and beyond
For WordPress 4.7 and better, this plugin completely disables the WP REST API unless the user is logged into WordPress.
- For logged-in users, WP REST API works normally
- For logged-out users, WP REST API is disabled
What happens if logged-out visitor makes a JSON/REST request? They will get only a simple message:
“rest_login_required: REST API restricted to authenticated users.”
This message may customized via the filter hook, disable_wp_rest_api_error
. Check out this post for an example of how to do it.
Older versions of WordPress
For WordPress versions less than 4.7, this plugin simply disables all REST API functionality for all users.
More information available below in the FAQs section.
Privacy
This plugin does not collect or store any user data. It does not set any cookies, and it does not connect to any third-party locations. Thus, this plugin does not affect user privacy in any way. If anything it improves user privacy, as it protects potentially sensitive information from being displayed/accessed via REST API.
Disable WP REST API is developed and maintained by Jeff Starr, 15-year WordPress developer and book author.
Support development of this plugin
I develop and maintain this free plugin with love for the WordPress community. To show support, you can make a donation or purchase one of my books:
- The Tao of WordPress
- Digging into WordPress
- .htaccess made easy
- WordPress Themes In Depth
- Wizard’s SQL Recipes for WordPress
And/or purchase one of my premium WordPress plugins:
- BBQ Pro – Super fast WordPress firewall
- Blackhole Pro – Automatically block bad bots
- Banhammer Pro – Monitor traffic and ban the bad guys
- GA Google Analytics Pro – Connect WordPress to Google Analytics
- Head Meta Pro – Ultimate Meta Tags for WordPress
- Simple Ajax Chat Pro – Unlimited chat rooms
- USP Pro – Unlimited front-end forms
Links, tweets and likes also appreciated. Thank you! 🙂
Installation
How to Install
- Upload the plugin to your blog and activate
- Done! No further configuration is required.
More info on installing WP plugins
Testing
To test that the plugin is working, log out of WordPress and then request https://example.com/wp-json/
in a browser. See FAQs for more infos.
Like the plugin?
If you like Disable WP REST API, please take a moment to give a 5-star rating. It helps to keep development and support going strong. Thank you!
Faq
When the user is logged in to WordPress, the normal REST API data will be displayed. When the user is not logged in, this is the default message:
{"code":"rest_login_required","message":"REST API restricted to authenticated users.","data":{"status":401}}
Technically this plugin only disables REST API for visitors who are not logged into WordPress. With that in mind, here are some good reasons why someone would want to disable REST API for non-logged users:
- The REST API may not be needed for non-logged users
- Disabling the REST API conserves server resources
- Disabling the REST API minimizes potential attack vectors
- Disabling the REST API prevents content scraping and plagiarism
I’m sure there are other valid reasons, but you get the idea 🙂
Yep, actually there are two other “Disable REST” plugins:
The first of those plugins is awesome and provides a LOT more features and functionality than is required to simply disable REST. And the second plugin was shut down due to lack of use. I wrote my disable-REST plugin because I wanted something super lightweight, fast, and effective. If you are looking for more options and features, then check out the first of those two listed alternatives.
Testing is easy:
- Log out of WordPress
- Using a browser, request
https://example.com/wp-json/
If you see the following message, REST is disabled:
“rest_login_required: REST API restricted to authenticated users.”
Then if you log back in and make a new request for https://example.com/wp-json/
, you will see that REST is working normally.
Yes, if the REST endpoints are registered with the WP REST API.
Yes. It works the same regardless of which editor (Classic or Block) you are using.
By default the plugin displays a message for unauthenticated users: “REST API restricted to authenticated users.” To customize that message to whatever you want, add the following code via functions.php or simple custom plugin:
function disable_wp_rest_api_error_custom($message) {
return 'Customize your message here.'; // change this to whatever you want
}
add_filter('disable_wp_rest_api_error', 'disable_wp_rest_api_error_custom');
As explained in this thread, the plugin Contact Form 7 requires REST API access in order for the contact form to work. To allow for this, follow this guide.
Send any questions or feedback via my contact form
Reviews
Very simple and effective
By terrymason on November 19, 2024
just activate the plugin and it works.
I like it!
By wildstar2022 on May 6, 2024
I've tried many different solutions using functions.php because I did not want to install yet another plugin.
I'm glad I found this one though. It's simple, lightweight, maintains privacy, and functions with the latest version of WordPress.
Thanks Jeff!
Good Stuff - but make many other things more complicate
By metaeditor on March 29, 2023
In generel a Good security concept .
But at the other end many plugin developer use the Rest API
Could be done much easier with a 5 3 line htaccess rule to block only ^.*wp-json/wp/v2/(users
But anyway a good solution if you have a simpel installation.
Blocks Contact Form 7 forms sending
By Hendrik57 on February 12, 2023
As the title says: Blocks Contact Form 7 forms sending after install and activate.
Super simple plugin
By tinaponting (ponting) on December 29, 2024
Great plugin, takes nopower from the blog:)
Works best
By 7 Mysteries (1greatness) on September 26, 2022
dead simple and efficient, but be aware
By Eduard "RwkY" Doloc (rwky) on July 28, 2022
Good
By proektion on July 7, 2022
You Deserve it 🙂
By mahfoof (mahfoofgmail) on February 1, 2022
Security can never be too much!
By Tunn (iuriem) on January 18, 2022
Changelog
If you like Disable WP REST API, please take a moment to give a 5-star rating. It helps to keep development and support going strong. Thank you!
2.6.5
- Tests on WordPress 6.8
Full changelog @ https://plugin-planet.com/wp/changelog/disable-wp-rest-api.txt