I'm currently building a small REST API with the WP-REST v2 plugin. Everything is working perfectly fine, however, in the documentation there are permission callbacks, which restrict access to certain user groups (exactly what I'm trying to do). The syntax provided is as follows:
'permission_callback' => function () {
return current_user_can( 'edit_others_posts' );
}
The issue I'm having is that at the point of execution the current user is empty, despite being logged in and authenticated as an administrative account (session tokens exist in the cookies before, during and after the request). I figured that it may be because the route endpoint returns a page with nothing but the response text, so I tried calling the API from the index.php and wp_get_current_user();
returns an empty user object and therefore current_user_can('condition')
will never succeed.
Thanks for any help!