How to add and use custom email templates

Use hook 'um_email_notifications' to add custom templates.

Use method UM()->mail()->send( $email, $template, $args ); to send email based on template. Optional argument $args allow to extend placeholders array.

Custom emails are shown on the Ultimate Member > Settings > Email page. Administrator can edit custom email templates in the same way as default email templates.
Custom email body will be saved to the file 'wp-content/themes/THEME_FOLDER/ultimate-member/email/TEMPLATE_NAME.php'.

Note: Each template has options 'TEMPLATE_NAME_on' and 'TEMPLATE_NAME_sub'. You can use method UM()->options()->update( $option_id, $value ); to set value for these options.


[Ultimate Member > Settings > Email]
UM-Email-custom-email-templates.png

[Ultimate Member > Settings > Email > Edit]
UM-Email-Account-Welcome-Email-Group-1.png

[wp-content/themes/THEME_FOLDER/ultimate-member/email/]
email-templates-files.png


How to add custom email templates, an example:

NOTE: We are not able to provide any support when it comes to customizing the plugin. We have provided this code example to provide guidance only.

/**
 * Add custom email templates
 * @param array $emails
 * @return array
 */
function custom_um_email_notifications_after_user_is_approved( $emails ) {

	/* New email templates */
	$custom_emails = array(
			'group1_approved_email'	 => array(
					'key'						 => 'group1_approved_email',
					'title'					 => __( 'Account Welcome Email, Group 1', 'ultimate-member' ),
					'subject'				 => 'Welcome to {site_name}!',
					'body'					 => '',
					'description'		 => __( 'Whether to send the user (Group 1) an email when his account is automatically approved.', 'ultimate-member' ),
					'recipient'			 => 'user',
					'default_active' => true
			),
			'group2_approved_email'	 => array(
					'key'						 => 'group2_approved_email',
					'title'					 => __( 'Account Welcome Email, Group 2', 'ultimate-member' ),
					'subject'				 => 'Welcome to {site_name}!',
					'body'					 => '',
					'description'		 => __( 'Whether to send the user (Group 2) an email when his account is automatically approved.', 'ultimate-member' ),
					'recipient'			 => 'user',
					'default_active' => true
			),
	);

	/* Default settings */
	UM()->options()->options = array_merge( array(
			'group1_approved_email_on'	 => 1,
			'group1_approved_email_sub'	 => 'Welcome to {site_name}!',
			'group2_approved_email_on'	 => 1,
			'group2_approved_email_sub'	 => 'Welcome to {site_name}!',
			), UM()->options()->options );

	return array_merge( $custom_emails, $emails );
}
add_filter( 'um_email_notifications', 'custom_um_email_notifications_after_user_is_approved' );

How to use custom email templates, an example:

NOTE: We are not able to provide any support when it comes to customizing the plugin. We have provided this code example to provide guidance only.

/**
 * Send custom email templates (depending on UM user role) on UM User approve action.
 * @param int $user_id
 * @return boolean
 */
function custom_um_after_user_is_approved( $user_id = null ) {

	if( empty( $user_id ) ) {
		$user_id = get_current_user_id();
	}

	$status = get_user_meta( $user_id, 'account_status', true );
	if( 'approved' !== $status ) {
		return;
	}

	$rolename = UM()->roles()->get_priority_user_role( $user_id );
	$userdata = get_userdata( $user_id );

	switch( $rolename ) {
		case 'um_group1':
			UM()->mail()->send( $userdata->user_email, 'group1_approved_email' );
			break;
		case 'um_group2':
			UM()->mail()->send( $userdata->user_email, 'group2_approved_email' );
			break;
		default:
			break;
	}
}
add_action( 'um_after_user_is_approved', 'custom_um_after_user_is_approved' );