User info not available for permission_callback?
-
I’m trying to create an endpoint for an admin dashboard widget, but it seems like the API loads before any user information loads.
current_user_can($anything)
andis_user_logged_in()
always return false, even if I’m logged in as an admin.Here’s the code in my plugin file:
add_action( 'rest_api_init', function() { register_rest_route('my_plugin', '/list', array( 'methods' => 'GET', 'callback' => 'myplug_rest_query', 'permission_callback' => function() { return current_user_can('edit_dashboard'); } //Always gives me a 403 ) ); } );
function myplug_rest_query(WP_REST_Request $request) { return current_user_can('edit_dashboard'); //Always false, when I remove the permission callback }
The add_action code is copied straight from the documentation?–?any idea why it’s not working?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘User info not available for permission_callback?’ is closed to new replies.