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


Generated: Thu May 28 01:00:03 2020 Cross-referenced by PHPXref 0.7.1