如何更改默认注册电子邮件?(插件和/或非插件)

时间:2011-04-21 作者:mike23

新用户注册后,WP会发送一封包含登录名/密码的电子邮件,以及登录页面的链接。

有没有办法更改此defaut电子邮件模板?我还想更改主题和发件人。

编辑:对于任何感兴趣的人,here 是一个插件解决方案。

3 个回复
最合适的回答,由SO网友:Bainternet 整理而成

使用发送新用户电子邮件wp_new_user_notification() 作用此函数是可插入的,这意味着您可以覆盖它:

// Redefine user notification function
if ( !function_exists(\'wp_new_user_notification\') ) {
    function wp_new_user_notification( $user_id, $plaintext_pass = \'\' ) {
        $user = new WP_User($user_id);

        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);

        $message  = sprintf(__(\'New user registration on your blog %s:\'), get_option(\'blogname\')) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'E-mail: %s\'), $user_email) . "\\r\\n";

        @wp_mail(get_option(\'admin_email\'), sprintf(__(\'[%s] New User Registration\'), get_option(\'blogname\')), $message);

        if ( empty($plaintext_pass) )
            return;

        $message  = __(\'Hi there,\') . "\\r\\n\\r\\n";
        $message .= sprintf(__("Welcome to %s! Here\'s how to log in:"), get_option(\'blogname\')) . "\\r\\n\\r\\n";
        $message .= wp_login_url() . "\\r\\n";
        $message .= sprintf(__(\'Username: %s\'), $user_login) . "\\r\\n";
        $message .= sprintf(__(\'Password: %s\'), $plaintext_pass) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'If you have any problems, please contact me at %s.\'), get_option(\'admin_email\')) . "\\r\\n\\r\\n";
        $message .= __(\'Adios!\');

        wp_mail($user_email, sprintf(__(\'[%s] Your username and password\'), get_option(\'blogname\')), $message);

    }
}
Note: 无法在主题函数中重写可插入函数。php文件。WP的可插入文件已经由该点加载,因此该函数将由WP定义(即默认值)。必须加载自定义版本before 发生这种情况,这意味着您必须将其加载到自定义插件文件中。

SO网友:Edu Wass

For 2018 and onwards users:

自WordPress 4.9.0以来,您可以使用新的过滤器(不再需要插件):

  • wp_new_user_notification_email - 自定义发送给用户的电子邮件wp_new_user_notification_email_admin - 自定义发送给管理员的电子邮件的用法示例(您可以将其粘贴到主题的functions.php ):

    add_filter( \'wp_new_user_notification_email_admin\', \'custom_wp_new_user_notification_email\', 10, 3 );
    
    function custom_wp_new_user_notification_email( $wp_new_user_notification_email, $user, $blogname ) {
        $wp_new_user_notification_email[\'subject\'] = sprintf( \'[%s] New user %s registered.\', $blogname, $user->user_login );
        $wp_new_user_notification_email[\'message\'] = sprintf( "%s ( %s ) has registerd to your blog %s.", $user->user_login, $user->user_email, $blogname );
        return $wp_new_user_notification_email;
    }
    

SO网友:Erez Lieberman

这对函数不起作用。php。您需要将此代码放入插件中。

如果您现在不想为此制作插件,请使用link.

不要忘记使用此函数表单的更新代码here.

结束

相关推荐

query users by role

我有一个查询用户和usermeta的自定义插件,但我现在需要从结果中筛选管理员。我的sql查询的一个非常简化的版本是:SELECT * FROM usermeta LEFT JOIN users ON users.ID = user_id WHERE meta_key = \'last_name\' AND user_role != \'admin\' ORDER BY meta_value ASC LIMIT 0, 25 user_role 不是字段,我看