[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/ -> wp-login.php (source)

   1  <?php
   2  /**
   3   * WordPress User Page
   4   *
   5   * Handles authentication, registering, resetting passwords, forgot password,
   6   * and other user handling.
   7   *
   8   * @package WordPress
   9   */
  10  
  11  /** Make sure that the WordPress bootstrap has run before continuing. */
  12  require  __DIR__ . '/wp-load.php';
  13  
  14  // Redirect to HTTPS login if forced to use SSL.
  15  if ( force_ssl_admin() && ! is_ssl() ) {
  16      if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
  17          wp_safe_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
  18          exit;
  19      } else {
  20          wp_safe_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  21          exit;
  22      }
  23  }
  24  
  25  /**
  26   * Output the login page header.
  27   *
  28   * @since 2.1.0
  29   *
  30   * @global string      $error         Login error message set by deprecated pluggable wp_login() function
  31   *                                    or plugins replacing it.
  32   * @global bool|string $interim_login Whether interim login modal is being displayed. String 'success'
  33   *                                    upon successful login.
  34   * @global string      $action        The action that brought the visitor to the login page.
  35   *
  36   * @param string   $title    Optional. WordPress login Page title to display in the `<title>` element.
  37   *                           Default 'Log In'.
  38   * @param string   $message  Optional. Message to display in header. Default empty.
  39   * @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance.
  40   */
  41  function login_header( $title = 'Log In', $message = '', $wp_error = null ) {
  42      global $error, $interim_login, $action;
  43  
  44      // Don't index any of these forms.
  45      add_action( 'login_head', 'wp_sensitive_page_meta' );
  46  
  47      add_action( 'login_head', 'wp_login_viewport_meta' );
  48  
  49      if ( ! is_wp_error( $wp_error ) ) {
  50          $wp_error = new WP_Error();
  51      }
  52  
  53      // Shake it!
  54      $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password', 'retrieve_password_email_failure' );
  55      /**
  56       * Filters the error codes array for shaking the login form.
  57       *
  58       * @since 3.0.0
  59       *
  60       * @param array $shake_error_codes Error codes that shake the login form.
  61       */
  62      $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
  63  
  64      if ( $shake_error_codes && $wp_error->has_errors() && in_array( $wp_error->get_error_code(), $shake_error_codes, true ) ) {
  65          add_action( 'login_footer', 'wp_shake_js', 12 );
  66      }
  67  
  68      $login_title = get_bloginfo( 'name', 'display' );
  69  
  70      /* translators: Login screen title. 1: Login screen name, 2: Network or site name. */
  71      $login_title = sprintf( __( '%1$s &lsaquo; %2$s &#8212; WordPress' ), $title, $login_title );
  72  
  73      if ( wp_is_recovery_mode() ) {
  74          /* translators: %s: Login screen title. */
  75          $login_title = sprintf( __( 'Recovery Mode &#8212; %s' ), $login_title );
  76      }
  77  
  78      /**
  79       * Filters the title tag content for login page.
  80       *
  81       * @since 4.9.0
  82       *
  83       * @param string $login_title The page title, with extra context added.
  84       * @param string $title       The original page title.
  85       */
  86      $login_title = apply_filters( 'login_title', $login_title, $title );
  87  
  88      ?><!DOCTYPE html>
  89      <html <?php language_attributes(); ?>>
  90      <head>
  91      <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
  92      <title><?php echo $login_title; ?></title>
  93      <?php
  94  
  95      wp_enqueue_style( 'login' );
  96  
  97      /*
  98       * Remove all stored post data on logging out.
  99       * This could be added by add_action('login_head'...) like wp_shake_js(),
 100       * but maybe better if it's not removable by plugins.
 101       */
 102      if ( 'loggedout' === $wp_error->get_error_code() ) {
 103          ?>
 104          <script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script>
 105          <?php
 106      }
 107  
 108      /**
 109       * Enqueue scripts and styles for the login page.
 110       *
 111       * @since 3.1.0
 112       */
 113      do_action( 'login_enqueue_scripts' );
 114  
 115      /**
 116       * Fires in the login page header after scripts are enqueued.
 117       *
 118       * @since 2.1.0
 119       */
 120      do_action( 'login_head' );
 121  
 122      $login_header_url = __( 'https://wordpress.org/' );
 123  
 124      /**
 125       * Filters link URL of the header logo above login form.
 126       *
 127       * @since 2.1.0
 128       *
 129       * @param string $login_header_url Login header logo URL.
 130       */
 131      $login_header_url = apply_filters( 'login_headerurl', $login_header_url );
 132  
 133      $login_header_title = '';
 134  
 135      /**
 136       * Filters the title attribute of the header logo above login form.
 137       *
 138       * @since 2.1.0
 139       * @deprecated 5.2.0 Use {@see 'login_headertext'} instead.
 140       *
 141       * @param string $login_header_title Login header logo title attribute.
 142       */
 143      $login_header_title = apply_filters_deprecated(
 144          'login_headertitle',
 145          array( $login_header_title ),
 146          '5.2.0',
 147          'login_headertext',
 148          __( 'Usage of the title attribute on the login logo is not recommended for accessibility reasons. Use the link text instead.' )
 149      );
 150  
 151      $login_header_text = empty( $login_header_title ) ? __( 'Powered by WordPress' ) : $login_header_title;
 152  
 153      /**
 154       * Filters the link text of the header logo above the login form.
 155       *
 156       * @since 5.2.0
 157       *
 158       * @param string $login_header_text The login header logo link text.
 159       */
 160      $login_header_text = apply_filters( 'login_headertext', $login_header_text );
 161  
 162      $classes = array( 'login-action-' . $action, 'wp-core-ui' );
 163  
 164      if ( is_rtl() ) {
 165          $classes[] = 'rtl';
 166      }
 167  
 168      if ( $interim_login ) {
 169          $classes[] = 'interim-login';
 170  
 171          ?>
 172          <style type="text/css">html{background-color: transparent;}</style>
 173          <?php
 174  
 175          if ( 'success' === $interim_login ) {
 176              $classes[] = 'interim-login-success';
 177          }
 178      }
 179  
 180      $classes[] = ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
 181  
 182      /**
 183       * Filters the login page body classes.
 184       *
 185       * @since 3.5.0
 186       *
 187       * @param array  $classes An array of body classes.
 188       * @param string $action  The action that brought the visitor to the login page.
 189       */
 190      $classes = apply_filters( 'login_body_class', $classes, $action );
 191  
 192      ?>
 193      </head>
 194      <body class="login no-js <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
 195      <script type="text/javascript">
 196          document.body.className = document.body.className.replace('no-js','js');
 197      </script>
 198      <?php
 199      /**
 200       * Fires in the login page header after the body tag is opened.
 201       *
 202       * @since 4.6.0
 203       */
 204      do_action( 'login_header' );
 205  
 206      ?>
 207      <div id="login">
 208          <h1><a href="<?php echo esc_url( $login_header_url ); ?>"><?php echo $login_header_text; ?></a></h1>
 209      <?php
 210      /**
 211       * Filters the message to display above the login form.
 212       *
 213       * @since 2.1.0
 214       *
 215       * @param string $message Login message text.
 216       */
 217      $message = apply_filters( 'login_message', $message );
 218  
 219      if ( ! empty( $message ) ) {
 220          echo $message . "\n";
 221      }
 222  
 223      // In case a plugin uses $error rather than the $wp_errors object.
 224      if ( ! empty( $error ) ) {
 225          $wp_error->add( 'error', $error );
 226          unset( $error );
 227      }
 228  
 229      if ( $wp_error->has_errors() ) {
 230          $errors   = '';
 231          $messages = '';
 232  
 233          foreach ( $wp_error->get_error_codes() as $code ) {
 234              $severity = $wp_error->get_error_data( $code );
 235              foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
 236                  if ( 'message' === $severity ) {
 237                      $messages .= '    ' . $error_message . "<br />\n";
 238                  } else {
 239                      $errors .= '    ' . $error_message . "<br />\n";
 240                  }
 241              }
 242          }
 243  
 244          if ( ! empty( $errors ) ) {
 245              /**
 246               * Filters the error messages displayed above the login form.
 247               *
 248               * @since 2.1.0
 249               *
 250               * @param string $errors Login error message.
 251               */
 252              echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
 253          }
 254  
 255          if ( ! empty( $messages ) ) {
 256              /**
 257               * Filters instructional messages displayed above the login form.
 258               *
 259               * @since 2.5.0
 260               *
 261               * @param string $messages Login messages.
 262               */
 263              echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
 264          }
 265      }
 266  } // End of login_header().
 267  
 268  /**
 269   * Outputs the footer for the login page.
 270   *
 271   * @since 3.1.0
 272   *
 273   * @global bool|string $interim_login Whether interim login modal is being displayed. String 'success'
 274   *                                    upon successful login.
 275   *
 276   * @param string $input_id Which input to auto-focus.
 277   */
 278  function login_footer( $input_id = '' ) {
 279      global $interim_login;
 280  
 281      // Don't allow interim logins to navigate away from the page.
 282      if ( ! $interim_login ) {
 283          ?>
 284          <p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>">
 285          <?php
 286  
 287          /* translators: %s: Site title. */
 288          printf( _x( '&larr; Back to %s', 'site' ), get_bloginfo( 'title', 'display' ) );
 289  
 290          ?>
 291          </a></p>
 292          <?php
 293  
 294          the_privacy_policy_link( '<div class="privacy-policy-page-link">', '</div>' );
 295      }
 296  
 297      ?>
 298      </div><?php // End of <div id="login">. ?>
 299  
 300      <?php
 301  
 302      if ( ! empty( $input_id ) ) {
 303          ?>
 304          <script type="text/javascript">
 305          try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
 306          if(typeof wpOnload=='function')wpOnload();
 307          </script>
 308          <?php
 309      }
 310  
 311      /**
 312       * Fires in the login page footer.
 313       *
 314       * @since 3.1.0
 315       */
 316      do_action( 'login_footer' );
 317  
 318      ?>
 319      <div class="clear"></div>
 320      </body>
 321      </html>
 322      <?php
 323  }
 324  
 325  /**
 326   * Outputs the Javascript to handle the form shaking on the login page.
 327   *
 328   * @since 3.0.0
 329   */
 330  function wp_shake_js() {
 331      ?>
 332      <script type="text/javascript">
 333      document.querySelector('form').classList.add('shake');
 334      </script>
 335      <?php
 336  }
 337  
 338  /**
 339   * Outputs the viewport meta tag for the login page.
 340   *
 341   * @since 3.7.0
 342   */
 343  function wp_login_viewport_meta() {
 344      ?>
 345      <meta name="viewport" content="width=device-width" />
 346      <?php
 347  }
 348  
 349  /**
 350   * Handles sending a password retrieval email to a user.
 351   *
 352   * @since 2.5.0
 353   *
 354   * @return true|WP_Error True when finished, WP_Error object on error.
 355   */
 356  function retrieve_password() {
 357      $errors    = new WP_Error();
 358      $user_data = false;
 359  
 360      if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) {
 361          $errors->add( 'empty_username', __( '<strong>Error</strong>: Please enter a username or email address.' ) );
 362      } elseif ( strpos( $_POST['user_login'], '@' ) ) {
 363          $user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) );
 364          if ( empty( $user_data ) ) {
 365              $errors->add( 'invalid_email', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
 366          }
 367      } else {
 368          $login     = trim( wp_unslash( $_POST['user_login'] ) );
 369          $user_data = get_user_by( 'login', $login );
 370      }
 371  
 372      /**
 373       * Fires before errors are returned from a password reset request.
 374       *
 375       * @since 2.1.0
 376       * @since 4.4.0 Added the `$errors` parameter.
 377       * @since 5.4.0 Added the `$user_data` parameter.
 378       *
 379       * @param WP_Error      $errors    A WP_Error object containing any errors generated
 380       *                                 by using invalid credentials.
 381       * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
 382       */
 383      do_action( 'lostpassword_post', $errors, $user_data );
 384  
 385      /**
 386       * Filters the errors encountered on a password reset request.
 387       *
 388       * The filtered WP_Error object may, for example, contain errors for an invalid
 389       * username or email address. A WP_Error object should always be returned,
 390       * but may or may not contain errors.
 391       *
 392       * If any errors are present in $errors, this will abort the password reset request.
 393       *
 394       * @since 5.5.0
 395       *
 396       * @param WP_Error      $errors    A WP_Error object containing any errors generated
 397       *                                 by using invalid credentials.
 398       * @param WP_User|false $user_data WP_User object if found, false if the user does not exist.
 399       */
 400      $errors = apply_filters( 'lostpassword_errors', $errors, $user_data );
 401  
 402      if ( $errors->has_errors() ) {
 403          return $errors;
 404      }
 405  
 406      if ( ! $user_data ) {
 407          $errors->add( 'invalidcombo', __( '<strong>Error</strong>: There is no account with that username or email address.' ) );
 408          return $errors;
 409      }
 410  
 411      // Redefining user_login ensures we return the right case in the email.
 412      $user_login = $user_data->user_login;
 413      $user_email = $user_data->user_email;
 414      $key        = get_password_reset_key( $user_data );
 415  
 416      if ( is_wp_error( $key ) ) {
 417          return $key;
 418      }
 419  
 420      if ( is_multisite() ) {
 421          $site_name = get_network()->site_name;
 422      } else {
 423          /*
 424           * The blogname option is escaped with esc_html on the way into the database
 425           * in sanitize_option. We want to reverse this for the plain text arena of emails.
 426           */
 427          $site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
 428      }
 429  
 430      $message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n";
 431      /* translators: %s: Site name. */
 432      $message .= sprintf( __( 'Site Name: %s' ), $site_name ) . "\r\n\r\n";
 433      /* translators: %s: User login. */
 434      $message .= sprintf( __( 'Username: %s' ), $user_login ) . "\r\n\r\n";
 435      $message .= __( 'If this was a mistake, ignore this email and nothing will happen.' ) . "\r\n\r\n";
 436      $message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n";
 437      $message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . "\r\n\r\n";
 438  
 439      $requester_ip = $_SERVER['REMOTE_ADDR'];
 440      if ( $requester_ip ) {
 441          $message .= sprintf(
 442              /* translators: %s: IP address of password reset requester. */
 443              __( 'This password reset request originated from the IP address %s.' ),
 444              $requester_ip
 445          ) . "\r\n";
 446      }
 447  
 448      /* translators: Password reset notification email subject. %s: Site title. */
 449      $title = sprintf( __( '[%s] Password Reset' ), $site_name );
 450  
 451      /**
 452       * Filters the subject of the password reset email.
 453       *
 454       * @since 2.8.0
 455       * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
 456       *
 457       * @param string  $title      Email subject.
 458       * @param string  $user_login The username for the user.
 459       * @param WP_User $user_data  WP_User object.
 460       */
 461      $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
 462  
 463      /**
 464       * Filters the message body of the password reset mail.
 465       *
 466       * If the filtered message is empty, the password reset email will not be sent.
 467       *
 468       * @since 2.8.0
 469       * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
 470       *
 471       * @param string  $message    Email message.
 472       * @param string  $key        The activation key.
 473       * @param string  $user_login The username for the user.
 474       * @param WP_User $user_data  WP_User object.
 475       */
 476      $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
 477  
 478      if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
 479          $errors->add(
 480              'retrieve_password_email_failure',
 481              sprintf(
 482                  /* translators: %s: Documentation URL. */
 483                  __( '<strong>Error</strong>: The email could not be sent. Your site may not be correctly configured to send emails. <a href="%s">Get support for resetting your password</a>.' ),
 484                  esc_url( __( 'https://wordpress.org/support/article/resetting-your-password/' ) )
 485              )
 486          );
 487          return $errors;
 488      }
 489  
 490      return true;
 491  }
 492  
 493  //
 494  // Main.
 495  //
 496  
 497  $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login';
 498  $errors = new WP_Error();
 499  
 500  if ( isset( $_GET['key'] ) ) {
 501      $action = 'resetpass';
 502  }
 503  
 504  if ( isset( $_GET['checkemail'] ) ) {
 505      $action = 'checkemail';
 506  }
 507  
 508  $default_actions = array(
 509      'confirm_admin_email',
 510      'postpass',
 511      'logout',
 512      'lostpassword',
 513      'retrievepassword',
 514      'resetpass',
 515      'rp',
 516      'register',
 517      'checkemail',
 518      'confirmaction',
 519      'login',
 520      WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED,
 521  );
 522  
 523  // Validate action so as to default to the login screen.
 524  if ( ! in_array( $action, $default_actions, true ) && false === has_filter( 'login_form_' . $action ) ) {
 525      $action = 'login';
 526  }
 527  
 528  nocache_headers();
 529  
 530  header( 'Content-Type: ' . get_bloginfo( 'html_type' ) . '; charset=' . get_bloginfo( 'charset' ) );
 531  
 532  if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set.
 533      if ( isset( $_SERVER['PATH_INFO'] ) && ( $_SERVER['PATH_INFO'] !== $_SERVER['PHP_SELF'] ) ) {
 534          $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
 535      }
 536  
 537      $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
 538  
 539      if ( get_option( 'siteurl' ) !== $url ) {
 540          update_option( 'siteurl', $url );
 541      }
 542  }
 543  
 544  // Set a cookie now to see if they are supported by the browser.
 545  $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
 546  setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
 547  
 548  if ( SITECOOKIEPATH !== COOKIEPATH ) {
 549      setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
 550  }
 551  
 552  /**
 553   * Fires when the login form is initialized.
 554   *
 555   * @since 3.2.0
 556   */
 557  do_action( 'login_init' );
 558  
 559  /**
 560   * Fires before a specified login form action.
 561   *
 562   * The dynamic portion of the hook name, `$action`, refers to the action
 563   * that brought the visitor to the login form. Actions include 'postpass',
 564   * 'logout', 'lostpassword', etc.
 565   *
 566   * @since 2.8.0
 567   */
 568  do_action( "login_form_{$action}" );
 569  
 570  $http_post     = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
 571  $interim_login = isset( $_REQUEST['interim-login'] );
 572  
 573  /**
 574   * Filters the separator used between login form navigation links.
 575   *
 576   * @since 4.9.0
 577   *
 578   * @param string $login_link_separator The separator used between login form navigation links.
 579   */
 580  $login_link_separator = apply_filters( 'login_link_separator', ' | ' );
 581  
 582  switch ( $action ) {
 583  
 584      case 'confirm_admin_email':
 585          /*
 586           * Note that `is_user_logged_in()` will return false immediately after logging in
 587           * as the current user is not set, see wp-includes/pluggable.php.
 588           * However this action runs on a redirect after logging in.
 589           */
 590          if ( ! is_user_logged_in() ) {
 591              wp_safe_redirect( wp_login_url() );
 592              exit;
 593          }
 594  
 595          if ( ! empty( $_REQUEST['redirect_to'] ) ) {
 596              $redirect_to = $_REQUEST['redirect_to'];
 597          } else {
 598              $redirect_to = admin_url();
 599          }
 600  
 601          if ( current_user_can( 'manage_options' ) ) {
 602              $admin_email = get_option( 'admin_email' );
 603          } else {
 604              wp_safe_redirect( $redirect_to );
 605              exit;
 606          }
 607  
 608          /**
 609           * Filters the interval for dismissing the admin email confirmation screen.
 610           *
 611           * If `0` (zero) is returned, the "Remind me later" link will not be displayed.
 612           *
 613           * @since 5.3.1
 614           *
 615           * @param int $interval Interval time (in seconds). Default is 3 days.
 616           */
 617          $remind_interval = (int) apply_filters( 'admin_email_remind_interval', 3 * DAY_IN_SECONDS );
 618  
 619          if ( ! empty( $_GET['remind_me_later'] ) ) {
 620              if ( ! wp_verify_nonce( $_GET['remind_me_later'], 'remind_me_later_nonce' ) ) {
 621                  wp_safe_redirect( wp_login_url() );
 622                  exit;
 623              }
 624  
 625              if ( $remind_interval > 0 ) {
 626                  update_option( 'admin_email_lifespan', time() + $remind_interval );
 627              }
 628  
 629              $redirect_to = add_query_arg( 'admin_email_remind_later', 1, $redirect_to );
 630              wp_safe_redirect( $redirect_to );
 631              exit;
 632          }
 633  
 634          if ( ! empty( $_POST['correct-admin-email'] ) ) {
 635              if ( ! check_admin_referer( 'confirm_admin_email', 'confirm_admin_email_nonce' ) ) {
 636                  wp_safe_redirect( wp_login_url() );
 637                  exit;
 638              }
 639  
 640              /**
 641               * Filters the interval for redirecting the user to the admin email confirmation screen.
 642               *
 643               * If `0` (zero) is returned, the user will not be redirected.
 644               *
 645               * @since 5.3.0
 646               *
 647               * @param int $interval Interval time (in seconds). Default is 6 months.
 648               */
 649              $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS );
 650  
 651              if ( $admin_email_check_interval > 0 ) {
 652                  update_option( 'admin_email_lifespan', time() + $admin_email_check_interval );
 653              }
 654  
 655              wp_safe_redirect( $redirect_to );
 656              exit;
 657          }
 658  
 659          login_header( __( 'Confirm your administration email' ), '', $errors );
 660  
 661          /**
 662           * Fires before the admin email confirm form.
 663           *
 664           * @since 5.3.0
 665           *
 666           * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid
 667           *                         credentials. Note that the error object may not contain any errors.
 668           */
 669          do_action( 'admin_email_confirm', $errors );
 670  
 671          ?>
 672  
 673          <form class="admin-email-confirm-form" name="admin-email-confirm-form" action="<?php echo esc_url( site_url( 'wp-login.php?action=confirm_admin_email', 'login_post' ) ); ?>" method="post">
 674              <?php
 675              /**
 676               * Fires inside the admin-email-confirm-form form tags, before the hidden fields.
 677               *
 678               * @since 5.3.0
 679               */
 680              do_action( 'admin_email_confirm_form' );
 681  
 682              wp_nonce_field( 'confirm_admin_email', 'confirm_admin_email_nonce' );
 683  
 684              ?>
 685              <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
 686  
 687              <h1 class="admin-email__heading">
 688                  <?php _e( 'Administration email verification' ); ?>
 689              </h1>
 690              <p class="admin-email__details">
 691                  <?php _e( 'Please verify that the <strong>administration email</strong> for this website is still correct.' ); ?>
 692                  <?php
 693  
 694                  /* translators: URL to the WordPress help section about admin email. */
 695                  $admin_email_help_url = __( 'https://wordpress.org/support/article/settings-general-screen/#email-address' );
 696  
 697                  /* translators: Accessibility text. */
 698                  $accessibility_text = sprintf( '<span class="screen-reader-text"> %s</span>', __( '(opens in a new tab)' ) );
 699  
 700                  printf(
 701                      '<a href="%s" rel="noopener" target="_blank">%s%s</a>',
 702                      esc_url( $admin_email_help_url ),
 703                      __( 'Why is this important?' ),
 704                      $accessibility_text
 705                  );
 706  
 707                  ?>
 708              </p>
 709              <p class="admin-email__details">
 710                  <?php
 711  
 712                  printf(
 713                      /* translators: %s: Admin email address. */
 714                      __( 'Current administration email: %s' ),
 715                      '<strong>' . esc_html( $admin_email ) . '</strong>'
 716                  );
 717  
 718                  ?>
 719              </p>
 720              <p class="admin-email__details">
 721                  <?php _e( 'This email may be different from your personal email address.' ); ?>
 722              </p>
 723  
 724              <div class="admin-email__actions">
 725                  <div class="admin-email__actions-primary">
 726                      <?php
 727  
 728                      $change_link = admin_url( 'options-general.php' );
 729                      $change_link = add_query_arg( 'highlight', 'confirm_admin_email', $change_link );
 730  
 731                      ?>
 732                      <a class="button button-large" href="<?php echo esc_url( $change_link ); ?>"><?php _e( 'Update' ); ?></a>
 733                      <input type="submit" name="correct-admin-email" id="correct-admin-email" class="button button-primary button-large" value="<?php esc_attr_e( 'The email is correct' ); ?>" />
 734                  </div>
 735                  <?php if ( $remind_interval > 0 ) : ?>
 736                      <div class="admin-email__actions-secondary">
 737                          <?php
 738  
 739                          $remind_me_link = wp_login_url( $redirect_to );
 740                          $remind_me_link = add_query_arg(
 741                              array(
 742                                  'action'          => 'confirm_admin_email',
 743                                  'remind_me_later' => wp_create_nonce( 'remind_me_later_nonce' ),
 744                              ),
 745                              $remind_me_link
 746                          );
 747  
 748                          ?>
 749                          <a href="<?php echo esc_url( $remind_me_link ); ?>"><?php _e( 'Remind me later' ); ?></a>
 750                      </div>
 751                  <?php endif; ?>
 752              </div>
 753          </form>
 754  
 755          <?php
 756  
 757          login_footer();
 758          break;
 759  
 760      case 'postpass':
 761          if ( ! array_key_exists( 'post_password', $_POST ) ) {
 762              wp_safe_redirect( wp_get_referer() );
 763              exit;
 764          }
 765  
 766          require_once  ABSPATH . WPINC . '/class-phpass.php';
 767          $hasher = new PasswordHash( 8, true );
 768  
 769          /**
 770           * Filters the life span of the post password cookie.
 771           *
 772           * By default, the cookie expires 10 days from creation. To turn this
 773           * into a session cookie, return 0.
 774           *
 775           * @since 3.7.0
 776           *
 777           * @param int $expires The expiry time, as passed to setcookie().
 778           */
 779          $expire  = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
 780          $referer = wp_get_referer();
 781  
 782          if ( $referer ) {
 783              $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
 784          } else {
 785              $secure = false;
 786          }
 787  
 788          setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
 789  
 790          wp_safe_redirect( wp_get_referer() );
 791          exit;
 792  
 793      case 'logout':
 794          check_admin_referer( 'log-out' );
 795  
 796          $user = wp_get_current_user();
 797  
 798          wp_logout();
 799  
 800          if ( ! empty( $_REQUEST['redirect_to'] ) ) {
 801              $redirect_to           = $_REQUEST['redirect_to'];
 802              $requested_redirect_to = $redirect_to;
 803          } else {
 804              $redirect_to = add_query_arg(
 805                  array(
 806                      'loggedout' => 'true',
 807                      'wp_lang'   => get_user_locale( $user ),
 808                  ),
 809                  wp_login_url()
 810              );
 811  
 812              $requested_redirect_to = '';
 813          }
 814  
 815          /**
 816           * Filters the log out redirect URL.
 817           *
 818           * @since 4.2.0
 819           *
 820           * @param string  $redirect_to           The redirect destination URL.
 821           * @param string  $requested_redirect_to The requested redirect destination URL passed as a parameter.
 822           * @param WP_User $user                  The WP_User object for the user that's logging out.
 823           */
 824          $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
 825  
 826          wp_safe_redirect( $redirect_to );
 827          exit;
 828  
 829      case 'lostpassword':
 830      case 'retrievepassword':
 831          if ( $http_post ) {
 832              $errors = retrieve_password();
 833  
 834              if ( ! is_wp_error( $errors ) ) {
 835                  $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm';
 836                  wp_safe_redirect( $redirect_to );
 837                  exit;
 838              }
 839          }
 840  
 841          if ( isset( $_GET['error'] ) ) {
 842              if ( 'invalidkey' === $_GET['error'] ) {
 843                  $errors->add( 'invalidkey', __( 'Your password reset link appears to be invalid. Please request a new link below.' ) );
 844              } elseif ( 'expiredkey' === $_GET['error'] ) {
 845                  $errors->add( 'expiredkey', __( 'Your password reset link has expired. Please request a new link below.' ) );
 846              }
 847          }
 848  
 849          $lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
 850          /**
 851           * Filters the URL redirected to after submitting the lostpassword/retrievepassword form.
 852           *
 853           * @since 3.0.0
 854           *
 855           * @param string $lostpassword_redirect The redirect destination URL.
 856           */
 857          $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
 858  
 859          /**
 860           * Fires before the lost password form.
 861           *
 862           * @since 1.5.1
 863           * @since 5.1.0 Added the `$errors` parameter.
 864           *
 865           * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid
 866           *                         credentials. Note that the error object may not contain any errors.
 867           */
 868          do_action( 'lost_password', $errors );
 869  
 870          login_header( __( 'Lost Password' ), '<p class="message">' . __( 'Please enter your username or email address. You will receive an email message with instructions on how to reset your password.' ) . '</p>', $errors );
 871  
 872          $user_login = '';
 873  
 874          if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
 875              $user_login = wp_unslash( $_POST['user_login'] );
 876          }
 877  
 878          ?>
 879  
 880          <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
 881              <p>
 882                  <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
 883                  <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
 884              </p>
 885              <?php
 886  
 887              /**
 888               * Fires inside the lostpassword form tags, before the hidden fields.
 889               *
 890               * @since 2.1.0
 891               */
 892              do_action( 'lostpassword_form' );
 893  
 894              ?>
 895              <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
 896              <p class="submit">
 897                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Get New Password' ); ?>" />
 898              </p>
 899          </form>
 900  
 901          <p id="nav">
 902              <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
 903              <?php
 904  
 905              if ( get_option( 'users_can_register' ) ) {
 906                  $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
 907  
 908                  echo esc_html( $login_link_separator );
 909  
 910                  /** This filter is documented in wp-includes/general-template.php */
 911                  echo apply_filters( 'register', $registration_url );
 912              }
 913  
 914              ?>
 915          </p>
 916          <?php
 917  
 918          login_footer( 'user_login' );
 919          break;
 920  
 921      case 'resetpass':
 922      case 'rp':
 923          list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
 924          $rp_cookie       = 'wp-resetpass-' . COOKIEHASH;
 925  
 926          if ( isset( $_GET['key'] ) ) {
 927              $value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
 928              setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 929  
 930              wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
 931              exit;
 932          }
 933  
 934          if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
 935              list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
 936  
 937              $user = check_password_reset_key( $rp_key, $rp_login );
 938  
 939              if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, $_POST['rp_key'] ) ) {
 940                  $user = false;
 941              }
 942          } else {
 943              $user = false;
 944          }
 945  
 946          if ( ! $user || is_wp_error( $user ) ) {
 947              setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 948  
 949              if ( $user && $user->get_error_code() === 'expired_key' ) {
 950                  wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
 951              } else {
 952                  wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) );
 953              }
 954  
 955              exit;
 956          }
 957  
 958          $errors = new WP_Error();
 959  
 960          if ( isset( $_POST['pass1'] ) && $_POST['pass1'] !== $_POST['pass2'] ) {
 961              $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
 962          }
 963  
 964          /**
 965           * Fires before the password reset procedure is validated.
 966           *
 967           * @since 3.5.0
 968           *
 969           * @param WP_Error         $errors WP Error object.
 970           * @param WP_User|WP_Error $user   WP_User object if the login and reset key match. WP_Error object otherwise.
 971           */
 972          do_action( 'validate_password_reset', $errors, $user );
 973  
 974          if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
 975              reset_password( $user, $_POST['pass1'] );
 976              setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 977              login_header( __( 'Password Reset' ), '<p class="message reset-pass">' . __( 'Your password has been reset.' ) . ' <a href="' . esc_url( wp_login_url() ) . '">' . __( 'Log in' ) . '</a></p>' );
 978              login_footer();
 979              exit;
 980          }
 981  
 982          wp_enqueue_script( 'utils' );
 983          wp_enqueue_script( 'user-profile' );
 984  
 985          login_header( __( 'Reset Password' ), '<p class="message reset-pass">' . __( 'Enter your new password below.' ) . '</p>', $errors );
 986  
 987          ?>
 988          <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
 989              <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
 990  
 991              <div class="user-pass1-wrap">
 992                  <p>
 993                      <label for="pass1"><?php _e( 'New password' ); ?></label>
 994                  </p>
 995  
 996                  <div class="wp-pwd">
 997                      <input type="password" data-reveal="1" data-pw="<?php echo esc_attr( wp_generate_password( 16 ) ); ?>" name="pass1" id="pass1" class="input password-input" size="24" value="" autocomplete="off" aria-describedby="pass-strength-result" />
 998  
 999                      <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
