Return user meta value
-
Hi I have looked at you guidance at:
https://wp-oauth.com/docs/how-to/extending-endpoints/
$me_data = apply_filters(‘wo_me_resource_return’, $me_data, $token);
I need to return some of the additioal fields stored against the user in the user end point. I am able to add these field to the rest API suing below – kindly advise how ca i reflect this in the oauth end point being returned through json token.
register_meta( ‘user’, ‘meta_key_here’, [ ‘show_in_rest’ => true ] );
add_action( 'rest_api_init', 'adding_user_meta_rest' ); function adding_user_meta_rest() { register_rest_field( 'user', 'collapsed_widgets', array( 'get_callback' => 'user_meta_callback', 'update_callback' => null, 'schema' => null, ) ); } function user_meta_callback( $user, $field_name, $request) { return get_user_meta( $user[ 'id' ], $field_name, true ); }
- The topic ‘Return user meta value’ is closed to new replies.