7

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

Khalid Ahmada
  • 340
  • 5
  • 14

2 Answers2

12

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;
});
dotancohen
  • 30,064
  • 36
  • 138
  • 197
Chris
  • 54,599
  • 30
  • 149
  • 186
  • there is any cleaner way to do this ? – Janith Chinthana Mar 13 '17 at 06:47
  • 2
    ....to? To do what exactly? To remove the default api routes, you can't really beat the one liner above. It's using `actions` and `filters` which is a pretty clean and abstract way to tackle modifications to core functionality – Chris Mar 13 '17 at 09:12
  • I mean your second opinion, because when I remove the `rest_api_init` then it clears custom routes as well(as you describe also). Basically I need to disable the default routes and add custom routes. – Janith Chinthana Mar 13 '17 at 09:43
  • are we need to unset all the default routes one by one ? are we having any cleaner solution for that ? to be precise : I asked new question http://stackoverflow.com/questions/42757726/disable-default-routes-of-wp-rest-api – Janith Chinthana Mar 13 '17 at 09:45
2

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

remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );
Igor Jerosimić
  • 13,621
  • 6
  • 44
  • 53