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


Generated : Sun Mar 7 08:20:02 2021 Cross-referenced by PHPXref