• Resolved albertoaranda

    (@albertoaranda)


    With this code it is possible to change the role of a user if his email is gmail.

    add_action("um_registration_complete","um_042121_change_user_role", 1, 2 );
    function um_042121_change_user_role( $user_id, $args ){
       
        if( isset( $args['user_email'] ) ){
    
            list($user, $domain) = explode('@', $args['user_email'] );
    
            if ($domain == 'gmail.com') {
                wp_update_user( array( 'ID' => $user_id, 'role' => 'premium-member' ) );
            }
    
        }
    }
    
    
    Is it also possible is the account status approved when the email is gmail? And so wait for the approval of the account?
    
    Thanks.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @albertoaranda

    You can try this code snippet that changes the user role and status when the email is a Gmail:

    add_action("um_registration_complete","um_042121_change_user_role", 1, 2 );
    function um_042121_change_user_role( $user_id, $args ){
       
        if( isset( $args['user_email'] ) ){
             um_fetch_user( $user_id );
                
            list($user, $domain) = explode('@', $args['user_email'] );
    
            if ($domain == 'gmail.com') {
                // Update the role
                wp_update_user( array( 'ID' => $user_id, 'role' => 'premium-member' ) );       // Approve the user account for Gmail users 
               UM()->user()->approve();
                
            }else{
               // Pending approval for non-Gmail users.
               UM()->user()->pending();
            }
    
        }
    }

    Regards,

    • This reply was modified 3 years, 7 months ago by Champ Camba.
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @albertoaranda
    Please feel free to re-open this thread by changing the Topic Status to ‘Not Resolved’ if any other questions come up and we’d be happy to help. ??

    Regards,

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Approve account when email is gmail’ is closed to new replies.