[ Index ]

PHP Cross Reference of WordPress

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.
 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.
 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 password retrieval email to user.
 351   *
 352   * @since 2.5.0
 353   *
 354   * @return bool|WP_Error True: when finish. WP_Error 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, just 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";
 438  
 439      /* translators: Password reset notification email subject. %s: Site title. */
 440      $title = sprintf( __( '[%s] Password Reset' ), $site_name );
 441  
 442      /**
 443       * Filters the subject of the password reset email.
 444       *
 445       * @since 2.8.0
 446       * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
 447       *
 448       * @param string  $title      Default email title.
 449       * @param string  $user_login The username for the user.
 450       * @param WP_User $user_data  WP_User object.
 451       */
 452      $title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
 453  
 454      /**
 455       * Filters the message body of the password reset mail.
 456       *
 457       * If the filtered message is empty, the password reset email will not be sent.
 458       *
 459       * @since 2.8.0
 460       * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
 461       *
 462       * @param string  $message    Default mail message.
 463       * @param string  $key        The activation key.
 464       * @param string  $user_login The username for the user.
 465       * @param WP_User $user_data  WP_User object.
 466       */
 467      $message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
 468  
 469      if ( $message && ! wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) ) {
 470          $errors->add(
 471              'retrieve_password_email_failure',
 472              sprintf(
 473                  /* translators: %s: Documentation URL. */
 474                  __( '<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>.' ),
 475                  esc_url( __( 'https://wordpress.org/support/article/resetting-your-password/' ) )
 476              )
 477          );
 478          return $errors;
 479      }
 480  
 481      return true;
 482  }
 483  
 484  //
 485  // Main.
 486  //
 487  
 488  $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login';
 489  $errors = new WP_Error();
 490  
 491  if ( isset( $_GET['key'] ) ) {
 492      $action = 'resetpass';
 493  }
 494  
 495  if ( isset( $_GET['checkemail'] ) ) {
 496      $action = 'checkemail';
 497  }
 498  
 499  $default_actions = array(
 500      'confirm_admin_email',
 501      'postpass',
 502      'logout',
 503      'lostpassword',
 504      'retrievepassword',
 505      'resetpass',
 506      'rp',
 507      'register',
 508      'checkemail',
 509      'confirmaction',
 510      'login',
 511      WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED,
 512  );
 513  
 514  // Validate action so as to default to the login screen.
 515  if ( ! in_array( $action, $default_actions, true ) && false === has_filter( 'login_form_' . $action ) ) {
 516      $action = 'login';
 517  }
 518  
 519  nocache_headers();
 520  
 521  header( 'Content-Type: ' . get_bloginfo( 'html_type' ) . '; charset=' . get_bloginfo( 'charset' ) );
 522  
 523  if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set.
 524      if ( isset( $_SERVER['PATH_INFO'] ) && ( $_SERVER['PATH_INFO'] !== $_SERVER['PHP_SELF'] ) ) {
 525          $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
 526      }
 527  
 528      $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
 529  
 530      if ( get_option( 'siteurl' ) !== $url ) {
 531          update_option( 'siteurl', $url );
 532      }
 533  }
 534  
 535  // Set a cookie now to see if they are supported by the browser.
 536  $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
 537  setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
 538  
 539  if ( SITECOOKIEPATH !== COOKIEPATH ) {
 540      setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
 541  }
 542  
 543  /**
 544   * Fires when the login form is initialized.
 545   *
 546   * @since 3.2.0
 547   */
 548  do_action( 'login_init' );
 549  
 550  /**
 551   * Fires before a specified login form action.
 552   *
 553   * The dynamic portion of the hook name, `$action`, refers to the action
 554   * that brought the visitor to the login form. Actions include 'postpass',
 555   * 'logout', 'lostpassword', etc.
 556   *
 557   * @since 2.8.0
 558   */
 559  do_action( "login_form_{$action}" );
 560  
 561  $http_post     = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
 562  $interim_login = isset( $_REQUEST['interim-login'] );
 563  
 564  /**
 565   * Filters the separator used between login form navigation links.
 566   *
 567   * @since 4.9.0
 568   *
 569   * @param string $login_link_separator The separator used between login form navigation links.
 570   */
 571  $login_link_separator = apply_filters( 'login_link_separator', ' | ' );
 572  
 573  switch ( $action ) {
 574  
 575      case 'confirm_admin_email':
 576          /*
 577           * Note that `is_user_logged_in()` will return false immediately after logging in
 578           * as the current user is not set, see wp-includes/pluggable.php.
 579           * However this action runs on a redirect after logging in.
 580           */
 581          if ( ! is_user_logged_in() ) {
 582              wp_safe_redirect( wp_login_url() );
 583              exit;
 584          }
 585  
 586          if ( ! empty( $_REQUEST['redirect_to'] ) ) {
 587              $redirect_to = $_REQUEST['redirect_to'];
 588          } else {
 589              $redirect_to = admin_url();
 590          }
 591  
 592          if ( current_user_can( 'manage_options' ) ) {
 593              $admin_email = get_option( 'admin_email' );
 594          } else {
 595              wp_safe_redirect( $redirect_to );
 596              exit;
 597          }
 598  
 599          /**
 600           * Filters the interval for dismissing the admin email confirmation screen.
 601           *
 602           * If `0` (zero) is returned, the "Remind me later" link will not be displayed.
 603           *
 604           * @since 5.3.1
 605           *
 606           * @param int $interval Interval time (in seconds). Default is 3 days.
 607           */
 608          $remind_interval = (int) apply_filters( 'admin_email_remind_interval', 3 * DAY_IN_SECONDS );
 609  
 610          if ( ! empty( $_GET['remind_me_later'] ) ) {
 611              if ( ! wp_verify_nonce( $_GET['remind_me_later'], 'remind_me_later_nonce' ) ) {
 612                  wp_safe_redirect( wp_login_url() );
 613                  exit;
 614              }
 615  
 616              if ( $remind_interval > 0 ) {
 617                  update_option( 'admin_email_lifespan', time() + $remind_interval );
 618              }
 619  
 620              $redirect_to = add_query_arg( 'admin_email_remind_later', 1, $redirect_to );
 621              wp_safe_redirect( $redirect_to );
 622              exit;
 623          }
 624  
 625          if ( ! empty( $_POST['correct-admin-email'] ) ) {
 626              if ( ! check_admin_referer( 'confirm_admin_email', 'confirm_admin_email_nonce' ) ) {
 627                  wp_safe_redirect( wp_login_url() );
 628                  exit;
 629              }
 630  
 631              /**
 632               * Filters the interval for redirecting the user to the admin email confirmation screen.
 633               *
 634               * If `0` (zero) is returned, the user will not be redirected.
 635               *
 636               * @since 5.3.0
 637               *
 638               * @param int $interval Interval time (in seconds). Default is 6 months.
 639               */
 640              $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS );
 641  
 642              if ( $admin_email_check_interval > 0 ) {
 643                  update_option( 'admin_email_lifespan', time() + $admin_email_check_interval );
 644              }
 645  
 646              wp_safe_redirect( $redirect_to );
 647              exit;
 648          }
 649  
 650          login_header( __( 'Confirm your administration email' ), '', $errors );
 651  
 652          /**
 653           * Fires before the admin email confirm form.
 654           *
 655           * @since 5.3.0
 656           *
 657           * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid
 658           *                         credentials. Note that the error object may not contain any errors.
 659           */
 660          do_action( 'admin_email_confirm', $errors );
 661  
 662          ?>
 663  
 664          <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">
 665              <?php
 666              /**
 667               * Fires inside the admin-email-confirm-form form tags, before the hidden fields.
 668               *
 669               * @since 5.3.0
 670               */
 671              do_action( 'admin_email_confirm_form' );
 672  
 673              wp_nonce_field( 'confirm_admin_email', 'confirm_admin_email_nonce' );
 674  
 675              ?>
 676              <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
 677  
 678              <h1 class="admin-email__heading">
 679                  <?php _e( 'Administration email verification' ); ?>
 680              </h1>
 681              <p class="admin-email__details">
 682                  <?php _e( 'Please verify that the <strong>administration email</strong> for this website is still correct.' ); ?>
 683                  <?php
 684  
 685                  /* translators: URL to the WordPress help section about admin email. */
 686                  $admin_email_help_url = __( 'https://wordpress.org/support/article/settings-general-screen/#email-address' );
 687  
 688                  /* translators: accessibility text */
 689                  $accessibility_text = sprintf( '<span class="screen-reader-text"> %s</span>', __( '(opens in a new tab)' ) );
 690  
 691                  printf(
 692                      '<a href="%s" rel="noopener noreferrer" target="_blank">%s%s</a>',
 693                      esc_url( $admin_email_help_url ),
 694                      __( 'Why is this important?' ),
 695                      $accessibility_text
 696                  );
 697  
 698                  ?>
 699              </p>
 700              <p class="admin-email__details">
 701                  <?php
 702  
 703                  printf(
 704                      /* translators: %s: Admin email address. */
 705                      __( 'Current administration email: %s' ),
 706                      '<strong>' . esc_html( $admin_email ) . '</strong>'
 707                  );
 708  
 709                  ?>
 710              </p>
 711              <p class="admin-email__details">
 712                  <?php _e( 'This email may be different from your personal email address.' ); ?>
 713              </p>
 714  
 715              <div class="admin-email__actions">
 716                  <div class="admin-email__actions-primary">
 717                      <?php
 718  
 719                      $change_link = admin_url( 'options-general.php' );
 720                      $change_link = add_query_arg( 'highlight', 'confirm_admin_email', $change_link );
 721  
 722                      ?>
 723                      <a class="button button-large" href="<?php echo esc_url( $change_link ); ?>"><?php _e( 'Update' ); ?></a>
 724                      <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' ); ?>" />
 725                  </div>
 726                  <?php if ( $remind_interval > 0 ) : ?>
 727                      <div class="admin-email__actions-secondary">
 728                          <?php
 729  
 730                          $remind_me_link = wp_login_url( $redirect_to );
 731                          $remind_me_link = add_query_arg(
 732                              array(
 733                                  'action'          => 'confirm_admin_email',
 734                                  'remind_me_later' => wp_create_nonce( 'remind_me_later_nonce' ),
 735                              ),
 736                              $remind_me_link
 737                          );
 738  
 739                          ?>
 740                          <a href="<?php echo esc_url( $remind_me_link ); ?>"><?php _e( 'Remind me later' ); ?></a>
 741                      </div>
 742                  <?php endif; ?>
 743              </div>
 744          </form>
 745  
 746          <?php
 747  
 748          login_footer();
 749          break;
 750  
 751      case 'postpass':
 752          if ( ! array_key_exists( 'post_password', $_POST ) ) {
 753              wp_safe_redirect( wp_get_referer() );
 754              exit;
 755          }
 756  
 757          require_once  ABSPATH . WPINC . '/class-phpass.php';
 758          $hasher = new PasswordHash( 8, true );
 759  
 760          /**
 761           * Filters the life span of the post password cookie.
 762           *
 763           * By default, the cookie expires 10 days from creation. To turn this
 764           * into a session cookie, return 0.
 765           *
 766           * @since 3.7.0
 767           *
 768           * @param int $expires The expiry time, as passed to setcookie().
 769           */
 770          $expire  = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
 771          $referer = wp_get_referer();
 772  
 773          if ( $referer ) {
 774              $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
 775          } else {
 776              $secure = false;
 777          }
 778  
 779          setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
 780  
 781          wp_safe_redirect( wp_get_referer() );
 782          exit;
 783  
 784      case 'logout':
 785          check_admin_referer( 'log-out' );
 786  
 787          $user = wp_get_current_user();
 788  
 789          wp_logout();
 790  
 791          if ( ! empty( $_REQUEST['redirect_to'] ) ) {
 792              $redirect_to           = $_REQUEST['redirect_to'];
 793              $requested_redirect_to = $redirect_to;
 794          } else {
 795              $redirect_to = add_query_arg(
 796                  array(
 797                      'loggedout' => 'true',
 798                      'wp_lang'   => get_user_locale( $user ),
 799                  ),
 800                  wp_login_url()
 801              );
 802  
 803              $requested_redirect_to = '';
 804          }
 805  
 806          /**
 807           * Filters the log out redirect URL.
 808           *
 809           * @since 4.2.0
 810           *
 811           * @param string  $redirect_to           The redirect destination URL.
 812           * @param string  $requested_redirect_to The requested redirect destination URL passed as a parameter.
 813           * @param WP_User $user                  The WP_User object for the user that's logging out.
 814           */
 815          $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
 816  
 817          wp_safe_redirect( $redirect_to );
 818          exit;
 819  
 820      case 'lostpassword':
 821      case 'retrievepassword':
 822          if ( $http_post ) {
 823              $errors = retrieve_password();
 824  
 825              if ( ! is_wp_error( $errors ) ) {
 826                  $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm';
 827                  wp_safe_redirect( $redirect_to );
 828                  exit;
 829              }
 830          }
 831  
 832          if ( isset( $_GET['error'] ) ) {
 833              if ( 'invalidkey' === $_GET['error'] ) {
 834                  $errors->add( 'invalidkey', __( 'Your password reset link appears to be invalid. Please request a new link below.' ) );
 835              } elseif ( 'expiredkey' === $_GET['error'] ) {
 836                  $errors->add( 'expiredkey', __( 'Your password reset link has expired. Please request a new link below.' ) );
 837              }
 838          }
 839  
 840          $lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
 841          /**
 842           * Filters the URL redirected to after submitting the lostpassword/retrievepassword form.
 843           *
 844           * @since 3.0.0
 845           *
 846           * @param string $lostpassword_redirect The redirect destination URL.
 847           */
 848          $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
 849  
 850          /**
 851           * Fires before the lost password form.
 852           *
 853           * @since 1.5.1
 854           * @since 5.1.0 Added the `$errors` parameter.
 855           *
 856           * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid
 857           *                         credentials. Note that the error object may not contain any errors.
 858           */
 859          do_action( 'lost_password', $errors );
 860  
 861          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 );
 862  
 863          $user_login = '';
 864  
 865          if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
 866              $user_login = wp_unslash( $_POST['user_login'] );
 867          }
 868  
 869          ?>
 870  
 871          <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
 872              <p>
 873                  <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
 874                  <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
 875              </p>
 876              <?php
 877  
 878              /**
 879               * Fires inside the lostpassword form tags, before the hidden fields.
 880               *
 881               * @since 2.1.0
 882               */
 883              do_action( 'lostpassword_form' );
 884  
 885              ?>
 886              <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
 887              <p class="submit">
 888                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Get New Password' ); ?>" />
 889              </p>
 890          </form>
 891  
 892          <p id="nav">
 893              <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
 894              <?php
 895  
 896              if ( get_option( 'users_can_register' ) ) {
 897                  $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
 898  
 899                  echo esc_html( $login_link_separator );
 900  
 901                  /** This filter is documented in wp-includes/general-template.php */
 902                  echo apply_filters( 'register', $registration_url );
 903              }
 904  
 905              ?>
 906          </p>
 907          <?php
 908  
 909          login_footer( 'user_login' );
 910          break;
 911  
 912      case 'resetpass':
 913      case 'rp':
 914          list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
 915          $rp_cookie       = 'wp-resetpass-' . COOKIEHASH;
 916  
 917          if ( isset( $_GET['key'] ) ) {
 918              $value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
 919              setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 920  
 921              wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
 922              exit;
 923          }
 924  
 925          if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
 926              list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
 927  
 928              $user = check_password_reset_key( $rp_key, $rp_login );
 929  
 930              if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, $_POST['rp_key'] ) ) {
 931                  $user = false;
 932              }
 933          } else {
 934              $user = false;
 935          }
 936  
 937          if ( ! $user || is_wp_error( $user ) ) {
 938              setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 939  
 940              if ( $user && $user->get_error_code() === 'expired_key' ) {
 941                  wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
 942              } else {
 943                  wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) );
 944              }
 945  
 946              exit;
 947          }
 948  
 949          $errors = new WP_Error();
 950  
 951          if ( isset( $_POST['pass1'] ) && $_POST['pass1'] !== $_POST['pass2'] ) {
 952              $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
 953          }
 954  
 955          /**
 956           * Fires before the password reset procedure is validated.
 957           *
 958           * @since 3.5.0
 959           *
 960           * @param WP_Error         $errors WP Error object.
 961           * @param WP_User|WP_Error $user   WP_User object if the login and reset key match. WP_Error object otherwise.
 962           */
 963          do_action( 'validate_password_reset', $errors, $user );
 964  
 965          if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
 966              reset_password( $user, $_POST['pass1'] );
 967              setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
 968              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>' );
 969              login_footer();
 970              exit;
 971          }
 972  
 973          wp_enqueue_script( 'utils' );
 974          wp_enqueue_script( 'user-profile' );
 975  
 976          login_header( __( 'Reset Password' ), '<p class="message reset-pass">' . __( 'Enter your new password below.' ) . '</p>', $errors );
 977  
 978          ?>
 979          <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
 980              <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
 981  
 982              <div class="user-pass1-wrap">
 983                  <p>
 984                      <label for="pass1"><?php _e( 'New password' ); ?></label>
 985                  </p>
 986  
 987                  <div class="wp-pwd">
 988                      <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" />
 989  
 990                      <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' ); ?>">
 991                          <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
 992                      </button>
 993                      <div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e( 'Strength indicator' ); ?></div>
 994                  </div>
 995                  <div class="pw-weak">
 996                      <input type="checkbox" name="pw_weak" id="pw-weak" class="pw-checkbox" />
 997                      <label for="pw-weak"><?php _e( 'Confirm use of weak password' ); ?></label>
 998                  </div>
 999              </div>
