禁用新用户注册的电子邮件

时间:2019-02-05 作者:gdfgdfg

我想禁用用户注册时发送的默认电子邮件。我正在使用此插件进行电子邮件验证User Verification By PickPlugins, 它发送带有确认链接的电子邮件,但问题是默认情况下,WordPress通过pluggable.php:

function wp_new_user_notification( $user_id, $deprecated = null, $notify = \'\' ){...}
我正在使用一个主题(我正在扩展一个子主题),它调用wp_create_user. 我已经替换了父主题函数functions.php 我补充道:

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  );
}
问题是,它仍然会发送来自插件的电子邮件和用于新用户注册的默认WordPress电子邮件。我不知道如何禁用此电子邮件。

2 个回复
SO网友:Lucien Dubois

考虑到您的代码正在工作,只需将其放在插件中即可。然后它应该会工作!

SO网友:JonShipman

将参数default移到函数中。

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\' );
}
将wpse236122\\u send\\u new\\u user\\u notifications函数更改为使用wp\\u new\\u user\\u通知,而不是直接使用操作。尽管它可以工作,但更有可能在WordPress更新中中断。

我还想提到的是,使用register\\u new\\u user操作并设置为较低的优先级,而不是删除init上的操作。WordPress core默认使用10,所以将您的值设置为9或更低就可以了。

add_action( \'register_new_user\', function(){
    remove_action( \'register_new_user\', \'wp_send_new_user_notifications\' );
}, 9);

相关推荐

Get users that likes the post

我有一个类似ajax的帖子系统,当用户喜欢帖子时,系统会在帖子中添加一个帖子元,并将其命名为(post\\u liked\\u users)。post\\u likes\\u users元值示例:a:1:{s:6:\"user-1\";i:1;}现在,如何才能获得喜欢该帖子的用户?注意:我不能像杰克·约翰逊那样只使用foreach答案,我必须使用WP\\u User\\u Query或WP\\u Query,因为我要使用offest和number。