帮助更改新网站通知的文本(WPMU_WEBLE_NOTIFICATION)

时间:2015-02-18 作者:need-help

我正在尝试更改新网站通知(wpmu\\u welcome\\u通知)的文本:

在核心文件中,我看到wordpress在创建新网站时使用此功能发送电子邮件:

问题是,我如何挂接此函数以更改“$welcome\\u email”中使用的正文文本

function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
    $current_site = get_current_site();
    /**
     * Filter whether to bypass the welcome email after site activation.
     *
     * Returning false disables the welcome email.
     *
     * @since MU
     *
     * @param int|bool $blog_id  Blog ID.
     * @param int      $user_id  User ID.
     * @param string   $password User password.
     * @param string   $title    Site title.
     * @param array    $meta     Signup meta data.
     */
    if ( ! apply_filters( \'wpmu_welcome_notification\', $blog_id, $user_id, $password, $title, $meta ) )
        return false;
    $welcome_email = get_site_option( \'welcome_email\' );
    if ( $welcome_email == false )
        $welcome_email = __( \'Howdy USERNAME,
Your new SITE_NAME site has been successfully set up at:
BLOG_URL
You can log in to the administrator account with the following information:
Username: USERNAME
Password: PASSWORD
Log in here: BLOG_URLwp-login.php
We hope you enjoy your new site. Thanks!
--The Team @ SITE_NAME\' );
    $url = get_blogaddress_by_id($blog_id);
    $user = get_userdata( $user_id );
    $welcome_email = str_replace( \'SITE_NAME\', $current_site->site_name, $welcome_email );
    $welcome_email = str_replace( \'BLOG_TITLE\', $title, $welcome_email );
    $welcome_email = str_replace( \'BLOG_URL\', $url, $welcome_email );
    $welcome_email = str_replace( \'USERNAME\', $user->user_login, $welcome_email );
    $welcome_email = str_replace( \'PASSWORD\', $password, $welcome_email );
    /**
     * Filter the content of the welcome email after site activation.
     *
     * Content should be formatted for transmission via wp_mail().
     *
     * @since MU
     *
     * @param string $welcome_email Message body of the email.
     * @param int    $blog_id       Blog ID.
     * @param int    $user_id       User ID.
     * @param string $password      User password.
     * @param string $title         Site title.
     * @param array  $meta          Signup meta data.
     */
    $welcome_email = apply_filters( \'update_welcome_email\', $welcome_email, $blog_id, $user_id, $password, $title, $meta );
    $admin_email = get_site_option( \'admin_email\' );
    if ( $admin_email == \'\' )
        $admin_email = \'support@\' . $_SERVER[\'SERVER_NAME\'];
    $from_name = get_site_option( \'site_name\' ) == \'\' ? \'WordPress\' : esc_html( get_site_option( \'site_name\' ) );
    $message_headers = "From: \\"{$from_name}\\" <{$admin_email}>\\n" . "Content-Type: text/plain; charset=\\"" . get_option(\'blog_charset\') . "\\"\\n";
    $message = $welcome_email;
    if ( empty( $current_site->site_name ) )
        $current_site->site_name = \'WordPress\';
    /**
     * Filter the subject of the welcome email after site activation.
     *
     * @since MU
     *
     * @param string $subject Subject of the email.
     */
    $subject = apply_filters( \'update_welcome_subject\', sprintf( __( \'New %1$s Site: %2$s\' ), $current_site->site_name, wp_unslash( $title ) ) );
    wp_mail( $user->user_email, wp_specialchars_decode( $subject ), $message, $message_headers );
    return true;
}

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

下面是一个未经测试的示例,您如何根据需要修改电子邮件正文:

add_filter( \'update_welcome_email\', 
    function( $welcome_email, $blog_id, $user_id, $password, $title, $meta )
    {
        // Override the email body:
        $welcome_email = __( \'Dear User,

Your new SITE_NAME site has been successfully set up at:
BLOG_URL

You can log in to the administrator account with the following information:

Username: USERNAME
Password: PASSWORD
Log in here: BLOG_URLwp-login.php

We hope you enjoy your new site. Thanks!

--The Team @ SITE_NAME\' );

        $current_site = get_current_site();
        $url          = get_blogaddress_by_id($blog_id);
        $user         = get_userdata( $user_id );

        return str_replace( 
            array( \'SITE_NAME\', \'BLOG_TITLE\', \'BLOG_URL\', \'USERNAME\', \'PASSWORD\' ),
            array( $current_site->site_name, $title, $url, $user->user_login, $password ),
            $welcome_email 
        );
    }
, 10, 6 );

结束

相关推荐

在同一操作中保持2个wp_user(在更新User_Email时更新BILLING_Email)

iam正在尝试更新woocommerce billing\\u email在更新user\\u email时,问题是如何在同一个操作中保存来自wp\\u user的两个对象,在此代码中add_action(\'profile_update\', \'sync_woocommerce_email\', 10, 2) ; function sync_woocommerce_email( $user_id, $old_user_data ) { $current_user = wp_g