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