Пример #1
0
 /**
  * Send a password reset code via email
  *
  * @param WP_User $user_data
  * @return true|WP_Error True if mail was sent, or WP_Error on error
  */
 private static function send_reset_code($user_data)
 {
     if (!$user_data instanceof \WP_User) {
         return new \WP_Error('internal_error', __('An internal program error has occured. Your request cannot be complied with. Please inform us.', 'YALW'), 'error');
     }
     if (!Handlers::get_retrieval_key($user_data)) {
         return new \WP_Error('internal_error', __('An internal program error has occured. Your request cannot be complied with. Please inform us.', 'YALW'), 'error');
     }
     $blogname = Handlers::get_blogname();
     $title = Handlers::create_mail_title($blogname);
     $db_code = Handlers::get_retrieval_code($user_data->user_login);
     if (empty($db_code)) {
         // could not get the code from the database
         return new \WP_error('unknown_error', __('There seems to be a problem with our database. Sorry. Please try again later.', 'YALW'), 'error');
     }
     $message = Handlers::get_password_retrieval_message($user_data->user_login, $db_code);
     if (!wp_mail($user_data->user_email, wp_specialchars_decode($title), $message)) {
         return new \WP_error('email_not_sent', __('The e-mail could not be sent.', 'YALW') . '<br />' . __('Possible reason: your host may have disabled the mail() function.', 'YALW'), 'error');
     } else {
         Session::clean_code_error_count();
         return true;
     }
 }