Make user groups available in rest
-
Hi,
I am trying to make a users group selection available in rest.. the field in the users profile which says which groups it belongs too.. not having much joy.. any help would be appreciated …
//user groups in rest
add_action(‘rest_api_init’, function() {
register_rest_field( ‘user’, ‘group_ids’, [
‘get_callback’ => ‘get_user_group_ids’,
‘update_callback’ => ‘update_user_group_ids’,
‘schema’ => [
‘type’ => ‘array’,
‘description’ => ‘Groups.’,
‘context’ => [ ‘view’, ‘edit’ ],
],
]);
});function get_user_group_ids( $user, $field_name, $request ) {
return get_user_meta( $user[ ‘id’ ], $field_name, true );
}function update_user_group_ids( $user, $meta_value ) {
update_user_meta( $user[ ‘id’ ], ‘group_ids’, $meta_value );
}
The topic ‘Make user groups available in rest’ is closed to new replies.