1000  
1001              <p class="user-pass2-wrap">
1002                  <label for="pass2"><?php _e( 'Confirm new password' ); ?></label>
1003                  <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" />
1004              </p>
1005  
1006              <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
1007              <br class="clear" />
1008  
1009              <?php
1010  
1011              /**
1012               * Fires following the 'Strength indicator' meter in the user password reset form.
1013               *
1014               * @since 3.9.0
1015               *
1016               * @param WP_User $user User object of the user whose password is being reset.
1017               */
1018              do_action( 'resetpass_form', $user );
1019  
1020              ?>
1021              <input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" />
1022              <p class="submit">
1023                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Reset Password' ); ?>" />
1024              </p>
1025          </form>
1026  
1027          <p id="nav">
1028              <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
1029              <?php
1030  
1031              if ( get_option( 'users_can_register' ) ) {
1032                  $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
1033  
1034                  echo esc_html( $login_link_separator );
1035  
1036                  /** This filter is documented in wp-includes/general-template.php */
1037                  echo apply_filters( 'register', $registration_url );
1038              }
1039  
1040              ?>
1041          </p>
1042          <?php
1043  
1044          login_footer( 'user_pass' );
1045          break;
1046  
1047      case 'register':
1048          if ( is_multisite() ) {
1049              /**
1050               * Filters the Multisite sign up URL.
1051               *
1052               * @since 3.0.0
1053               *
1054               * @param string $sign_up_url The sign up URL.
1055               */
1056              wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) );
1057              exit;
1058          }
1059  
1060          if ( ! get_option( 'users_can_register' ) ) {
1061              wp_redirect( site_url( 'wp-login.php?registration=disabled' ) );
1062              exit;
1063          }
1064  
1065          $user_login = '';
1066          $user_email = '';
1067  
1068          if ( $http_post ) {
1069              if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
1070                  $user_login = wp_unslash( $_POST['user_login'] );
1071              }
1072  
1073              if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) {
1074                  $user_email = wp_unslash( $_POST['user_email'] );
1075              }
1076  
1077              $errors = register_new_user( $user_login, $user_email );
1078  
1079              if ( ! is_wp_error( $errors ) ) {
1080                  $redirect_to = ! empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
1081                  wp_safe_redirect( $redirect_to );
1082                  exit;
1083              }
1084          }
1085  
1086          $registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
1087  
1088          /**
1089           * Filters the registration redirect URL.
1090           *
1091           * @since 3.0.0
1092           *
1093           * @param string $registration_redirect The redirect destination URL.
1094           */
1095          $redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
1096  
1097          login_header( __( 'Registration Form' ), '<p class="message register">' . __( 'Register For This Site' ) . '</p>', $errors );
1098  
1099          ?>
1100          <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
1101              <p>
1102                  <label for="user_login"><?php _e( 'Username' ); ?></label>
1103                  <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( wp_unslash( $user_login ) ); ?>" size="20" autocapitalize="off" />
1104              </p>
1105              <p>
1106                  <label for="user_email"><?php _e( 'Email' ); ?></label>
1107                  <input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" />
1108              </p>
1109              <?php
1110  
1111              /**
1112               * Fires following the 'Email' field in the user registration form.
1113               *
1114               * @since 2.1.0
1115               */
1116              do_action( 'register_form' );
1117  
1118              ?>
1119              <p id="reg_passmail">
1120                  <?php _e( 'Registration confirmation will be emailed to you.' ); ?>
1121              </p>
1122              <br class="clear" />
1123              <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
1124              <p class="submit">
1125                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Register' ); ?>" />
1126              </p>
1127          </form>
1128  
1129          <p id="nav">
1130              <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
1131                  <?php echo esc_html( $login_link_separator ); ?>
1132              <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
1133          </p>
1134          <?php
1135  
1136          login_footer( 'user_login' );
1137          break;
1138  
1139      case 'checkemail':
1140          $redirect_to = admin_url();
1141          $errors      = new WP_Error();
1142  
1143          if ( 'confirm' === $_GET['checkemail'] ) {
1144              $errors->add(
1145                  'confirm',
1146                  sprintf(
1147                      /* translators: %s: Link to the login page. */
1148                      __( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ),
1149                      wp_login_url()
1150                  ),
1151                  'message'
1152              );
1153          } elseif ( 'registered' === $_GET['checkemail'] ) {
1154              $errors->add(
1155                  'registered',
1156                  sprintf(
1157                      /* translators: %s: Link to the login page. */
1158                      __( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ),
1159                      wp_login_url()
1160                  ),
1161                  'message'
1162              );
1163          }
1164  
1165          /** This action is documented in wp-login.php */
1166          $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
1167  
1168          login_header( __( 'Check your email' ), '', $errors );
1169          login_footer();
1170          break;
1171  
1172      case 'confirmaction':
1173          if ( ! isset( $_GET['request_id'] ) ) {
1174              wp_die( __( 'Missing request ID.' ) );
1175          }
1176  
1177          if ( ! isset( $_GET['confirm_key'] ) ) {
1178              wp_die( __( 'Missing confirm key.' ) );
1179          }
1180  
1181          $request_id = (int) $_GET['request_id'];
1182          $key        = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) );
1183          $result     = wp_validate_user_request_key( $request_id, $key );
1184  
1185          if ( is_wp_error( $result ) ) {
1186              wp_die( $result );
1187          }
1188  
1189          /**
1190           * Fires an action hook when the account action has been confirmed by the user.
1191           *
1192           * Using this you can assume the user has agreed to perform the action by
1193           * clicking on the link in the confirmation email.
1194           *
1195           * After firing this action hook the page will redirect to wp-login a callback
1196           * redirects or exits first.
1197           *
1198           * @since 4.9.6
1199           *
1200           * @param int $request_id Request ID.
1201           */
1202          do_action( 'user_request_action_confirmed', $request_id );
1203  
1204          $message = _wp_privacy_account_request_confirmed_message( $request_id );
1205  
1206          login_header( __( 'User action confirmed.' ), $message );
1207          login_footer();
1208          exit;
1209  
1210      case 'login':
1211      default:
1212          $secure_cookie   = '';
1213          $customize_login = isset( $_REQUEST['customize-login'] );
1214  
1215          if ( $customize_login ) {
1216              wp_enqueue_script( 'customize-base' );
1217          }
1218  
1219          // If the user wants SSL but the session is not SSL, force a secure cookie.
1220          if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
1221              $user_name = sanitize_user( wp_unslash( $_POST['log'] ) );
1222              $user      = get_user_by( 'login', $user_name );
1223  
1224              if ( ! $user && strpos( $user_name, '@' ) ) {
1225                  $user = get_user_by( 'email', $user_name );
1226              }
1227  
1228              if ( $user ) {
1229                  if ( get_user_option( 'use_ssl', $user->ID ) ) {
1230                      $secure_cookie = true;
1231                      force_ssl_admin( true );
1232                  }
1233              }
1234          }
1235  
1236          if ( isset( $_REQUEST['redirect_to'] ) ) {
1237              $redirect_to = $_REQUEST['redirect_to'];
1238              // Redirect to HTTPS if user wants SSL.
1239              if ( $secure_cookie && false !== strpos( $redirect_to, 'wp-admin' ) ) {
1240                  $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to );
1241              }
1242          } else {
1243              $redirect_to = admin_url();
1244          }
1245  
1246          $reauth = empty( $_REQUEST['reauth'] ) ? false : true;
1247  
1248          $user = wp_signon( array(), $secure_cookie );
1249  
1250          if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
1251              if ( headers_sent() ) {
1252                  $user = new WP_Error(
1253                      'test_cookie',
1254                      sprintf(
1255                          /* translators: 1: Browser cookie documentation URL, 2: Support forums URL. */
1256                          __( '<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>.' ),
1257                          __( 'https://wordpress.org/support/article/cookies/' ),
1258                          __( 'https://wordpress.org/support/forums/' )
1259                      )
1260                  );
1261              } elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
1262                  // If cookies are disabled, we can't log in even with a valid user and password.
1263                  $user = new WP_Error(
1264                      'test_cookie',
1265                      sprintf(
1266                          /* translators: %s: Browser cookie documentation URL. */
1267                          __( '<strong>Error</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.' ),
1268                          __( 'https://wordpress.org/support/article/cookies/#enable-cookies-in-your-browser' )
1269                      )
1270                  );
1271              }
1272          }
1273  
1274          $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
1275          /**
1276           * Filters the login redirect URL.
1277           *
1278           * @since 3.0.0
1279           *
1280           * @param string           $redirect_to           The redirect destination URL.
1281           * @param string           $requested_redirect_to The requested redirect destination URL passed as a parameter.
1282           * @param WP_User|WP_Error $user                  WP_User object if login was successful, WP_Error object otherwise.
1283           */
1284          $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
1285  
1286          if ( ! is_wp_error( $user ) && ! $reauth ) {
1287              if ( $interim_login ) {
1288                  $message       = '<p class="message">' . __( 'You have logged in successfully.' ) . '</p>';
1289                  $interim_login = 'success';
1290                  login_header( '', $message );
1291  
1292                  ?>
1293                  </div>
1294                  <?php
1295  
1296                  /** This action is documented in wp-login.php */
1297                  do_action( 'login_footer' );
1298  
1299                  if ( $customize_login ) {
1300                      ?>
1301                      <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
1302                      <?php
1303                  }
1304  
1305                  ?>
1306                  </body></html>
1307                  <?php
1308  
1309                  exit;
1310              }
1311  
1312              // Check if it is time to add a redirect to the admin email confirmation screen.
1313              if ( is_a( $user, 'WP_User' ) && $user->exists() && $user->has_cap( 'manage_options' ) ) {
1314                  $admin_email_lifespan = (int) get_option( 'admin_email_lifespan' );
1315  
1316                  // If `0` (or anything "falsey" as it is cast to int) is returned, the user will not be redirected
1317                  // to the admin email confirmation screen.
1318                  /** This filter is documented in wp-login.php */
1319                  $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS );
1320  
1321                  if ( $admin_email_check_interval > 0 && time() > $admin_email_lifespan ) {
1322                      $redirect_to = add_query_arg(
1323                          array(
1324                              'action'  => 'confirm_admin_email',
1325                              'wp_lang' => get_user_locale( $user ),
1326                          ),
1327                          wp_login_url( $redirect_to )
1328                      );
1329                  }
1330              }
1331  
1332              if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
1333                  // 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.
1334                  if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
1335                      $redirect_to = user_admin_url();
1336                  } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
1337                      $redirect_to = get_dashboard_url( $user->ID );
1338                  } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
1339                      $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
1340                  }
1341  
1342                  wp_redirect( $redirect_to );
1343                  exit;
1344              }
1345  
1346              wp_safe_redirect( $redirect_to );
1347              exit;
1348          }
1349  
1350          $errors = $user;
1351          // Clear errors if loggedout is set.
1352          if ( ! empty( $_GET['loggedout'] ) || $reauth ) {
1353              $errors = new WP_Error();
1354          }
1355  
1356          if ( empty( $_POST ) && $errors->get_error_codes() === array( 'empty_username', 'empty_password' ) ) {
1357              $errors = new WP_Error( '', '' );
1358          }
1359  
1360          if ( $interim_login ) {
1361              if ( ! $errors->has_errors() ) {
1362                  $errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' );
1363              }
1364          } else {
1365              // Some parts of this script use the main login form to display a message.
1366              if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] ) {
1367                  $errors->add( 'loggedout', __( 'You are now logged out.' ), 'message' );
1368              } elseif ( isset( $_GET['registration'] ) && 'disabled' === $_GET['registration'] ) {
1369                  $errors->add( 'registerdisabled', __( 'User registration is currently not allowed.' ) );
1370              } elseif ( strpos( $redirect_to, 'about.php?updated' ) ) {
1371                  $errors->add( 'updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
1372              } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) {
1373                  $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' );
1374              }
1375          }
1376  
1377          /**
1378           * Filters the login page errors.
1379           *
1380           * @since 3.6.0
1381           *
1382           * @param WP_Error $errors      WP Error object.
1383           * @param string   $redirect_to Redirect destination URL.
1384           */
1385          $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
1386  
1387          // Clear any stale cookies.
1388          if ( $reauth ) {
1389              wp_clear_auth_cookie();
1390          }
1391  
1392          login_header( __( 'Log In' ), '', $errors );
1393  
1394          if ( isset( $_POST['log'] ) ) {
1395              $user_login = ( 'incorrect_password' === $errors->get_error_code() || 'empty_password' === $errors->get_error_code() ) ? esc_attr( wp_unslash( $_POST['log'] ) ) : '';
1396          }
1397  
1398          $rememberme = ! empty( $_POST['rememberme'] );
1399  
1400          if ( $errors->has_errors() ) {
1401              $aria_describedby_error = ' aria-describedby="login_error"';
1402          } else {
1403              $aria_describedby_error = '';
1404          }
1405  
1406          wp_enqueue_script( 'user-profile' );
1407          ?>
1408  
1409          <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
1410              <p>
1411                  <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
1412                  <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" />
1413              </p>
1414  
1415              <div class="user-pass-wrap">
1416                  <label for="user_pass"><?php _e( 'Password' ); ?></label>
1417                  <div class="wp-pwd">
1418                      <input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input password-input" value="" size="20" />
1419                      <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' ); ?>">
1420                          <span class="dashicons dashicons-visibility" aria-hidden="true"></span>
1421                      </button>
1422                  </div>
1423              </div>
1424              <?php
1425  
1426              /**
1427               * Fires following the 'Password' field in the login form.
1428               *
1429               * @since 2.1.0
1430               */
1431              do_action( 'login_form' );
1432  
1433              ?>
1434              <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>
1435              <p class="submit">
1436                  <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Log In' ); ?>" />
1437                  <?php
1438  
1439                  if ( $interim_login ) {
1440                      ?>
1441                      <input type="hidden" name="interim-login" value="1" />
1442                      <?php
1443                  } else {
1444                      ?>
1445                      <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
1446                      <?php
1447                  }
1448  
1449                  if ( $customize_login ) {
1450                      ?>
1451                      <input type="hidden" name="customize-login" value="1" />
1452                      <?php
1453                  }
1454  
1455                  ?>
1456                  <input type="hidden" name="testcookie" value="1" />
1457              </p>
1458          </form>
1459  
1460          <?php
1461  
1462          if ( ! $interim_login ) {
1463              ?>
1464              <p id="nav">
1465                  <?php
1466  
1467                  if ( get_option( 'users_can_register' ) ) {
1468                      $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
1469  
1470                      /** This filter is documented in wp-includes/general-template.php */
1471                      echo apply_filters( 'register', $registration_url );
1472  
1473                      echo esc_html( $login_link_separator );
1474                  }
1475  
1476                  ?>
1477                  <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
1478              </p>
1479              <?php
1480          }
1481  
1482          $login_script  = 'function wp_attempt_focus() {';
1483          $login_script .= 'setTimeout( function() {';
1484          $login_script .= 'try {';
1485  
1486          if ( $user_login ) {
1487              $login_script .= 'd = document.getElementById( "user_pass" ); d.value = "";';
1488          } else {
1489              $login_script .= 'd = document.getElementById( "user_login" );';
1490  
1491              if ( $errors->get_error_code() === 'invalid_username' ) {
1492                  $login_script .= 'd.value = "";';
1493              }
1494          }
1495  
1496          $login_script .= 'd.focus(); d.select();';
1497          $login_script .= '} catch( er ) {}';
1498          $login_script .= '}, 200);';
1499          $login_script .= "}\n"; // End of wp_attempt_focus().
1500  
1501          /**
1502           * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
1503           *
1504           * @since 4.8.0
1505           *
1506           * @param bool $print Whether to print the function call. Default true.
1507           */
1508          if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) {
1509              $login_script .= "wp_attempt_focus();\n";
1510          }
1511  
1512          // Run `wpOnload()` if defined.
1513          $login_script .= "if ( typeof wpOnload === 'function' ) { wpOnload() }";
1514  
1515          ?>
1516          <script type="text/javascript">
1517              <?php echo $login_script; ?>
1518          </script>
1519          <?php
1520  
1521          if ( $interim_login ) {
1522              ?>
1523              <script type="text/javascript">
1524              ( function() {
1525                  try {
1526                      var i, links = document.getElementsByTagName( 'a' );
1527                      for ( i in links ) {
1528                          if ( links[i].href ) {
1529                              links[i].target = '_blank';
1530                              links[i].rel = 'noreferrer noopener';
1531                          }
1532                      }
1533                  } catch( er ) {}
1534              }());
1535              </script>
1536              <?php
1537          }
1538  
1539          login_footer();
1540          break;
1541  } // End action switch.


Generated: Sat Aug 8 01:00:03 2020 Cross-referenced by PHPXref 0.7.1