新的用户通知电子邮件由函数创建并发送,该函数wp_new_user_notification()
位于wp-includes / plugable.php中
此功能中没有过滤器挂钩,可让您操纵电子邮件的输出,但是您当然可以通过插件覆盖任何可插拔功能。
注意 -您只能从插件内部而不是主题内部覆盖可插入函数。
有关可插拔功能的详细信息以及可用功能的完整列表,请参见此处-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;