我有一个非常简单的代码,如果他们的帐户已被批准,就会向Wordpress用户发送电子邮件。
我还想将用户名和密码发送到此电子邮件中。
我该怎么做?
以下是我用来发送电子邮件的代码。
<?php
add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));
/*--------------------------------
message received after account approval and account denied
------------------------------------*/
/**
* Modify the message sent to a user after being approved.
*
* @param $message The default message.
* @param $user The user who will receive the message.
* @return string the updated message.
*/
function my_custom_message( $message, $user ) {
$message = 'account approved, your login details are below:';
return $message;
}
function my_deniedcustom_message( $message, $user ) {
$message = 'Unfortunately you account has been denied membership';
return $message;
}
// add a new custom approval message
add_filter( 'new_user_approve_approve_user_message', 'my_custom_message' );
// add a new custom denial message
add_filter( 'new_user_approve_deny_user_message', 'my_deniedcustom_message' );
?>
答案 0 :(得分:0)
基本上你可以使用内置的wp_new_user_notification()
功能:
// Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
$user = new WP_User( $user_id );
$user_login = stripslashes( $user->user_login );
$user_email = stripslashes( $user->user_email );
$message = sprintf( __('New user registration on %s:'), get_option('blogname') ) . "\r\n\r\n";
$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n\r\n";
$message .= sprintf( __('E-mail: %s'), $user_email ) . "\r\n";
@wp_mail(
get_option('admin_email'),
sprintf(__('[%s] New User Registration'), get_option('blogname') ),
$message
);
if ( empty( $plaintext_pass ) )
return;
$message = __('Hi there,') . "\r\n\r\n";
$message .= sprintf( __("Welcome to %s! Here's how to log in:"), get_option('blogname')) . "\r\n\r\n";
$message .= wp_login_url() . "\r\n";
$message .= sprintf( __('Username: %s'), $user_login ) . "\r\n";
$message .= sprintf( __('Password: %s'), $plaintext_pass ) . "\r\n\r\n";
$message .= sprintf( __('If you have any problems, please contact me at %s.'), get_option('admin_email') ) . "\r\n\r\n";
$message .= __('Bye!');
wp_mail(
$user_email,
sprintf( __('[%s] Your username and password'), get_option('blogname') ),
$message
);
}
}
注意:如果密码未传递给功能,新注册的用户将不会收到欢迎电子邮件。