• Resolved Cal

    (@caleblai)


    Hi,

    I would like to ask what is the hook and steps to switch a user’s role when a specific page is loaded.
    EG. “Subscriber” -> “Premium User”

    I have tried um_set_user_role and set_role but it wasn’t working.

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @caleblai

    Have you tried using the action hook instead?

    Here’s the action hook that gets triggered on role changed:
    + um_after_user_role_is_updated
    $user_id
    $role

    Regards,

    Thread Starter Cal

    (@caleblai)

    Hi Champ,

    My issue is trying to implement a trigger to change user role itself when they reached a page, not trigger a function/action after role change occurred.

    Thank you.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @caleblai

    You can try this code snippet to change a user role:

    <?php
    $user_id = 123;
    $user_role = 'subscriber'; // slug
    UM()->roles()->set_role( $user_id, $user_role );
    ?>

    Regards,

    Thread Starter Cal

    (@caleblai)

    Hi Champ,

    It is unfortunately still not working for me. Is there any alternative methods?

    Thanks.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @caleblai

    Have you tried checking the role slug that you’re assigning to the user?

    It should match the slug. It could be um_subscriber or subscriber

    Regards,

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @caleblai

    This thread has been inactive for a while so we’re going to go ahead and mark it Resolved.

    Please feel free to re-open this thread if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hook for user role change on page load’ is closed to new replies.