Skip to content

Instantly share code, notes, and snippets.

@yuriinalivaiko
Last active February 27, 2026 13:45
Show Gist options
  • Select an option

  • Save yuriinalivaiko/61e025eaa52eb83cc33a42e51240e114 to your computer and use it in GitHub Desktop.

Select an option

Save yuriinalivaiko/61e025eaa52eb83cc33a42e51240e114 to your computer and use it in GitHub Desktop.
Ultimate Member customization. Code snippets for email notifications.
<?php
/**
* Disable email notifications for specific roles.
*
* @param bool $disabled Does an email is disabled? Default: false.
* @param string $email Email address for sending.
* @param string $template Email template.
* @param array $args Arguments for sending email.
* @return bool Return true to stop mailing.
*/
function my_disable_email_notification_sending( $disabled, $email, $template, $args ) {
// List the roles for which email notifications should be disabled.
$roles = array(
'contributor',
'um_pending-member',
);
$user = get_user_by( 'email', $email );
if ( $user ) {
$user_roles = UM()->roles()->get_all_user_roles( $user->ID );
if ( array_intersect( $roles, $user_roles ) ) {
$disabled = true;
}
}
return $disabled;
}
add_filter( 'um_disable_email_notification_sending', 'my_disable_email_notification_sending', 10, 4 );
<?php
/**
* Add role-specific content to the email template.
*
* @tutorial https://docs.google.com/document/d/1Vo4OrpEjzw4QILYgTWjso2EJUZmyQ4U7DM-CDdRriP4/edit?usp=sharing
*/
add_filter( 'um_template_tags_patterns_hook', 'my_template_tags_patterns', 10, 1 );
add_filter( 'um_template_tags_replaces_hook', 'my_template_tags_replaces', 10, 1 );
function my_template_tags_patterns( $search ) {
$search[] = '{welcome_content_for_subscriber}';
$search[] = '{welcome_content_for_customer}';
$search[] = '{welcome_content_for_um_member}';
return $search;
}
function my_template_tags_replaces( $replace ) {
$role = um_user( 'role' );
$replace[] = 'subscriber' === $role ? 'This message is shown in the welcome email for users whose priority user role is "Subscriber".' : '';
$replace[] = 'customer' === $role ? 'This message is shown in the welcome email for users whose priority user role is "Customer".' : '';
$replace[] = 'um_member' === $role ? 'This message is shown in the welcome email for users whose priority user role is "Member".' : '';
return $replace;
}
<?php
/**
* Add the "Bcc" header to the "Account Updated" email.
* Send the mail copy to the website admins.
*
* @param string $subject Email subject.
* @param string $template Email template key.
*/
function my_um_email_changedaccount_email_bcc( $subject, $template ) {
if ( 'changedaccount_email' === $template ) {
$bcc = um_multi_admin_email();
UM()->mail()->headers .= 'Bcc: ' . implode( ',', $bcc ) . "\r\n";
}
return $subject;
}
add_filter( 'um_email_send_subject', 'my_um_email_changedaccount_email_bcc', 10, 2 );
@yuriinalivaiko
Copy link
Copy Markdown
Author

yuriinalivaiko commented Mar 12, 2024

This code is an example for the Ultimate Member plugin.

Related documentation: Emails Tab, Placeholders for email templates

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