Exemplo n.º 1
0
 /**
  * Sign on the user from YALW
  *
  * @param string $login user login
  * @param string $password user password
  * @param bool $rememberme indicates, if Wordpress should remember the user
  * @return WP_Error WP_Error on error
  */
 static function sign_on($login, $password, $rememberme = true)
 {
     if (!is_string($login)) {
         return new \WP_Error('internal_error', __('An internal program error has occured. Your request cannot be complied with. Please inform us.', 'YALW'), 'error');
     }
     if (!is_string($password)) {
         return new \WP_Error('internal_error', __('An internal program error has occured. Your request cannot be complied with. Please inform us.', 'YALW'), 'error');
     }
     if (!is_bool($rememberme)) {
         $rememberme = false;
     }
     // These lines are needed for working with BuddyPress
     if (!username_exists($login)) {
         return new \WP_Error('login_failure', __('There seems to be something wrong with the username or password.', 'YALW'), 'warn');
     }
     $YALW_credentials = array('user_login' => $login, 'user_password' => $password, 'remember' => $rememberme);
     $user = wp_signon($YALW_credentials, true);
     if ($user instanceof \WP_Error) {
         return new \WP_Error('login_failure', __('There seems to be something wrong with the username or password.', 'YALW'), 'warn');
     } else {
         wp_set_auth_cookie($user->ID);
         // remove our GET-Variable if user logs in after password retrieval
         wp_redirect(Handlers::remove_get_from_uri($_POST['YALW_redirect']));
         exit;
     }
 }