Ejemplo n.º 1
0
 /**
  * set up the new user notification email
  *
  * @param  integer $user      the newly created user ID or the entire object
  * @param  string  $password  the password assigned to the new user
  *
  * @return mixed              an HTML email with the new user info
  */
 protected static function new_user_notification($user = 0, $password = '')
 {
     // check if we recieved just the user ID and fetch the object
     if (is_numeric($user) && !is_object($user)) {
         $user = new WP_User($user);
     }
     // bail if somehow we didn't get a valid user object
     if (!is_object($user)) {
         return false;
     }
     // get our email content type
     $email_type = apply_filters('tempadmin_email_content_type', 'html');
     // fetch the site info, which we need for the email
     $sitedata = TempAdminUser_Utilities::get_site_data();
     // switch to HTML format unless otherwise told
     if ($email_type == 'html') {
         add_filter('wp_mail_content_type', array(__CLASS__, 'set_html_content_type'));
     }
     // construct email headers
     $headers = 'From: ' . esc_attr($sitedata['site-name']) . ' <' . sanitize_email($sitedata['admin-email']) . '>' . "\r\n";
     $headers .= 'Return-Path: ' . sanitize_email($sitedata['admin-email']) . "\r\n";
     // add the additional headers for HTML email
     if ($email_type == 'html') {
         $headers .= 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-Type: text/html; charset="UTF-8"' . "\r\n";
     }
     // set my email subject
     $subject = apply_filters('tempadmin_email_subject', __('New User Account', 'temporary-admin-user'));
     // get my user content
     $content = TempAdminUser_Layout::generate_email_content($user, $password, $sitedata);
     // and send the email
     wp_mail(sanitize_email($user->user_email), $subject, $content, $headers);
     // reset the email content type (if originally set )
     if ($email_type == 'html') {
         remove_filter('wp_mail_content_type', array(__CLASS__, 'set_html_content_type'));
     }
     // and return
     return;
 }