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