Example #1
0
 private function forget_password()
 {
     $error_array = array();
     $error_array['authentication'] = array('type' => 'forget_password', 'status' => 'false');
     $db = wpl_db::get_DBO();
     $user_login = wpl_db::sanitize($this->username);
     if (trim($user_login) == '') {
         return $error_array;
     } elseif (strpos($user_login, '@')) {
         $user_data = wpl_users::get_user_by('email', $user_login);
         if (trim($user_data) == '') {
             return $error_array;
         }
     } else {
         $login = trim($user_login);
         $user_data = wpl_users::get_user_by('login', $login);
     }
     do_action('lostpassword_post');
     if (!$user_data) {
         return $this->failed_array;
     }
     $user_login = $user_data->user_login;
     $user_email = $user_data->user_email;
     do_action('retreive_password', $user_login);
     do_action('retrieve_password', $user_login);
     $allow = apply_filters('allow_password_reset', true, $user_data->ID);
     if (is_wp_error($allow)) {
         return $error_array;
     }
     $key = wpl_global::generate_password(20, false);
     do_action('retrieve_password_key', $user_login, $key);
     $hashed = wpl_global::wpl_hasher(8, $key);
     wpl_db::update('users', array('user_activation_key' => $hashed), 'user_login', $user_login);
     $message = __('Someone requested that the password be reset for the following account:', WPL_TEXTDOMAIN) . "\r\n";
     $message .= network_home_url('/') . "\r\n";
     $message .= sprintf(__('Username: %s', WPL_TEXTDOMAIN), $user_login) . "\r\n";
     $message .= __('If this was a mistake, just ignore this email and nothing will happen.', WPL_TEXTDOMAIN) . "\r\n";
     $message .= __('To reset your password, visit the following address:', WPL_TEXTDOMAIN) . "\r\n";
     $message .= '<' . network_site_url("wp-login.php?action=rp&key={$key}&login="******">\r\n";
     if (is_multisite()) {
         $blogname = $GLOBALS['current_site']->site_name;
     } else {
         $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
     }
     $title = sprintf(__('[%s] Password Reset', WPL_TEXTDOMAIN), $blogname);
     $title = apply_filters('retrieve_password_title', $title);
     $message = apply_filters('retrieve_password_message', $message, $key);
     if ($message && !wp_mail($user_email, $title, $message)) {
         return $error_array;
     }
     $this->built['authentication'] = array('type' => 'forget_password', 'status' => 'true');
     return $this->built;
 }