1000                          <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
1001                      </button>
1002                      <div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e( 'Strength indicator' ); ?></div>
1003                  </div>
1004                  <div class="pw-weak">
1005                      <input type="checkbox" name="pw_weak" id="pw-weak" class="pw-checkbox" />
1006                      <label for="pw-weak"><?php _e( 'Confirm use of weak password' ); ?></label>
1007                  </div>
1008              </div>
1009  
1010              <p class="user-pass2-wrap">
1011                  <label for="pass2"><?php _e( 'Confirm new password' ); ?></label>
1012                  <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" />
1013              </p>
1014  
1015              <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
1016              <br class="clear" />
1017  
1018              <?php
1019  
1020              /**
1021               * Fires following the 'Strength indicator' meter in the user password reset form.
1022               *
1023               * @since 3.9.0
1024               *
1025               * @param WP_User $user User object of the user whose password is being reset.
1026               */
1027              do_action( 'resetpass_form', $user );
1028  
1029              ?>
1030              <input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" />
1031              <p class="submit">
1032                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Reset Password' ); ?>" />
1033              </p>
1034          </form>
1035  
1036          <p id="nav">
1037              <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
1038              <?php
1039  
1040              if ( get_option( 'users_can_register' ) ) {
1041                  $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
1042  
1043                  echo esc_html( $login_link_separator );
1044  
1045                  /** This filter is documented in wp-includes/general-template.php */
1046                  echo apply_filters( 'register', $registration_url );
1047              }
1048  
1049              ?>
1050          </p>
1051          <?php
1052  
1053          login_footer( 'user_pass' );
1054          break;
1055  
1056      case 'register':
1057          if ( is_multisite() ) {
1058              /**
1059               * Filters the Multisite sign up URL.
1060               *
1061               * @since 3.0.0
1062               *
1063               * @param string $sign_up_url The sign up URL.
1064               */
1065              wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) );
1066              exit;
1067          }
1068  
1069          if ( ! get_option( 'users_can_register' ) ) {
1070              wp_redirect( site_url( 'wp-login.php?registration=disabled' ) );
1071              exit;
1072          }
1073  
1074          $user_login = '';
1075          $user_email = '';
1076  
1077          if ( $http_post ) {
1078              if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
1079                  $user_login = wp_unslash( $_POST['user_login'] );
1080              }
1081  
1082              if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) {
1083                  $user_email = wp_unslash( $_POST['user_email'] );
1084              }
1085  
1086              $errors = register_new_user( $user_login, $user_email );
1087  
1088              if ( ! is_wp_error( $errors ) ) {
1089                  $redirect_to = ! empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
1090                  wp_safe_redirect( $redirect_to );
1091                  exit;
1092              }
1093          }
1094  
1095          $registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
1096  
1097          /**
1098           * Filters the registration redirect URL.
1099           *
1100           * @since 3.0.0
1101           *
1102           * @param string $registration_redirect The redirect destination URL.
1103           */
1104          $redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
1105  
1106          login_header( __( 'Registration Form' ), '<p class="message register">' . __( 'Register For This Site' ) . '</p>', $errors );
1107  
1108          ?>
1109          <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
1110              <p>
1111                  <label for="user_login"><?php _e( 'Username' ); ?></label>
1112                  <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( wp_unslash( $user_login ) ); ?>" size="20" autocapitalize="off" />
1113              </p>
1114              <p>
1115                  <label for="user_email"><?php _e( 'Email' ); ?></label>
1116                  <input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" />
1117              </p>
1118              <?php
1119  
1120              /**
1121               * Fires following the 'Email' field in the user registration form.
1122               *
1123               * @since 2.1.0
1124               */
1125              do_action( 'register_form' );
1126  
1127              ?>
1128              <p id="reg_passmail">
1129                  <?php _e( 'Registration confirmation will be emailed to you.' ); ?>
1130              </p>
1131              <br class="clear" />
1132              <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
1133              <p class="submit">
1134                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Register' ); ?>" />
1135              </p>
1136          </form>
1137  
1138          <p id="nav">
1139              <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
1140                  <?php echo esc_html( $login_link_separator ); ?>
1141              <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
1142          </p>
1143          <?php
1144  
1145          login_footer( 'user_login' );
1146          break;
1147  
1148      case 'checkemail':
1149          $redirect_to = admin_url();
1150          $errors      = new WP_Error();
1151  
1152          if ( 'confirm' === $_GET['checkemail'] ) {
1153              $errors->add(
1154                  'confirm',
1155                  sprintf(
1156                      /* translators: %s: Link to the login page. */
1157                      __( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ),
1158                      wp_login_url()
1159                  ),
1160                  'message'
1161              );
1162          } elseif ( 'registered' === $_GET['checkemail'] ) {
1163              $errors->add(
1164                  'registered',
1165                  sprintf(
1166                      /* translators: %s: Link to the login page. */
1167                      __( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ),
1168                      wp_login_url()
1169                  ),
1170                  'message'
1171              );
1172          }
1173  
1174          /** This action is documented in wp-login.php */
1175          $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
1176  
1177          login_header( __( 'Check your email' ), '', $errors );
1178          login_footer();
1179          break;
1180  
1181      case 'confirmaction':
1182          if ( ! isset( $_GET['request_id'] ) ) {
1183              wp_die( __( 'Missing request ID.' ) );
1184          }
1185  
1186          if ( ! isset( $_GET['confirm_key'] ) ) {
1187              wp_die( __( 'Missing confirm key.' ) );
1188          }
1189  
1190          $request_id = (int) $_GET['request_id'];
1191          $key        = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) );
1192          $result     = wp_validate_user_request_key( $request_id, $key );
1193  
1194          if ( is_wp_error( $result ) ) {
1195              wp_die( $result );
1196          }
1197  
1198          /**
1199           * Fires an action hook when the account action has been confirmed by the user.
1200           *
1201           * Using this you can assume the user has agreed to perform the action by
1202           * clicking on the link in the confirmation email.
1203           *
1204           * After firing this action hook the page will redirect to wp-login a callback
1205           * redirects or exits first.
1206           *
1207           * @since 4.9.6
1208           *
1209           * @param int $request_id Request ID.
1210           */
1211          do_action( 'user_request_action_confirmed', $request_id );
1212  
1213          $message = _wp_privacy_account_request_confirmed_message( $request_id );
1214  
1215          login_header( __( 'User action confirmed.' ), $message );
1216          login_footer();
1217          exit;
1218  
1219      case 'login':
1220      default:
1221          $secure_cookie   = '';
1222          $customize_login = isset( $_REQUEST['customize-login'] );
1223  
1224          if ( $customize_login ) {
1225              wp_enqueue_script( 'customize-base' );
1226          }
1227  
1228          // If the user wants SSL but the session is not SSL, force a secure cookie.
1229          if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
1230              $user_name = sanitize_user( wp_unslash( $_POST['log'] ) );
1231              $user      = get_user_by( 'login', $user_name );
1232  
1233              if ( ! $user && strpos( $user_name, '@' ) ) {
1234                  $user = get_user_by( 'email', $user_name );
1235              }
1236  
1237              if ( $user ) {
1238                  if ( get_user_option( 'use_ssl', $user->ID ) ) {
1239                      $secure_cookie = true;
1240                      force_ssl_admin( true );
1241                  }
1242              }
1243          }
1244  
1245          if ( isset( $_REQUEST['redirect_to'] ) ) {
1246              $redirect_to = $_REQUEST['redirect_to'];
1247              // Redirect to HTTPS if user wants SSL.
1248              if ( $secure_cookie && false !== strpos( $redirect_to, 'wp-admin' ) ) {
1249                  $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to );
1250              }
1251          } else {
1252              $redirect_to = admin_url();
1253          }
1254  
1255          $reauth = empty( $_REQUEST['reauth'] ) ? false : true;
1256  
1257          $user = wp_signon( array(), $secure_cookie );
1258  
1259          if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
1260              if ( headers_sent() ) {
1261                  $user = new WP_Error(
1262                      'test_cookie',
1263                      sprintf(
1264                          /* translators: 1: Browser cookie documentation URL, 2: Support forums URL. */
1265                          __( '<strong>Error</strong>: Cookies are blocked due to unexpected output. For help, please see <a href="%1$s">this documentation</a> or try the <a href="%2$s">support forums</a>.' ),
1266                          __( 'https://wordpress.org/support/article/cookies/' ),
1267                          __( 'https://wordpress.org/support/forums/' )
1268                      )
1269                  );
1270              } elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
1271                  // If cookies are disabled, we can't log in even with a valid user and password.
1272                  $user = new WP_Error(
1273                      'test_cookie',
1274                      sprintf(
1275                          /* translators: %s: Browser cookie documentation URL. */
1276                          __( '<strong>Error</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.' ),
1277                          __( 'https://wordpress.org/support/article/cookies/#enable-cookies-in-your-browser' )
1278                      )
1279                  );
1280              }
1281          }
1282  
1283          $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
1284          /**
1285           * Filters the login redirect URL.
1286           *
1287           * @since 3.0.0
1288           *
1289           * @param string           $redirect_to           The redirect destination URL.
1290           * @param string           $requested_redirect_to The requested redirect destination URL passed as a parameter.
1291           * @param WP_User|WP_Error $user                  WP_User object if login was successful, WP_Error object otherwise.
1292           */
1293          $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
1294  
1295          if ( ! is_wp_error( $user ) && ! $reauth ) {
1296              if ( $interim_login ) {
1297                  $message       = '<p class="message">' . __( 'You have logged in successfully.' ) . '</p>';
1298                  $interim_login = 'success';
1299                  login_header( '', $message );
1300  
1301                  ?>
1302                  </div>
1303                  <?php
1304  
1305                  /** This action is documented in wp-login.php */
1306                  do_action( 'login_footer' );
1307  
1308                  if ( $customize_login ) {
1309                      ?>
1310                      <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
1311                      <?php
1312                  }
1313  
1314                  ?>
1315                  </body></html>
1316                  <?php
1317  
1318                  exit;
1319              }
1320  
1321              // Check if it is time to add a redirect to the admin email confirmation screen.
1322              if ( is_a( $user, 'WP_User' ) && $user->exists() && $user->has_cap( 'manage_options' ) ) {
1323                  $admin_email_lifespan = (int) get_option( 'admin_email_lifespan' );
1324  
1325                  // If `0` (or anything "falsey" as it is cast to int) is returned, the user will not be redirected
1326                  // to the admin email confirmation screen.
1327                  /** This filter is documented in wp-login.php */
1328                  $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS );
1329  
1330                  if ( $admin_email_check_interval > 0 && time() > $admin_email_lifespan ) {
1331                      $redirect_to = add_query_arg(
1332                          array(
1333                              'action'  => 'confirm_admin_email',
1334                              'wp_lang' => get_user_locale( $user ),
1335                          ),
1336                          wp_login_url( $redirect_to )
1337                      );
1338                  }
1339              }
1340  
1341              if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
1342                  // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.
1343                  if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
1344                      $redirect_to = user_admin_url();
1345                  } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
1346                      $redirect_to = get_dashboard_url( $user->ID );
1347                  } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
1348                      $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
1349                  }
1350  
1351                  wp_redirect( $redirect_to );
1352                  exit;
1353              }
1354  
1355              wp_safe_redirect( $redirect_to );
1356              exit;
1357          }
1358  
1359          $errors = $user;
1360          // Clear errors if loggedout is set.
1361          if ( ! empty( $_GET['loggedout'] ) || $reauth ) {
1362              $errors = new WP_Error();
1363          }
1364  
1365          if ( empty( $_POST ) && $errors->get_error_codes() === array( 'empty_username', 'empty_password' ) ) {
1366              $errors = new WP_Error( '', '' );
1367          }
1368  
1369          if ( $interim_login ) {
1370              if ( ! $errors->has_errors() ) {
1371                  $errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' );
1372              }
1373          } else {
1374              // Some parts of this script use the main login form to display a message.
1375              if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] ) {
1376                  $errors->add( 'loggedout', __( 'You are now logged out.' ), 'message' );
1377              } elseif ( isset( $_GET['registration'] ) && 'disabled' === $_GET['registration'] ) {
1378                  $errors->add( 'registerdisabled', __( 'User registration is currently not allowed.' ) );
1379              } elseif ( strpos( $redirect_to, 'about.php?updated' ) ) {
1380                  $errors->add( 'updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
1381              } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) {
1382                  $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' );
1383              } elseif ( isset( $_GET['redirect_to'] ) && false !== strpos( $_GET['redirect_to'], 'wp-admin/authorize-application.php' ) ) {
1384                  $query_component = wp_parse_url( $_GET['redirect_to'], PHP_URL_QUERY );
1385                  parse_str( $query_component, $query );
1386  
1387                  if ( ! empty( $query['app_name'] ) ) {
1388                      /* translators: 1: Website name, 2: Application name. */
1389                      $message = sprintf( 'Please log in to %1$s to authorize %2$s to connect to your account.', get_bloginfo( 'name', 'display' ), '<strong>' . esc_html( $query['app_name'] ) . '</strong>' );
1390                  } else {
1391                      /* translators: %s: Website name. */
1392                      $message = sprintf( 'Please log in to %s to proceed with authorization.', get_bloginfo( 'name', 'display' ) );
1393                  }
1394  
1395                  $errors->add( 'authorize_application', $message, 'message' );
1396              }
1397          }
1398  
1399          /**
1400           * Filters the login page errors.
1401           *
1402           * @since 3.6.0
1403           *
1404           * @param WP_Error $errors      WP Error object.
1405           * @param string   $redirect_to Redirect destination URL.
1406           */
1407          $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
1408  
1409          // Clear any stale cookies.
1410          if ( $reauth ) {
1411              wp_clear_auth_cookie();
1412          }
1413  
1414          login_header( __( 'Log In' ), '', $errors );
1415  
1416          if ( isset( $_POST['log'] ) ) {
1417              $user_login = ( 'incorrect_password' === $errors->get_error_code() || 'empty_password' === $errors->get_error_code() ) ? esc_attr( wp_unslash( $_POST['log'] ) ) : '';
1418          }
1419  
1420          $rememberme = ! empty( $_POST['rememberme'] );
1421  
1422          if ( $errors->has_errors() ) {
1423              $aria_describedby_error = ' aria-describedby="login_error"';
1424          } else {
1425              $aria_describedby_error = '';
1426          }
1427  
1428          wp_enqueue_script( 'user-profile' );
1429          ?>
1430  
1431          <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
1432              <p>
1433                  <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
1434                  <input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
1435              </p>
1436  
1437              <div class="user-pass-wrap">
1438                  <label for="user_pass"><?php _e( 'Password' ); ?></label>
1439                  <div class="wp-pwd">
1440                      <input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input password-input" value="" size="20" />
1441                      <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Show password' ); ?>">
1442                          <span class="dashicons dashicons-visibility" aria-hidden="true"></span>
1443                      </button>
1444                  </div>
1445              </div>
1446              <?php
1447  
1448              /**
1449               * Fires following the 'Password' field in the login form.
1450               *
1451               * @since 2.1.0
1452               */
1453              do_action( 'login_form' );
1454  
1455              ?>
1456              <p class="forgetmenot"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <label for="rememberme"><?php esc_html_e( 'Remember Me' ); ?></label></p>
1457              <p class="submit">
1458                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Log In' ); ?>" />
1459                  <?php
1460  
1461                  if ( $interim_login ) {
1462                      ?>
1463                      <input type="hidden" name="interim-login" value="1" />
1464                      <?php
1465                  } else {
1466                      ?>
1467                      <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
1468                      <?php
1469                  }
1470  
1471                  if ( $customize_login ) {
1472                      ?>
1473                      <input type="hidden" name="customize-login" value="1" />
1474                      <?php
1475                  }
1476  
1477                  ?>
1478                  <input type="hidden" name="testcookie" value="1" />
1479              </p>
1480          </form>
1481  
1482          <?php
1483  
1484          if ( ! $interim_login ) {
1485              ?>
1486              <p id="nav">
1487                  <?php
1488  
1489                  if ( get_option( 'users_can_register' ) ) {
1490                      $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
1491  
1492                      /** This filter is documented in wp-includes/general-template.php */
1493                      echo apply_filters( 'register', $registration_url );
1494  
1495                      echo esc_html( $login_link_separator );
1496                  }
1497  
1498                  ?>
1499                  <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
1500              </p>
1501              <?php
1502          }
1503  
1504          $login_script  = 'function wp_attempt_focus() {';
1505          $login_script .= 'setTimeout( function() {';
1506          $login_script .= 'try {';
1507  
1508          if ( $user_login ) {
1509              $login_script .= 'd = document.getElementById( "user_pass" ); d.value = "";';
1510          } else {
1511              $login_script .= 'd = document.getElementById( "user_login" );';
1512  
1513              if ( $errors->get_error_code() === 'invalid_username' ) {
1514                  $login_script .= 'd.value = "";';
1515              }
1516          }
1517  
1518          $login_script .= 'd.focus(); d.select();';
1519          $login_script .= '} catch( er ) {}';
1520          $login_script .= '}, 200);';
1521          $login_script .= "}\n"; // End of wp_attempt_focus().
1522  
1523          /**
1524           * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
1525           *
1526           * @since 4.8.0
1527           *
1528           * @param bool $print Whether to print the function call. Default true.
1529           */
1530          if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) {
1531              $login_script .= "wp_attempt_focus();\n";
1532          }
1533  
1534          // Run `wpOnload()` if defined.
1535          $login_script .= "if ( typeof wpOnload === 'function' ) { wpOnload() }";
1536  
1537          ?>
1538          <script type="text/javascript">
1539              <?php echo $login_script; ?>
1540          </script>
1541          <?php
1542  
1543          if ( $interim_login ) {
1544              ?>
1545              <script type="text/javascript">
1546              ( function() {
1547                  try {
1548                      var i, links = document.getElementsByTagName( 'a' );
1549                      for ( i in links ) {
1550                          if ( links[i].href ) {
1551                              links[i].target = '_blank';
1552                              links[i].rel = 'noopener';
1553                          }
1554                      }
1555                  } catch( er ) {}
1556              }());
1557              </script>
1558              <?php
1559          }
1560  
1561          login_footer();
1562          break;
1563  } // End action switch.


Generated : Wed Oct 28 08:20:01 2020 Cross-referenced by PHPXref