我一直在尝试编辑WordPress在用户注册我的网站时发送给他们的自动电子邮件。目前,他们注册在一个名为Forminator的插件制作的表单上。然而,WordPress默认的电子邮件仍然会发送,其中包含我的管理员url,这简直没有吸引力。我已经求助于使用代码,因为没有其他插件可以在不完全禁用电子邮件的情况下停止/替换默认WP电子邮件。
我尝试了以下代码,但没有替换默认电子邮件:
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(__(\'Hey %s,\'), $user->user_login) . "\\r\\n";
$message .= sprintf(__(\'Thank you for registering with us! You are officially a Member who just earned the Loyalty Bagde, which grants you 50 Points!\'), $plaintext_pass) . "\\r\\n";
$message .= sprintf(__(\'Earn more rewards now by purchasing any products!\'), $plaintext_pass) . "\\r\\n";
$message .= wp_login_url() . "\\r\\n";
wp_mail($user->user_email, sprintf(__(\'Your Brand New Account at %s\'), $blogname), $message);
}
endif;
这段代码是否有问题,或者我是否使用了错误的钩子?我对编码知之甚少,因此非常感谢您的帮助。