Customization suggestion for M2 verification email

I activated verify account setting. So now the default process is after registration user will be shown a page with a message to verify email and from the email a verification link.

But what I need is, after registration redirect to a welcome page 1 showing info to ask him to verify email and in email sending Welcome page 2 link so when user click on that link he will be verified and also at the same time he will be given a free membership and redirected to welcome page 2

Is this possible?

  • Panos

    Hi Mark ,

    It is possible but it does require custom code which exceeds the scope of our support. We can only provide suggestions and hints, but we can not provide the entire custom solution nor we can provide support for custom code. For custom changes on plugins/themes that need a big amount of coding you need to hire a skilled developer. Our members have 60$ off from Codeable for their first project :
    https://premium.wpmudev.org/partners/

    Here is my suggestion on how to achieve this, if I have understood your requirements correctly.

    But what I need is, after registration redirect to a welcome page 1 showing info to ask him to verify email

    I understand that you do not want the email with the verification code to be sent right away. Instead you want to redirect to a page showing for example a link/button and after clicking that button it should send the email with the verification code.

    For this create a new page with your welcome message. You can add a link pointing to the same page with a custom query var:
    ?ms_action=verify_reg_email
    We will use that query var in next step.

    Now that we have the page ready, we need to redirect to that page after registration. In a mu-plugin insert:

    add_action( 'ms_controller_frontend_register_user_before_login', function(){
    
    	if ( ! isset( $_REQUEST['email'] ) || ! is_email( $_REQUEST['email'] ) ) {
    		return;
    	}
    
    	$user = get_user_by( 'email', $_REQUEST['email'] );
    
    	$page_id = 263;
    	wp_safe_redirect(
    		esc_url_raw(
    			add_query_arg(
    				array( 'member_id' => $user->ID ),
    				get_permalink( $page_id )
    			)
    		)
    	);
    	exit;
    
    });

    Replace
    $page_id = 263;
    with the id of the welcome page you just created.

    Following we need to check when the link is clicked so we send the email. For that you could try adding the following snippet:

    add_action( 'template_redirect', function(){
    
    	if ( ! isset( $_GET['ms_action'] ) || 'verify_reg_email' != $_GET['ms_action'] || ! isset( $_GET['member_id'] ) ) {
    		return;
    	}
    
    	$user_id = (int) $_GET['member_id'];
    	$member = MS_Factory::load( 'MS_Model_Member', $user_id );
    
    	MS_Model_Event::save_event( MS_Model_Event::TYPE_MS_VERIFYACCOUNT, $member );
    
    	if ( empty( $_REQUEST['membership_id'] ) ) {
    		$after_redirect = esc_url_raw(
    			add_query_arg(
    				array(
    					'step' => MS_Controller_Frontend::STEP_CHOOSE_MEMBERSHIP,
    				)
    			)
    		);
    	} else {
    		$after_redirect = esc_url_raw(
    			add_query_arg(
    				array(
    					'step' => MS_Controller_Frontend::STEP_PAYMENT_TABLE,
    					'membership_id' => absint( $_REQUEST['membership_id'] ),
    				),
    				MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REGISTER )
    			)
    		);
    	}
    
    	update_user_meta( $member->ID, '_ms_user_activation_redirect_url', $after_redirect );
    
    	$communication 		= MS_Model_Communication::get_communication( MS_Model_Communication::COMM_TYPE_REGISTRATION_VERIFY );
    	$comm_vars 			= _wpmudev_ms_get_communication_vars( $member );
    	$to 				= $member->email;
    	$admin_emails 		= MS_Model_Member::get_admin_user_emails();
    	$headers 			= array();
    
    	$headers[] 			= 'Content-Type: text/html; charset="UTF-8"';
    	if ( ! empty( $admin_emails[0] ) ) {
    		$headers[] 		= sprintf(
    							'From: %s <%s> ',
    							get_option( 'blogname' ),
    							$admin_emails[0]
    						);
    	}
    
    	$message 			= str_replace(
    							array_keys( $comm_vars ),
    							array_values( $comm_vars ),
    							stripslashes( $communication->message )
    						);
    
    	$subject 			= str_replace(
    							array_keys( $comm_vars ),
    							array_values( $comm_vars ),
    							stripslashes( $communication->subject )
    						);
    	$subject 			= strip_tags( $subject );
    
    	if ( wp_mail( $to, $subject, $message, $headers ) ) {
    		$redirect = esc_url_raw(
    			add_query_arg(
    				array(
    					'action' => 'check_email'
    				),
    				MS_Model_Pages::get_page_url( MS_Model_Pages::MS_PAGE_REGISTER )
    			)
    		);
    
    		wp_safe_redirect( $redirect );
    		exit;
    	}
    	else{
    		//$redirect = redirect to some error message page or same page with some error message
    		//wp_safe_redirect( $redirect );
    		//exit;
    	}
    
    });

    when user click on that link he will be verified and also at the same time he will be given a free membership and redirected to welcome page 2

    In order to verify the code and add a Free membership subscription to the new user, you can try following snippet:

    add_action( 'ms_frontend_user_account_manager-ac', function(){
    
    	$membership_id = 24;
    	$page_id = 14;
    
    	$verification_key 	= wp_unslash( $_GET['key'] );
    	$user_id 			= MS_Model_Member::verification_account_id( $verification_key  );
    
    	if ( ! $user_id ) {
    		return;
    		//Or redirect to some other page
    	}
    
    	$member = MS_Factory::load( 'MS_Model_Member', $user_id );
    	$member->add_membership( $membership_id );
    
    	wp_safe_redirect( get_permalink( $page_id ) );
    	exit;
    
    });

    Of course code provided here would require further customisation regarding your needs, but it is a helpful guide to start with.

    Hope this helps!

    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.