Last active
April 20, 2023 11:53
-
-
Save AngeliMae/d07a3f925005b0a5e757f6bdc119597e to your computer and use it in GitHub Desktop.
Disable Welcome Email After Registration for Certain Roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| add_action( 'um_before_email_notification_sending', function( $email, $template, $args ) { | |
| if ( 'custom-role-id' === um_user( 'role' ) && 'welcome_email' === $template ) { | |
| add_filter( 'pre_wp_mail', '__return_true' ); | |
| } | |
| }, 10, 3 ); | |
| add_action( 'um_after_email_notification_sending', function( $email, $template, $args ) { | |
| if ( 'custom-role-id' === um_user( 'role' ) && 'welcome_email' === $template ) { | |
| remove_filter( 'pre_wp_mail', '__return_true' ); | |
| } | |
| }, 10, 3 ); |
Hi @AngeliMae
Your code may work wrong. The um_before_email_notification_sending hook is an action, not a filter. This hook has only 3 parameters.
Try this code instead:
// Disable the Account Welcome Email for Contributor.
add_action( 'um_before_email_notification_sending', function( $email, $template, $args ) {
if ( 'custom-role-id' === um_user( 'role' ) && 'welcome_email' === $template ) {
add_filter( 'pre_wp_mail', '__return_true' );
}
}, 10, 3 );
add_action( 'um_after_email_notification_sending', function( $email, $template, $args ) {
if ( 'custom-role-id' === um_user( 'role' ) && 'welcome_email' === $template ) {
remove_filter( 'pre_wp_mail', '__return_true' );
}
}, 10, 3 );
This code also can disable an email for a role:
// Disable the Account Welcome Email for Contributor v2.0.
add_filter( 'um_get_option_filter__welcome_email_on', function( $option ) {
if ( 'custom-role-id' === um_user( 'role' ) ) {
$option = false;
}
return $option;
} );
Author
It is working now, Thank you!
My wrong, comment has been edited https://gist.github.com/AngeliMae/d07a3f925005b0a5e757f6bdc119597e?permalink_comment_id=4541559#gistcomment-4541559
But it only since 2.6.1 version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since 2.6.1 version you may use this code snippet to avoid WordPress native 'pre_wp_mail' hook: