admin管理员组文章数量:1122832
I want to disable the default email that is send when user is registered.
I am using this plugin for email verification User Verification
By PickPlugins
, which sends an email with confirmation link, but the problem is that by default and WordPress send an email via pluggable.php
:
function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ){...}
I am using a theme (which I am extending with a child theme), which calls wp_create_user
. I have replaced that parent theme function and in my functions.php
I have added:
add_action( 'init', function(){
remove_action( 'register_new_user', 'wp_send_new_user_notifications'
);
add_action( 'register_new_user', 'wpse236122_send_new_user_notifications' );
});
function wpse236122_send_new_user_notifications( $user_id, $notify = 'user' ){
wp_send_new_user_notifications( $user_id, $notify );
}
The problem is, it still send both emails, from the plugin and default WordPress email for new user registration. I don't know how to disable this email.
I want to disable the default email that is send when user is registered.
I am using this plugin for email verification User Verification
By PickPlugins
, which sends an email with confirmation link, but the problem is that by default and WordPress send an email via pluggable.php
:
function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ){...}
I am using a theme (which I am extending with a child theme), which calls wp_create_user
. I have replaced that parent theme function and in my functions.php
I have added:
add_action( 'init', function(){
remove_action( 'register_new_user', 'wp_send_new_user_notifications'
);
add_action( 'register_new_user', 'wpse236122_send_new_user_notifications' );
});
function wpse236122_send_new_user_notifications( $user_id, $notify = 'user' ){
wp_send_new_user_notifications( $user_id, $notify );
}
The problem is, it still send both emails, from the plugin and default WordPress email for new user registration. I don't know how to disable this email.
Share Improve this question edited Feb 5, 2019 at 23:34 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Feb 5, 2019 at 23:03 gdfgdfggdfgdfg 1721 silver badge15 bronze badges3 Answers
Reset to default 0Considering your code to be working, simply put it in a plugin. It should then work!
Move the parameter default into the function.
add_action( 'init', function() {
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
});
add_action( 'register_new_user', 'wpse236122_send_new_user_notifications' );
function wpse236122_send_new_user_notifications( $user_id ){
wp_new_user_notification( $user_id, null, 'user' );
}
Changed the wpse236122_send_new_user_notifications function to use the wp_new_user_notification as opposed to the action directly. Even though it works, it is more likely to break in a WordPress update.
I would also mention maybe instead of removing the action on init, use the register_new_user action and set at a lower priority. WordPress core uses 10 by default, so putting yours at 9 or below will work.
add_action( 'register_new_user', function(){
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
}, 9);
Tried several suggestions but they didn't work for me. Found a piece of code at SmartWP.com for disabling the admin notification and changed the code slightly and this one finally worked great
function smartwp_disable_new_user_notifications() {
//Remove original use created emails
remove_action( 'register_new_user', 'wp_send_new_user_notifications' );
remove_action( 'edit_user_created_user', 'wp_send_new_user_notifications', 10, 2 );
add_action( 'register_new_user', 'smartwp_send_new_user_notifications' );
add_action( 'edit_user_created_user', 'smartwp_send_new_user_notifications', 10, 2 );}
function smartwp_send_new_user_notifications( $user_id, $notify = 'admin' ) {
if ( empty($notify) || $notify == 'user' ) {
return;
}elseif( $notify == 'both' ){
//Only send the admin their email, not the user
$notify = 'admin';
}
wp_send_new_user_notifications( $user_id, $notify );}
add_action( 'init', 'smartwp_disable_new_user_notifications' );
本文标签: Disable emails for new user registration
版权声明:本文标题:Disable emails for new user registration 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292134a1928869.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论