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


Generated: Mon Aug 19 01:00:03 2019 Cross-referenced by PHPXref 0.7.1