새 사용자의 이메일 템플릿을 변경하는 방법


10

새 고객을 추가하면 이메일이 다음 형식으로 새 사용자에게 전달됩니다.

From: WordPress [wordpress@siteurl.com]
Subject: [site name] Your user name and password
Message:
         username: user
         Password: password
         siteurl.com/wp-login.php

이제이 형식을 변경하고 싶습니다.

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

       Your Login credentials are:

       Username: user email
       Password: password

       Thanks,
       abcd

이 답변을 시도했지만 작동하지 않습니다.

어떻게해야합니까?

답변:


17

2018 이상 사용자 :

David Gard의 답변은 여전히 ​​작동하지만 오래되었으며 더 좋은 / 더 깨끗한 방법이 있습니다 (더 이상 플러그인 필요 없음).

WordPress 4.9.0부터 등록 이메일을 사용자 정의하는 데 사용할 수있는 새로운 필터가 있습니다.

관리자에게 보낸 이메일의 사용 예 (테마의 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;
}

7

새로운 사용자 통지 이메일이 작성하는 기능에 의해 전송되고 wp_new_user_notification(), 검색된 / plugable.php WP-포함

이 기능 내에는 이메일 출력을 조작 할 수있는 필터 후크가 없지만 플러그인을 통해 플러그 형 기능을 덮어 쓸 수 있습니다.

참고 -테마 내에서가 아니라 플러그인 내에서만 플러그 가능한 기능을 덮어 쓸 수 있습니다.

플러그 가능 기능 및 사용 가능한 전체 기능 목록에 대한 자세한 내용은 여기를 참조하십시오-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;

당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.