Hello guy's Please help me i install REST API plugin WP and i adding some specific route and any things it's work fine as i wont. But I want to disable default route exemple : /wp-json/ /wp-json/wp/v2/posts
We have covered the basics of registering endpoints for the WordPress REST API. Routes are the URIs that our endpoints live at. Endpoints are a collection of callbacks, methods, args, and other options.
To strip out unwanted data or to transform data into a desired format we need to register a sanitize_callback for our arguments. Here is an example of how to use WordPress’s sanitize_text_field () for a sanitize callback: We have covered the basics of registering endpoints for the WordPress REST API. Routes are the URIs that our endpoints live at.
The first argument passed into register_rest_route () is the namespace, which provides us a way to group our routes. The second argument passed in is the resource path, or resource base. For our example, the resource we are retrieving is the “Hello World, this is the WordPress REST API” phrase. The third argument is an array of options.
The “core” endpoints utilize v2 to represent version 2 of the WordPress REST API. If you are writing a plugin, you can maintain backwards compatibility of your REST API endpoints by simply creating new endpoints and bumping up the version number you provide. This way both the original v1 and v2 endpoints can be accessed.
As of Wordpress 4.7 it seems to be the following (noting 99 instead of 0):
remove_action('rest_api_init', 'create_initial_rest_routes', 99);
However this will also remove any custom content type routes. So instead you may choose to use:
add_filter('rest_endpoints', function($endpoints) {
unset( $endpoints['/wp/v2/users'] );
// etc
return $endpoints;
});
You can use this on your plugin for remove all default route.
remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With