Skip to content

Instantly share code, notes, and snippets.

@rolandinsh
Last active February 22, 2022 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save rolandinsh/5636349 to your computer and use it in GitHub Desktop.
Save rolandinsh/5636349 to your computer and use it in GitHub Desktop.
wp_new_user_notification() - wordpress new user notification message on register
<?php
if ( !function_exists( 'wp_new_user_notification' ) ) {
function wp_new_user_notification( $studentID, $plaintext_pass = '' ) {
$student = new WP_User($studentID);
$student_data = get_userdata( $studentID );
$firstname = $student_data->first_name;
$student_login = stripslashes( $student_data->user_login );
// URLs
$site_url = site_url();
$ads_url = site_url( 'ads/' );
$login_url = site_url();
// Email variables
$headers = 'From: EXAMPLE.INFO <info@example.info>' . "rn";
$blog_name = get_option( 'blogname' );
$admin_subject = 'New User Registration on ' . $blog_name;
$welcome_subject = 'Welcome to EXAMPLE.INFO!';
$welcome_email = stripslashes( $student_data->user_email );
$admin_email = get_option('admin_email');
$admin_message =
<<<EOT
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head><body>
<div class="content">
<div class="wrapper">
<p>New user registration on your blog: {$blog_name}.</p>
<p>Username: {$student_login}</p>
<p>Email: {$welcome_email}</p>
</div>
</div>
</body></html>
EOT;
$welcome_message =
<<<EOT
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head><body>
<div class="content">
<div class="wrapper">
<table width="100%"><tr><td>
Hello {$firstname},<br />
To log into your account,
go <a href="{$login_url}">visit our site</a>
and use the credentials below.<br />
Your Username: {$student_login}<br />
Your Password: {$plaintext_pass}<br />
</td></tr></table>
</div>
</div>
</body></html>
EOT;
wp_mail( $admin_email, $admin_subject, $admin_message, $headers );
wp_mail( $welcome_email, $welcome_subject, $welcome_message, $headers );
} // End of wp_new_user_notification()
}
@rohitkc72
Copy link

rohitkc72 commented Feb 22, 2022

How to know if the function is working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment