User login option "Per form"

Home Forums User Registration User login option "Per form"

This topic contains 1 reply, has 2 voices, and was last updated by  rumesh38 3 months, 3 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19833

    Josh
    Participant

    Hello, we have several forms that require admin approval and one that should log in automatically after registration. Are we able to set this option “per form” instead of globally?

    #19970

    rumesh38
    Moderator

    Hi Josh,

    There is no option to select a different login option for the registration form. But there is a way around for your case if you are comfortable using the code. You can add the following code in the function.php file of your theme to approve users registered through the specific form.

    function ur_set_user_status( $valid_form_data, $form_id, $user_id ) {
    
    	$user_manager = new UR_Admin_User_Manager( $user_id );
    
    	$alert_user_email = false; // Set true to send email to user for approval.
    
    	if ( in_array( $form_id, array( '<Your form ID to be approved>' ) ) ) { // [user_registration_form id = "<Your form ID>"]
    		$user_manager->save_status( UR_Admin_User_Manager::APPROVED, $alert_user_email );
    		wp_clear_auth_cookie();
    		wp_set_auth_cookie( $user_id );
    	}
    }
    add_action( 'user_registration_after_register_user_action', 'ur_set_user_status', 20, 3 );
    
    function ur_user_register_status( $success_params, $valid_form_data, $form_id, $user_id ) {
    	if ( in_array( $form_id, array( '<Your form ID to be approved>' ) ) ) { // [user_registration_form id = "<Your form ID>"]
    		$success_params['auto_login'] = true;
    	}
    
    	return $success_params;
    }
    add_filter( 'user_registration_success_params', 'ur_user_register_status', 10, 4 );
    

    Hope this help!

    Thanks & Regards,
    WPEverest Support Team.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.