如何更改新用户的电子邮件模板

时间:2015-02-06 作者:deemi-D-nadeem

当我添加新客户时,电子邮件将以以下格式发送给新用户:

From: WordPress [[email protected]]
Subject: [site name] Your user name and password
Message:
         username: user
         Password: password
         siteurl.com/wp-login.php
现在我想更改如下格式:

From: My Site Name [[email protected]]
Subject: siteurl.com customer account activated
Message:
       Your customer account has been activated.

       Your Login credentials are:

       Username: user email
       Password: password

       Thanks,
       abcd
我试过了this answer 但它不起作用。

我该怎么做?

3 个回复
SO网友:Edu Wass

For 2018 and onwards users:

David Gard的答案仍然有效,但很旧,有一种新的更好/更干净的方法可以做到这一点(不再需要插件)。

自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网友:David Gard

新用户通知电子邮件由函数创建并发送wp_new_user_notification(), 在中找到wp-includes/plugable.php

此函数中没有允许您操作电子邮件输出的过滤器挂钩,但是您当然可以通过插件覆盖任何可插入功能。

Note - 只能从插件中覆盖可插入函数,而不能从主题中覆盖

有关可插拔功能的更多详细信息以及可用功能的完整列表,请参见此处-http://codex.wordpress.org/Pluggable_Functions

此代码将创建插件,该插件将被使用,而不是wp-includes/plugable.php (将其保存在wp-content/plugins/).

我还没有为你定制,但这会让你上路的。

<?php
/**
 * Plugin Name: Custom new user notification email
 * Description: Overwrites the pluggable \'wp_new_user_notification()\' plugin to allow the sending of a custom email
 * Author: David Gard
 * Version: 1.0
 */

if ( !function_exists(\'wp_new_user_notification\') ) :
/**
 * Pluggable - Email login credentials to a newly-registered user
 *
 * A new user registration notification is also sent to admin email.
 *
 * @since 2.0.0
 *
 * @param int    $user_id        User ID.
 * @param string $plaintext_pass Optional. The user\'s plaintext password. Default empty.
 */
function wp_new_user_notification($user_id, $plaintext_pass = \'\'){

    $user = get_userdata($user_id);

    // The blogname option is escaped with esc_html on the way into the database in sanitize_option
    // we want to reverse this for the plain text arena of emails.
    $blogname = wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);

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

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

    if ( empty($plaintext_pass) )
        return;

    $message  = sprintf(__(\'Username: %s\'), $user->user_login) . "\\r\\n";
    $message .= sprintf(__(\'Password: %s\'), $plaintext_pass) . "\\r\\n";
    $message .= wp_login_url() . "\\r\\n";

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

}
endif;

SO网友:Richard Dinh

如果您指的是多站点设置,则可以通过在数据库中的以下两个部分中设置的模板进行配置:

Welcome Email

Welcome User Email

http://yoursite/wp-admin/network/settings.php

您可以根据自己的喜好进行定制。

结束

相关推荐

Email notification

我正在尝试用主题(帖子标题)和内容来丰富此通知,而不是它的当前视图和编辑链接,有人能帮忙吗?<?php function __notify_admin_on_publish( $new_status, $old_status, $ticket ) { if ( $new_status != \'publish\' || $old_status == \'publish\' ) return; $message = \'View it