I'm trying to add some user meta information to the existing wp/v2/users
REST endpoint. However, it looks like additional authentication is required, i.e. I get this (output in comments):
error_log( is_user_logged_in() ); // true
register_rest_field( 'user',
'is_logged_in',
array(
'get_callback' => function () {
return is_user_logged_in(); // false
},
)
);
(so it doesn't seem possible to get actual user meta in the new field I registered).
Firstly: please correct me if I'm wrong on this point because it would make things much easier.
However, assuming additional authentication is required: I tried just setting _wpnonce to the nonce I got when logged in, and got back a 403. I simply want to be able to send any user who is logged in their own user data in JSON format. What is the correct way to do this?
'wp-api'
script and the nonce will be available viawpApiSettings.nonce
. If you want to do it on your own, usewp_create_nonce( 'wp_rest' )
to create the nonce.