Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yuriinalivaiko/772146e00f0c22ca7598fa636afd9c3f to your computer and use it in GitHub Desktop.
Save yuriinalivaiko/772146e00f0c22ca7598fa636afd9c3f to your computer and use it in GitHub Desktop.
This code adds custom email template "Verified Users - Account is not verified E-mail" to be used in the "Ultimate Member - Verified Users" extension.
<?php
if ( ! function_exists( 'um_email_locate_template' ) ) {
/**
* Locate a template and return the path for inclusion.
*/
function um_email_locate_template( $template_name ) {
$blog_id = is_multisite() ? '/' . get_current_blog_id() : '';
$template = locate_template(
array(
trailingslashit( 'ultimate-member/email' . $blog_id ) . $template_name . '.php',
trailingslashit( 'ultimate-member/email' ) . $template_name . '.php',
)
);
if ( ! $template ) {
$template = wp_normalize_path( STYLESHEETPATH . '/ultimate-member/email/' . $template_name . '.php' );
}
return apply_filters( 'um_locate_email_template', $template, $template_name );
}
}
/**
* Add custom email template "Verified Users - Account is not verified E-mail".
*
* @param array $emails Emails list.
* @return array
*/
function um_email_notification_unverify_user( $emails ) {
// New email templates.
$custom_emails = array(
'unverify_user' => array(
'key' => 'unverify_user',
'title' => __( 'Verified Users - Account is not verified E-mail', 'um-verified' ),
'description' => __( 'Send a notification to user when his account is not verified', 'um-verified' ),
'recipient' => 'user',
'default_active' => true,
'subject' => 'Your account is not verified on {site_name}',
'body' => 'We have reviewed your verification request. '
. 'Unfortunately we can not verify your account now. '
. 'Please update your profile and fill all required fields.<br /><br />'
. 'To view your profile click here: {user_profile_link}<br /><br />'
. 'Thank You!<br />'
. '{site_name}',
),
);
foreach ( $custom_emails as $slug => $custom_email ) {
// Default settings.
if ( ! array_key_exists( $slug . '_on', UM()->options()->options ) ) {
UM()->options()->options[ $slug . '_on' ] = empty( $custom_email['default_active'] ) ? 0 : 1;
UM()->options()->options[ $slug . '_sub' ] = $custom_email['subject'];
}
// Template file.
$located = um_email_locate_template( $slug );
if ( ! file_exists( $located ) ) {
wp_mkdir_p( dirname( $located ) );
file_put_contents( $located, $custom_email['body'] );
}
$emails[ $slug ] = $custom_email;
}
return $emails;
}
add_filter( 'um_email_notifications', 'um_email_notification_unverify_user' );
/**
* Send a notification to user when his account is not verified.
*
* @param int $user_id User ID.
*/
function um_email_notification_unverify_user_send( $user_id ) {
$userdata = get_userdata( $user_id );
$email = $userdata->user_email;
um_fetch_user( $user_id );
UM()->mail()->send( $email, 'unverify_user' );
}
add_action( 'um_after_user_is_unverified', 'um_email_notification_unverify_user_send', 20, 1 );
@yuriinalivaiko
Copy link
Author

yuriinalivaiko commented Feb 4, 2023

@yuriinalivaiko
Copy link
Author

Method UM()->mail()->locate_template() has been marked private. Use custom function um_email_locate_template instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment