• 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 6 replies - 1 through 6 (of 6 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

    Hello

    I think I have the same question as this but I’m not clear what the answer was.

    We are looking to add users to groups using the rest API. Is this possible?

    Users are being imported / created automatically from another system and we wish them to automatically be assigned to a group which is indicated from a field in the other system.

    My dev has said he is looking for the endpoints.

    Does my request make sense and if so do you know the solution please?

    Thanks

    Joel

    Plugin Author Kento

    (@proaktion)

    Hi Joel,

    Yes your request makes a lot of sense.

    Groups does not provide any REST API endpoints yet. But I think this is long overdue and we should add them the sooner the better.

    As a temporary solution, you could add your own endpoints and use Groups’ API to make the necessary modifications. This should eventually been made available via Groups itself, without the need to implement your own endpoints.

    Taking note as a high-priority feature to add.

    Thanks for all your input @csyecommerce and @joelkriteman

    Cheers

    Hi Kento

    Thank you for coming back to me on this and clarifying the situation.

    Do you have a timescale on when that feature might be added please?

    If I were willing to pay for some custom development is it something you could offer me within the next few weeks or as a plugin upgrade or something?

    Thanks very much

    Joel

    Plugin Author Kento

    (@proaktion)

    Hi Joel,

    I can’t give you an ETA for REST API endpoints yet as we’re planning its development and need to integrate it within our current schedule (which is packed). But we’re actively looking into it and have given it high priority.

    Please note that as per https://wordpress.org/support/guidelines/#do-not-offer-to-pay-for-help offering to pay for help goes against the forum guidelines. Not that we wouldn’t appreciate any contribution, but if you’d like to suggest anything please use https://www.itthinx.com/contact/ instead.

    Cheers

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Make user groups available in rest’ is closed to new replies.