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


Generated: Wed Jan 29 01:00:05 2020 Cross-referenced by PHPXref 0.7.1