For all REST API routes, the rest_api_init action hook fires when preparing to serve a REST API request. The request URI ($_SERVER[‘REQUEST_URI’]) can be inspected with a regular expression to detect the root (e.g. wp-json) and the route (e.g. /wp/v2/posts) of the request. You can then decide what to return to the client (e.g. WP_Error, friendly message, Link Relation Names with alternative routes, etc).
Update
Found the code snippet below here. You could try adding a conditional statement with Regex on the Request_URI inside the rest_authentication_errors callback to see if it is effective for filtering requests.
<?php
add_filter( 'rest_authentication_errors', 'wp_snippet_disable_rest_api' );
function wp_snippet_disable_rest_api( $access ) {
return new WP_Error( 'rest_disabled', __('The WordPress REST API has been disabled.'), array( 'status' => rest_authorization_required_code()));
}
?>
Related Posts:
- Custom API plugin to execute 3rd party API to retrieve data
- Is it a good idea to restrict the REST API
- What security concerns should I have when setting FS_METHOD to “direct” in wp-config?
- I should enable automatic updates?
- Can some vulnerabilities in plugins be exploited even when the plugin is inactive?
- Security and Must Use Plugins
- Is Timthumb still broken? What security measures should be taken?
- Prevent direct access to WordPress plugin assets?
- REST route from a plugin not working if WordPress is installed in a subdirectory
- Plugin retrieving results even after uninstallation
- Is it safe to use admin-ajax.php in the frontend?
- Getting a Page via its post-name using WP REST API v2 and Postman
- How to protect WordPress from security scanner [closed]
- WordPress REST API Plugin Development – Add Custom Endpoint
- Specific way to allow WordPress users to view their current password? And edit it?
- Too many login attempts
- Is there any pre-existing plugin to track and block IPs with suspicious activity on my site?
- How to prevent plugins from sniffing/stealing other plugins’ options?
- Website show Google Ads when we have no Google Ads linked to our website
- How to create WordPress custom end point with multiple parameters?
- How to execute plugin and theme updates from a web hook / endpoint?
- Vulnerability Concern From the Plugin or From Not Updating the Plugin?
- How do I make reusable content blocks for header and footer when using WordPress headless with another front-end?
- REST API can’t get the response manually
- How to integrate together a website currently hosted WordPress.com and a custom web application currently hosted on Azure?
- How to deal with Slow HTTP POST (slowloris) vulnerability
- Running multiple security plugins
- how do I secure my WP website from hackers? [closed]
- Chrome Dev Tools console says every page in my blog has link to http://maps.google.com [closed]
- WP Rest API and json_decode()
- Webservice credential storage [duplicate]
- WordPress /users/me endpoint request forbidden
- Regarding plugin security
- How do I determine if the user who registered is not spam?
- If I use an alternative login (e.g. CAS or other SSO) plugin, is my site protected from the recent brute force login attempts?
- Is this plugin safe to run?
- Is the Block Bad Queries Plugin Still Relevant?
- WP Insert Post If user refreshes override new post
- 404 errors when updating options in admin dashboard
- Website Captcha Error: The reCAPTCHA wasn’t entered correctly
- Hide plugins and theme from public
- Seperate plugin and theme files
- WordPress search shows protected content
- Change Dashboard URL from wp-admin to wp-admin/index.php
- WordPress Media Library Folders + Custom Linux Server Hosting
- Security of a WordPress Plugin
- Can I disable xml-rpc by setting it to false?
- wc_get_template_part doesnt display the content [duplicate]
- WordPress REST API: Query media files attached to a custom post type
- How can I disable new plugin and theme install, but allow updates?
- Help to Create a Simple Plugin to make a post
- I’m receiving the following error using the below code: Uncaught Error: Cannot use object of type WP_REST_Response as array
- Validating ajax search
- How to send SMS notification to customer after click on submit?
- Content-Security-Policy implementation with WordPress W3Total Cache plugin installed
- How to send the featured image of a post to an API?
- Escape commas in REST API
- WordPress disable direct access of files in WordPress installation path
- How to authenticate via API to allow writes/updates
- Do i need to use a plugin for third party api integration?
- Asking help regarding potential malware
- Adding Custom Endpoint in WordPress Rest API
- One WooCommerce Store to multi distributor sites
- prevent anonymous access to WordPress site (non-admin site)
- Custom REST API POST Endpoint Not Working, 404 Error
- Getting all woocommerce products from REST API call in plugin
- is it possible to fetch data from a remote api while admin is writing a new post?
- add tags to wordpress post using REST API
- WordPress output data to another website and pull data
- Hide response returned from WordPress REST API call
- How much PHP and MySQL or MariaDB knowledge should I know to start writing WordPress themes and plug-ins and whatever else a beginner can edit?
- How achive serving multiple concurrent Ajax / Rest calls in plugin?
- Bing/msn bots is heavily requesting random of my website
- CRUD from WordPress to Business Central 365 through OData REST API
- WP Rest Api GET method restriction on route, but POST method also works
- “Fire Secure” menu item
- Showing how many times is plugin activated or deactivated
- Modifying server’s response to API endpoint
- Can’t access 3rd party API, code works on local server but not on wordpress
- Is it possible to custom set query for a WordPress REST API response?
- How can I add a permissions callback to the REST API index pages?
- Securing a plugin pop-up window
- How to get data from a private API and add it to wordpress pages
- https rewrite not working for All in one security Brute force > rename login url
- Fetching users data from REST API
- Consume legacy rest api dependent upon WP API plugin
- wp rest api (v2) filter not working (404 error – rest_no_route)
- WordPress PHP error getting posts from another wordpress blog
- custom REST endpoint not passing body of POST request to callback
- Fetching WP.me shortlinks for posts using WP Rest API
- Upload image to wordpress using ionic/cordova with WP REST API V2
- WP Rest API v2.0 user profile update issue
- Redux framework somehow added to my site, can’t locate in plugins
- Sending post data over REST API, how to parse shortcodes in post_content?
- How to do rest APi with wordpress
- Being hacked. Is there a list of WordPress security holes I can check against?
- wp_verify_nonce fails always
- How can i see/log all requests coming from a registration form (not from the UI)?
- Write mysql credentials in plugin
- Site is continuously accessing by several IPs