• I’m using this code, but it isn’t working:

    
    add_action("user_register", "onRegister", 50, 1);
    function onRegister($id) {
        $user = get_user_by('id', $id);
        $user->set_role('s2member_level1');
    }
    

    Users remain ‘subscribers’ (level 0). Why?

    When users register, I send them on a landing page.
    If I put the same above code on the landing page (using a PHP Plugin), users get the new role.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Because the actual setting of the role of the new member is done by s2M after the “user_register” hook, so your code runs before s2M’s one, and your changes are overwrited. At your landing page your code runs after s2M’s one, and you see your changes.

    Thread Starter espritlibre

    (@espritlibre)

    Is there another hook I can set to get the code executed after s2M ha set user role?
    Thank you

    No idea, try to search in code. I did such things once: at “user_register” I set a wp_cron job to 5 sec later, which reads the user and did something. This way s2M runs and finishes his job before my code to runs. And because wp_cron runs new instance of WP, it reads the final data from user.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Set Role On Register’ is closed to new replies.