[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Fri Oct 25 08:20:01 2019 Cross-referenced by PHPXref 0.7