新用户通知电子邮件由函数创建并发送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;