• Resolved fishmarketing

    (@fishmarketing)


    I’m trying to integrate your plugin with the Groups membership plugin so when a user is approved, they are assigned a designated group to gain access to restricted content. I need to have the user ID in order to assign the appropriate group.

    So far in my functions.php I have:

    add_action( 'new_user_approve_user_approved', 'change_user_confirmed_group', 18 );
    
    function change_user_confirmed_group( $user_id ) {
    
    	$user = new WP_User( $user_id );
    	$user_role = $user->roles[0];
    
    	...assign group to user based on role
    }

    Is this the best way to capture the $user_id being used by the new_user_approve_user_approved action?

    Thanks ahead for you assistance.

    https://ww.wp.xz.cn/plugins/new-user-approve/

Viewing 2 replies - 1 through 2 (of 2 total)
  • That is exactly how you should use the new_user_approve_user_approved action. Did it accomplish what you wanted it to?

    Thread Starter fishmarketing

    (@fishmarketing)

    Thanks for getting back to me on this.

    I found that the new_user_approve_user_approved action passes along a user Object so I didn’t have to establish a new one. The code that worked for me is slightly different than what I posted:

    add_action( 'new_user_approve_user_approved', 'change_user_confirmed_group');
    
    function change_user_confirmed_group( $user ) {
    
    		$user_role = $user->roles[0];
    		$user_id = $user->ID;
    
                    ...assign group to user based on role
    }
Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add action when user is approved’ is closed to new replies.