Wordpress user-registered email content custom format beautification instance

Source: Internet
Author: User
Tags sprintf

WordPress provides a new user email notification function wp_new_user_notification () that can be redefined by the plug-in. Now Let's redefine the content of this function to beautify the Mail content format.

The original function content is as follows:


The code is as follows: Copy code
If (! Function_exists ('WP _ new_user_notification ')):
/**
* Login y the blog admin of a new user, normally via email.
 *
* @ Since 2.0
 *
* @ Param int $ user_id User ID
* @ Param string $ plaintext_pass Optional. The user's plaintext password
*/
Function wp_new_user_notification ($ user_id, $ plaintext_pass = ''){
$ User = get_userdata ($ user_id );

$ User_login = stripslashes ($ user-> user_login );
$ User_email = stripslashes ($ user-> user_email );

// 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). "rnrn ";
$ Message. = sprintf (_ ('username: % S'), $ user_login). "rnrn ";
$ Message. = sprintf (_ ('E-mail: % S'), $ user_email). "rn ";

@ Wp_mail (get_option ('admin _ email '), sprintf (_ (' [% s] New User Registration '), $ blogname), $ message );

If (empty ($ plaintext_pass ))
Return;

$ Message = sprintf (_ ('username: % S'), $ user_login). "rn ";
$ Message. = sprintf (_ ('password: % S'), $ plaintext_pass). "rn ";
$ Message. = wp_login_url (). "rn ";

Wp_mail ($ user_email, sprintf (_ ('[% s] Your username and password'), $ blogname), $ message );

}
Endif;



Custom email content and format

We can create a new "plug-in" to redefine the Mail content defined by the wp_new_user_notification function. In the wp-content/plugins/directory, create a new text file named new-user-notification.php, insert the following code, save it, and then start the plug-in new-user-notification in the background:
The code is as follows: Copy code

<? Php
/*
Plugin Name: new-user-notification
Description: redefine the content and format of the sent email.
Version: 1.0
*/

If (! Function_exists ('WP _ new_user_notification ')):
/**
* Login y the blog admin of a new user, normally via email.
 *
* @ Since 2.0
 *
* @ Param int $ user_id User ID
* @ Param string $ plaintext_pass Optional. The user's plaintext password
*/
Function wp_new_user_notification ($ user_id, $ plaintext_pass = ''){
$ User = get_userdata ($ user_id );

$ User_login = stripslashes ($ user-> user_login );
$ User_email = stripslashes ($ user-> user_email );

// Obtain the blog name
$ Blogname = wp_specialchars_decode (get_option ('blogname'), ENT_QUOTES );

// The email content sent to the Postmaster. The content is in HTML format.
$ Message = '
// Send an email to the website administrator
$ Message_headers = "Content-Type: text/html; charset =" UTF-8 "n ";
@ Wp_mail (get_option ('admin _ email '), sprintf (_ (' [% s] New User Registration '), $ blogname), $ message, $ message_headers );

If (empty ($ plaintext_pass ))
Return;
  
// You can modify the notification Email sent to new users in HTML format.
$ Message = '
// Sprintf (_ ('[% s] Your username and password'), $ blogname) is the Mail title
Wp_mail ($ user_email, sprintf (_ ('[% s] Your username and password'), $ blogname), $ message, $ message_headers );
}
Endif;

?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.