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
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;
});
-
-
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
andfilters
which is a pretty clean and abstract way to tackle modifications to core functionality– ChrisMar 13, 2017 at 9: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. Mar 13, 2017 at 9: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 stackoverflow.com/questions/42757726/… Mar 13, 2017 at 9:45
You can use this on your plugin for remove all default route.
remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );