Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rest API plugin wordpress disable default routes

Tags:

wordpress

api

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

like image 904
Khalid Ahmada Avatar asked Jun 14 '16 15:06

Khalid Ahmada


People also ask

What are routes and endpoints for the WordPress REST API?

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.

How do I sanitize arguments in the WordPress REST API?

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.

How do I use Register_rest_route () in WordPress?

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.

What is V1 and V2 in WordPress REST API?

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.


2 Answers

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;
});
like image 199
Chris Avatar answered Nov 15 '22 14:11

Chris


You can use this on your plugin for remove all default route.

remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );
like image 22
Mahfuz-ur Rahman Avatar answered Nov 15 '22 14:11

Mahfuz-ur Rahman