在里面WP REST API v2 使用permission_callback 在中找到Adding Custom Endpoints Docs.
<?php
add_action( \'rest_api_init\', function () {
register_rest_route( \'myplugin/v2\', \'/author/(?P<id>\\d+)\', array(
\'methods\' => \'GET\',
\'callback\' => \'my_awesome_func\',
\'args\' => array(
\'id\' => array(
\'validate_callback\' => \'is_numeric\'
),
),
\'permission_callback\' => function (WP_REST_Request $request) {
if ( current_user_can( \'edit_others_posts\' ) ) {
return true;
}
else {
return false;
}
}
) );
} );