Rest API plugin wordpress disable default routes

2019-04-27 03:05发布

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

标签: wordpress api
2条回答
聊天终结者
2楼-- · 2019-04-27 03:28

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;
});
查看更多
淡お忘
3楼-- · 2019-04-27 03:36

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

remove_action( 'rest_api_init', 'create_initial_rest_routes', 0 );
查看更多
登录 后发表回答