Support » Plugin: Groups » Make user groups available in rest

  • Resolved CSY

    (@csyecommerce)


    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 );
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Kento

    (@proaktion)

    Hi,

    You can see an example of how to obtain the groups a user belongs to here: http://docs.itthinx.com/document/groups/api/examples/

    Cheers

    Thread Starter CSY

    (@csyecommerce)

    Hi Kento,

    I would like to be able to add and remove users from a group via the wordpress Rest API
    Its unclear what the field id is being used in the users profile so to expose this to rest.. so i can edit and manage this fields data via the user_meta in the rest API

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.