wp/wp-login.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    23 }
    23 }
    24 
    24 
    25 /**
    25 /**
    26  * Output the login page header.
    26  * Output the login page header.
    27  *
    27  *
    28  * @param string $title    Optional. WordPress Log In Page title to display in <title/> element. Default 'Log In'.
    28  * @param string   $title    Optional. WordPress login Page title to display in the `<title>` element.
    29  * @param string $message  Optional. Message to display in header. Default empty.
    29  *                           Default 'Log In'.
    30  * @param string $wp_error Optional. The error to pass. Default empty.
    30  * @param string   $message  Optional. Message to display in header. Default empty.
    31  * @param WP_Error $wp_error Optional. WordPress Error Object
    31  * @param WP_Error $wp_error Optional. The error to pass. Default empty.
    32  */
    32  */
    33 function login_header($title = 'Log In', $message = '', $wp_error = '') {
    33 function login_header( $title = 'Log In', $message = '', $wp_error = '' ) {
    34 	global $error, $interim_login, $current_site, $action;
    34 	global $error, $interim_login, $action;
    35 
    35 
    36 	// Don't index any of these forms
    36 	// Don't index any of these forms
    37 	add_action( 'login_head', 'wp_no_robots' );
    37 	add_action( 'login_head', 'wp_no_robots' );
    38 
    38 
    39 	if ( wp_is_mobile() )
    39 	if ( wp_is_mobile() )
    55 
    55 
    56 	if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
    56 	if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
    57 		add_action( 'login_head', 'wp_shake_js', 12 );
    57 		add_action( 'login_head', 'wp_shake_js', 12 );
    58 
    58 
    59 	?><!DOCTYPE html>
    59 	?><!DOCTYPE html>
    60 	<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    60 	<!--[if IE 8]>
       
    61 		<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
       
    62 	<![endif]-->
       
    63 	<!--[if !(IE 8) ]><!-->
       
    64 		<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
       
    65 	<!--<![endif]-->
    61 	<head>
    66 	<head>
    62 	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    67 	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    63 	<title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
    68 	<title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
    64 	<?php
    69 	<?php
    65 
    70 
    66 	wp_admin_css( 'wp-admin', true );
    71 	wp_admin_css( 'login', true );
    67 	wp_admin_css( 'colors-fresh', true );
    72 
    68 
    73 	/*
    69 	// Remove all stored post data on logging out.
    74 	 * Remove all stored post data on logging out.
    70 	// This could be added by add_action('login_head'...) like wp_shake_js()
    75 	 * This could be added by add_action('login_head'...) like wp_shake_js(),
    71 	// but maybe better if it's not removable by plugins
    76 	 * but maybe better if it's not removable by plugins
       
    77 	 */
    72 	if ( 'loggedout' == $wp_error->get_error_code() ) {
    78 	if ( 'loggedout' == $wp_error->get_error_code() ) {
    73 		?>
    79 		?>
    74 		<script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script>
    80 		<script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script>
    75 		<?php
    81 		<?php
    76 	}
    82 	}
    88 	 */
    94 	 */
    89 	do_action( 'login_head' );
    95 	do_action( 'login_head' );
    90 
    96 
    91 	if ( is_multisite() ) {
    97 	if ( is_multisite() ) {
    92 		$login_header_url   = network_home_url();
    98 		$login_header_url   = network_home_url();
    93 		$login_header_title = $current_site->site_name;
    99 		$login_header_title = get_current_site()->site_name;
    94 	} else {
   100 	} else {
    95 		$login_header_url   = __( 'http://wordpress.org/' );
   101 		$login_header_url   = __( 'https://wordpress.org/' );
    96 		$login_header_title = __( 'Powered by WordPress' );
   102 		$login_header_title = __( 'Powered by WordPress' );
    97 	}
   103 	}
    98 
   104 
    99 	/**
   105 	/**
   100 	 * Filter link URL of the header logo above login form.
   106 	 * Filter link URL of the header logo above login form.
   125 		<?php
   131 		<?php
   126 
   132 
   127 		if ( 'success' ===  $interim_login )
   133 		if ( 'success' ===  $interim_login )
   128 			$classes[] = 'interim-login-success';
   134 			$classes[] = 'interim-login-success';
   129 	}
   135 	}
       
   136 	$classes[] =' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
   130 
   137 
   131 	/**
   138 	/**
   132 	 * Filter the login page body classes.
   139 	 * Filter the login page body classes.
   133 	 *
   140 	 *
   134 	 * @since 3.5.0
   141 	 * @since 3.5.0
   140 
   147 
   141 	?>
   148 	?>
   142 	</head>
   149 	</head>
   143 	<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
   150 	<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
   144 	<div id="login">
   151 	<div id="login">
   145 		<h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
   152 		<h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
   146 	<?php
   153 	<?php
   147 
   154 
   148 	unset( $login_header_url, $login_header_title );
   155 	unset( $login_header_url, $login_header_title );
   149 
   156 
   150 	/**
   157 	/**
   166 
   173 
   167 	if ( $wp_error->get_error_code() ) {
   174 	if ( $wp_error->get_error_code() ) {
   168 		$errors = '';
   175 		$errors = '';
   169 		$messages = '';
   176 		$messages = '';
   170 		foreach ( $wp_error->get_error_codes() as $code ) {
   177 		foreach ( $wp_error->get_error_codes() as $code ) {
   171 			$severity = $wp_error->get_error_data($code);
   178 			$severity = $wp_error->get_error_data( $code );
   172 			foreach ( $wp_error->get_error_messages($code) as $error ) {
   179 			foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
   173 				if ( 'message' == $severity )
   180 				if ( 'message' == $severity )
   174 					$messages .= '	' . $error . "<br />\n";
   181 					$messages .= '	' . $error_message . "<br />\n";
   175 				else
   182 				else
   176 					$errors .= '	' . $error . "<br />\n";
   183 					$errors .= '	' . $error_message . "<br />\n";
   177 			}
   184 			}
   178 		}
   185 		}
   179 		if ( ! empty( $errors ) ) {
   186 		if ( ! empty( $errors ) ) {
   180 			/**
   187 			/**
   181 			 * Filter the error messages displayed above the login form.
   188 			 * Filter the error messages displayed above the login form.
   255 }
   262 }
   256 
   263 
   257 /**
   264 /**
   258  * Handles sending password retrieval email to user.
   265  * Handles sending password retrieval email to user.
   259  *
   266  *
   260  * @uses $wpdb WordPress Database object
   267  * @global wpdb         $wpdb      WordPress database abstraction object.
       
   268  * @global PasswordHash $wp_hasher Portable PHP password hashing framework.
   261  *
   269  *
   262  * @return bool|WP_Error True: when finish. WP_Error on error
   270  * @return bool|WP_Error True: when finish. WP_Error on error
   263  */
   271  */
   264 function retrieve_password() {
   272 function retrieve_password() {
   265 	global $wpdb, $current_site, $wp_hasher;
   273 	global $wpdb, $wp_hasher;
   266 
   274 
   267 	$errors = new WP_Error();
   275 	$errors = new WP_Error();
   268 
   276 
   269 	if ( empty( $_POST['user_login'] ) ) {
   277 	if ( empty( $_POST['user_login'] ) ) {
   270 		$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
   278 		$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
   271 	} else if ( strpos( $_POST['user_login'], '@' ) ) {
   279 	} elseif ( strpos( $_POST['user_login'], '@' ) ) {
   272 		$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
   280 		$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
   273 		if ( empty( $user_data ) )
   281 		if ( empty( $user_data ) )
   274 			$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
   282 			$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
   275 	} else {
   283 	} else {
   276 		$login = trim($_POST['user_login']);
   284 		$login = trim($_POST['user_login']);
   290 	if ( !$user_data ) {
   298 	if ( !$user_data ) {
   291 		$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
   299 		$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
   292 		return $errors;
   300 		return $errors;
   293 	}
   301 	}
   294 
   302 
   295 	// redefining user_login ensures we return the right case in the email
   303 	// Redefining user_login ensures we return the right case in the email.
   296 	$user_login = $user_data->user_login;
   304 	$user_login = $user_data->user_login;
   297 	$user_email = $user_data->user_email;
   305 	$user_email = $user_data->user_email;
   298 
   306 
   299 	/**
   307 	/**
   300 	 * Fires before a new password is retrieved.
   308 	 * Fires before a new password is retrieved.
   301 	 *
   309 	 *
   302 	 * @since 1.5.2
   310 	 * @since 1.5.0
   303 	 * @deprecated 1.5.2 Misspelled. Use 'retrieve_password' hook instead.
   311 	 * @deprecated 1.5.1 Misspelled. Use 'retrieve_password' hook instead.
   304 	 *
   312 	 *
   305 	 * @param string $user_login The user login name.
   313 	 * @param string $user_login The user login name.
   306 	 */
   314 	 */
   307 	do_action( 'retreive_password', $user_login );
   315 	do_action( 'retreive_password', $user_login );
       
   316 
   308 	/**
   317 	/**
   309 	 * Fires before a new password is retrieved.
   318 	 * Fires before a new password is retrieved.
   310 	 *
   319 	 *
   311 	 * @since 1.5.2
   320 	 * @since 1.5.1
   312 	 *
   321 	 *
   313 	 * @param string $user_login The user login name.
   322 	 * @param string $user_login The user login name.
   314 	 */
   323 	 */
   315 	do_action( 'retrieve_password', $user_login );
   324 	do_action( 'retrieve_password', $user_login );
   316 
   325 
   322 	 * @param bool true           Whether to allow the password to be reset. Default true.
   331 	 * @param bool true           Whether to allow the password to be reset. Default true.
   323 	 * @param int  $user_data->ID The ID of the user attempting to reset a password.
   332 	 * @param int  $user_data->ID The ID of the user attempting to reset a password.
   324 	 */
   333 	 */
   325 	$allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
   334 	$allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
   326 
   335 
   327 	if ( ! $allow )
   336 	if ( ! $allow ) {
   328 		return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
   337 		return new WP_Error( 'no_password_reset', __('Password reset is not allowed for this user') );
   329 	else if ( is_wp_error($allow) )
   338 	} elseif ( is_wp_error( $allow ) ) {
   330 		return $allow;
   339 		return $allow;
       
   340 	}
   331 
   341 
   332 	// Generate something random for a password reset key.
   342 	// Generate something random for a password reset key.
   333 	$key = wp_generate_password( 20, false );
   343 	$key = wp_generate_password( 20, false );
   334 
   344 
   335 	/**
   345 	/**
   342 	 */
   352 	 */
   343 	do_action( 'retrieve_password_key', $user_login, $key );
   353 	do_action( 'retrieve_password_key', $user_login, $key );
   344 
   354 
   345 	// Now insert the key, hashed, into the DB.
   355 	// Now insert the key, hashed, into the DB.
   346 	if ( empty( $wp_hasher ) ) {
   356 	if ( empty( $wp_hasher ) ) {
   347 		require_once ABSPATH . 'wp-includes/class-phpass.php';
   357 		require_once ABSPATH . WPINC . '/class-phpass.php';
   348 		$wp_hasher = new PasswordHash( 8, true );
   358 		$wp_hasher = new PasswordHash( 8, true );
   349 	}
   359 	}
   350 	$hashed = $wp_hasher->HashPassword( $key );
   360 	$hashed = $wp_hasher->HashPassword( $key );
   351 	$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
   361 	$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
   352 
   362 
   358 	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
   368 	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
   359 
   369 
   360 	if ( is_multisite() )
   370 	if ( is_multisite() )
   361 		$blogname = $GLOBALS['current_site']->site_name;
   371 		$blogname = $GLOBALS['current_site']->site_name;
   362 	else
   372 	else
   363 		// The blogname option is escaped with esc_html on the way into the database in sanitize_option
   373 		/*
   364 		// we want to reverse this for the plain text arena of emails.
   374 		 * The blogname option is escaped with esc_html on the way into the database
       
   375 		 * in sanitize_option we want to reverse this for the plain text arena of emails.
       
   376 		 */
   365 		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
   377 		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
   366 
   378 
   367 	$title = sprintf( __('[%s] Password Reset'), $blogname );
   379 	$title = sprintf( __('[%s] Password Reset'), $blogname );
   368 
   380 
   369 	/**
   381 	/**
   372 	 * @since 2.8.0
   384 	 * @since 2.8.0
   373 	 *
   385 	 *
   374 	 * @param string $title Default email title.
   386 	 * @param string $title Default email title.
   375 	 */
   387 	 */
   376 	$title = apply_filters( 'retrieve_password_title', $title );
   388 	$title = apply_filters( 'retrieve_password_title', $title );
       
   389 
   377 	/**
   390 	/**
   378 	 * Filter the message body of the password reset mail.
   391 	 * Filter the message body of the password reset mail.
   379 	 *
   392 	 *
   380 	 * @since 2.8.0
   393 	 * @since 2.8.0
   381 	 *
   394 	 * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
   382 	 * @param string $message Default mail message.
   395 	 *
   383 	 * @param string $key     The activation key.
   396 	 * @param string  $message    Default mail message.
   384 	 */
   397 	 * @param string  $key        The activation key.
   385 	$message = apply_filters( 'retrieve_password_message', $message, $key );
   398 	 * @param string  $user_login The username for the user.
   386 
   399 	 * @param WP_User $user_data  WP_User object.
   387 	if ( $message && !wp_mail($user_email, $title, $message) )
   400 	 */
       
   401 	$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
       
   402 
       
   403 	if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
   388 		wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
   404 		wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
   389 
   405 
   390 	return true;
   406 	return true;
   391 }
   407 }
   392 
   408 
   416 	if ( $url != get_option( 'siteurl' ) )
   432 	if ( $url != get_option( 'siteurl' ) )
   417 		update_option( 'siteurl', $url );
   433 		update_option( 'siteurl', $url );
   418 }
   434 }
   419 
   435 
   420 //Set a cookie now to see if they are supported by the browser.
   436 //Set a cookie now to see if they are supported by the browser.
   421 setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
   437 $secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) && 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
       
   438 setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
   422 if ( SITECOOKIEPATH != COOKIEPATH )
   439 if ( SITECOOKIEPATH != COOKIEPATH )
   423 	setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
   440 	setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
   424 
   441 
   425 /**
   442 /**
   426  * Fires when the login form is initialized.
   443  * Fires when the login form is initialized.
   427  *
   444  *
   428  * @since 3.2.0
   445  * @since 3.2.0
   429  */
   446  */
   430 do_action( 'login_init' );
   447 do_action( 'login_init' );
   431 /**
   448 /**
   432  * Fires before a specified login form action.
   449  * Fires before a specified login form action.
   433  *
   450  *
   434  * The dynamic portion of the hook name, $action, refers to the action
   451  * The dynamic portion of the hook name, `$action`, refers to the action
   435  * that brought the visitor to the login form. Actions include 'postpass',
   452  * that brought the visitor to the login form. Actions include 'postpass',
   436  * 'logout', 'lostpassword', etc.
   453  * 'logout', 'lostpassword', etc.
   437  *
   454  *
   438  * @since 2.8.0
   455  * @since 2.8.0
   439  */
   456  */
   443 $interim_login = isset($_REQUEST['interim-login']);
   460 $interim_login = isset($_REQUEST['interim-login']);
   444 
   461 
   445 switch ($action) {
   462 switch ($action) {
   446 
   463 
   447 case 'postpass' :
   464 case 'postpass' :
   448 	require_once ABSPATH . 'wp-includes/class-phpass.php';
   465 	require_once ABSPATH . WPINC . '/class-phpass.php';
   449 	$hasher = new PasswordHash( 8, true );
   466 	$hasher = new PasswordHash( 8, true );
   450 
   467 
   451 	/**
   468 	/**
   452 	 * Filter the life span of the post password cookie.
   469 	 * Filter the life span of the post password cookie.
   453 	 *
   470 	 *
   457 	 * @since 3.7.0
   474 	 * @since 3.7.0
   458 	 *
   475 	 *
   459 	 * @param int $expires The expiry time, as passed to setcookie().
   476 	 * @param int $expires The expiry time, as passed to setcookie().
   460 	 */
   477 	 */
   461 	$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
   478 	$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
   462 	setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH );
   479 	$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
       
   480 	setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
   463 
   481 
   464 	wp_safe_redirect( wp_get_referer() );
   482 	wp_safe_redirect( wp_get_referer() );
   465 	exit();
   483 	exit();
   466 
   484 
   467 break;
       
   468 
       
   469 case 'logout' :
   485 case 'logout' :
   470 	check_admin_referer('log-out');
   486 	check_admin_referer('log-out');
       
   487 
       
   488 	$user = wp_get_current_user();
       
   489 
   471 	wp_logout();
   490 	wp_logout();
   472 
   491 
   473 	$redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?loggedout=true';
   492 	if ( ! empty( $_REQUEST['redirect_to'] ) ) {
       
   493 		$redirect_to = $requested_redirect_to = $_REQUEST['redirect_to'];
       
   494 	} else {
       
   495 		$redirect_to = 'wp-login.php?loggedout=true';
       
   496 		$requested_redirect_to = '';
       
   497 	}
       
   498 
       
   499 	/**
       
   500 	 * Filter the log out redirect URL.
       
   501 	 *
       
   502 	 * @since 4.2.0
       
   503 	 *
       
   504 	 * @param string  $redirect_to           The redirect destination URL.
       
   505 	 * @param string  $requested_redirect_to The requested redirect destination URL passed as a parameter.
       
   506 	 * @param WP_User $user                  The WP_User object for the user that's logging out.
       
   507 	 */
       
   508 	$redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
   474 	wp_safe_redirect( $redirect_to );
   509 	wp_safe_redirect( $redirect_to );
   475 	exit();
   510 	exit();
   476 
       
   477 break;
       
   478 
   511 
   479 case 'lostpassword' :
   512 case 'lostpassword' :
   480 case 'retrievepassword' :
   513 case 'retrievepassword' :
   481 
   514 
   482 	if ( $http_post ) {
   515 	if ( $http_post ) {
   506 	$redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
   539 	$redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
   507 
   540 
   508 	/**
   541 	/**
   509 	 * Fires before the lost password form.
   542 	 * Fires before the lost password form.
   510 	 *
   543 	 *
   511 	 * @since 1.5.2
   544 	 * @since 1.5.1
   512 	 */
   545 	 */
   513 	do_action( 'lost_password' );
   546 	do_action( 'lost_password' );
   514 
   547 
   515 	login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or email address. You will receive a link to create a new password via email.') . '</p>', $errors);
   548 	login_header(__('Lost Password'), '<p class="message">' . __('Please enter your username or email address. You will receive a link to create a new password via email.') . '</p>', $errors);
   516 
   549 
   517 	$user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
   550 	$user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
   518 
   551 
   519 ?>
   552 ?>
   520 
   553 
   521 <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
   554 <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
   522 	<p>
   555 	<p>
   523 		<label for="user_login" ><?php _e('Username or E-mail:') ?><br />
   556 		<label for="user_login" ><?php _e('Username or E-mail:') ?><br />
   524 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
   557 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
   525 	</p>
   558 	</p>
   526 	<?php
   559 	<?php
   527 	/**
   560 	/**
   528 	 * Fires inside the lostpassword <form> tags, before the hidden fields.
   561 	 * Fires inside the lostpassword form tags, before the hidden fields.
   529 	 *
   562 	 *
   530 	 * @since 2.1.0
   563 	 * @since 2.1.0
   531 	 */
   564 	 */
   532 	do_action( 'lostpassword_form' ); ?>
   565 	do_action( 'lostpassword_form' ); ?>
   533 	<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
   566 	<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
   537 <p id="nav">
   570 <p id="nav">
   538 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
   571 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
   539 <?php
   572 <?php
   540 if ( get_option( 'users_can_register' ) ) :
   573 if ( get_option( 'users_can_register' ) ) :
   541 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   574 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   542 	/**
   575 
   543 	 * Filter the registration URL below the login form.
   576 	/** This filter is documented in wp-includes/general-template.php */
   544 	 *
       
   545 	 * @since 1.5.2
       
   546 	 *
       
   547 	 * @param string $registration_url Registration URL.
       
   548 	 */
       
   549 	echo ' | ' . apply_filters( 'register', $registration_url );
   577 	echo ' | ' . apply_filters( 'register', $registration_url );
   550 endif;
   578 endif;
   551 ?>
   579 ?>
   552 </p>
   580 </p>
   553 
   581 
   555 login_footer('user_login');
   583 login_footer('user_login');
   556 break;
   584 break;
   557 
   585 
   558 case 'resetpass' :
   586 case 'resetpass' :
   559 case 'rp' :
   587 case 'rp' :
   560 	$user = check_password_reset_key($_GET['key'], $_GET['login']);
   588 	list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
   561 
   589 	$rp_cookie = 'wp-resetpass-' . COOKIEHASH;
   562 	if ( is_wp_error($user) ) {
   590 	if ( isset( $_GET['key'] ) ) {
   563 		if ( $user->get_error_code() === 'expired_key' )
   591 		$value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
       
   592 		setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
       
   593 		wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
       
   594 		exit;
       
   595 	}
       
   596 
       
   597 	if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
       
   598 		list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
       
   599 		$user = check_password_reset_key( $rp_key, $rp_login );
       
   600 		if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, $_POST['rp_key'] ) ) {
       
   601 			$user = false;
       
   602 		}
       
   603 	} else {
       
   604 		$user = false;
       
   605 	}
       
   606 
       
   607 	if ( ! $user || is_wp_error( $user ) ) {
       
   608 		setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
       
   609 		if ( $user && $user->get_error_code() === 'expired_key' )
   564 			wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
   610 			wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
   565 		else
   611 		else
   566 			wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) );
   612 			wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) );
   567 		exit;
   613 		exit;
   568 	}
   614 	}
   582 	 */
   628 	 */
   583 	do_action( 'validate_password_reset', $errors, $user );
   629 	do_action( 'validate_password_reset', $errors, $user );
   584 
   630 
   585 	if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
   631 	if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
   586 		reset_password($user, $_POST['pass1']);
   632 		reset_password($user, $_POST['pass1']);
       
   633 		setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
   587 		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>' );
   634 		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>' );
   588 		login_footer();
   635 		login_footer();
   589 		exit;
   636 		exit;
   590 	}
   637 	}
   591 
   638 
   593 	wp_enqueue_script('user-profile');
   640 	wp_enqueue_script('user-profile');
   594 
   641 
   595 	login_header(__('Reset Password'), '<p class="message reset-pass">' . __('Enter your new password below.') . '</p>', $errors );
   642 	login_header(__('Reset Password'), '<p class="message reset-pass">' . __('Enter your new password below.') . '</p>', $errors );
   596 
   643 
   597 ?>
   644 ?>
   598 <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( site_url( 'wp-login.php?action=resetpass&key=' . urlencode( $_GET['key'] ) . '&login=' . urlencode( $_GET['login'] ), 'login_post' ) ); ?>" method="post" autocomplete="off">
   645 <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
   599 	<input type="hidden" id="user_login" value="<?php echo esc_attr( $_GET['login'] ); ?>" autocomplete="off" />
   646 	<input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
   600 
   647 
   601 	<p>
   648 	<p>
   602 		<label for="pass1"><?php _e('New password') ?><br />
   649 		<label for="pass1"><?php _e('New password') ?><br />
   603 		<input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" /></label>
   650 		<input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" /></label>
   604 	</p>
   651 	</p>
   606 		<label for="pass2"><?php _e('Confirm new password') ?><br />
   653 		<label for="pass2"><?php _e('Confirm new password') ?><br />
   607 		<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /></label>
   654 		<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /></label>
   608 	</p>
   655 	</p>
   609 
   656 
   610 	<div id="pass-strength-result" class="hide-if-no-js"><?php _e('Strength indicator'); ?></div>
   657 	<div id="pass-strength-result" class="hide-if-no-js"><?php _e('Strength indicator'); ?></div>
   611 	<p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
   658 	<p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
   612 
       
   613 	<br class="clear" />
   659 	<br class="clear" />
       
   660 
       
   661 	<?php
       
   662 	/**
       
   663 	 * Fires following the 'Strength indicator' meter in the user password reset form.
       
   664 	 *
       
   665 	 * @since 3.9.0
       
   666 	 *
       
   667 	 * @param WP_User $user User object of the user whose password is being reset.
       
   668 	 */
       
   669 	do_action( 'resetpass_form', $user );
       
   670 	?>
       
   671 	<input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" />
   614 	<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Reset Password'); ?>" /></p>
   672 	<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Reset Password'); ?>" /></p>
   615 </form>
   673 </form>
   616 
   674 
   617 <p id="nav">
   675 <p id="nav">
   618 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
   676 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
   619 <?php
   677 <?php
   620 if ( get_option( 'users_can_register' ) ) :
   678 if ( get_option( 'users_can_register' ) ) :
   621 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   679 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   622 	/** This filter is documented in wp-login.php */
   680 
       
   681 	/** This filter is documented in wp-includes/general-template.php */
   623 	echo ' | ' . apply_filters( 'register', $registration_url );
   682 	echo ' | ' . apply_filters( 'register', $registration_url );
   624 endif;
   683 endif;
   625 ?>
   684 ?>
   626 </p>
   685 </p>
   627 
   686 
   629 login_footer('user_pass');
   688 login_footer('user_pass');
   630 break;
   689 break;
   631 
   690 
   632 case 'register' :
   691 case 'register' :
   633 	if ( is_multisite() ) {
   692 	if ( is_multisite() ) {
   634 		$sign_up_url = network_site_url( 'wp-signup.php' );
       
   635 		/**
   693 		/**
   636 		 * Filter the Multisite sign up URL.
   694 		 * Filter the Multisite sign up URL.
   637 		 *
   695 		 *
   638 		 * @since 3.0.0
   696 		 * @since 3.0.0
   639 		 *
   697 		 *
   640 		 * @param string $sign_up_url The sign up URL.
   698 		 * @param string $sign_up_url The sign up URL.
   641 		 */
   699 		 */
   642 		wp_redirect( apply_filters( 'wp_signup_location', $sign_up_url ) );
   700 		wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) );
   643 		exit;
   701 		exit;
   644 	}
   702 	}
   645 
   703 
   646 	if ( !get_option('users_can_register') ) {
   704 	if ( !get_option('users_can_register') ) {
   647 		wp_redirect( site_url('wp-login.php?registration=disabled') );
   705 		wp_redirect( site_url('wp-login.php?registration=disabled') );
   671 	 */
   729 	 */
   672 	$redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
   730 	$redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
   673 	login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
   731 	login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
   674 ?>
   732 ?>
   675 
   733 
   676 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url('wp-login.php?action=register', 'login_post') ); ?>" method="post">
   734 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url('wp-login.php?action=register', 'login_post') ); ?>" method="post" novalidate="novalidate">
   677 	<p>
   735 	<p>
   678 		<label for="user_login"><?php _e('Username') ?><br />
   736 		<label for="user_login"><?php _e('Username') ?><br />
   679 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label>
   737 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label>
   680 	</p>
   738 	</p>
   681 	<p>
   739 	<p>
   682 		<label for="user_email"><?php _e('E-mail') ?><br />
   740 		<label for="user_email"><?php _e('E-mail') ?><br />
   683 		<input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(wp_unslash($user_email)); ?>" size="25" /></label>
   741 		<input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label>
   684 	</p>
   742 	</p>
   685 	<?php
   743 	<?php
   686 	/**
   744 	/**
   687 	 * Fires following the 'E-mail' field in the user registration form.
   745 	 * Fires following the 'E-mail' field in the user registration form.
   688 	 *
   746 	 *
   732 		$redirect_to = admin_url();
   790 		$redirect_to = admin_url();
   733 	}
   791 	}
   734 
   792 
   735 	$reauth = empty($_REQUEST['reauth']) ? false : true;
   793 	$reauth = empty($_REQUEST['reauth']) ? false : true;
   736 
   794 
   737 	// If the user was redirected to a secure login form from a non-secure admin page, and secure login is required but secure admin is not, then don't use a secure
   795 	$user = wp_signon( '', $secure_cookie );
   738 	// cookie and redirect back to the referring non-secure admin page. This allows logins to always be POSTed over SSL while allowing the user to choose visiting
   796 
   739 	// the admin via http or https.
   797 	if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
   740 	if ( !$secure_cookie && is_ssl() && force_ssl_login() && !force_ssl_admin() && ( 0 !== strpos($redirect_to, 'https') ) && ( 0 === strpos($redirect_to, 'http') ) )
   798 		if ( headers_sent() ) {
   741 		$secure_cookie = false;
   799 			$user = new WP_Error( 'test_cookie', sprintf( __( '<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>.' ),
   742 
   800 				__( 'https://codex.wordpress.org/Cookies' ), __( 'https://wordpress.org/support/' ) ) );
   743 	// If cookies are disabled we can't log in even with a valid user+pass
   801 		} elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
   744 	if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
   802 			// If cookies are disabled we can't log in even with a valid user+pass
   745 		$user = new WP_Error('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
   803 			$user = new WP_Error( 'test_cookie', sprintf( __( '<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.' ),
   746 	else
   804 				__( 'https://codex.wordpress.org/Cookies' ) ) );
   747 		$user = wp_signon('', $secure_cookie);
   805 		}
       
   806 	}
   748 
   807 
   749 	$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   808 	$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   750 	/**
   809 	/**
   751 	 * Filter the login redirect URL.
   810 	 * Filter the login redirect URL.
   752 	 *
   811 	 *
   806 		elseif	( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
   865 		elseif	( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
   807 			$errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
   866 			$errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
   808 		elseif	( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
   867 		elseif	( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
   809 			$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
   868 			$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
   810 		elseif ( strpos( $redirect_to, 'about.php?updated' ) )
   869 		elseif ( strpos( $redirect_to, 'about.php?updated' ) )
   811 			$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
   870 			$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
   812 	}
   871 	}
   813 
   872 
   814 	/**
   873 	/**
   815 	 * Filter the login page errors.
   874 	 * Filter the login page errors.
   816 	 *
   875 	 *
   828 	login_header(__('Log In'), '', $errors);
   887 	login_header(__('Log In'), '', $errors);
   829 
   888 
   830 	if ( isset($_POST['log']) )
   889 	if ( isset($_POST['log']) )
   831 		$user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? esc_attr(wp_unslash($_POST['log'])) : '';
   890 		$user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? esc_attr(wp_unslash($_POST['log'])) : '';
   832 	$rememberme = ! empty( $_POST['rememberme'] );
   891 	$rememberme = ! empty( $_POST['rememberme'] );
       
   892 
       
   893 	if ( ! empty( $errors->errors ) ) {
       
   894 		$aria_describedby_error = ' aria-describedby="login_error"';
       
   895 	} else {
       
   896 		$aria_describedby_error = '';
       
   897 	}
   833 ?>
   898 ?>
   834 
   899 
   835 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
   900 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
   836 	<p>
   901 	<p>
   837 		<label for="user_login"><?php _e('Username') ?><br />
   902 		<label for="user_login"><?php _e('Username') ?><br />
   838 		<input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
   903 		<input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" /></label>
   839 	</p>
   904 	</p>
   840 	<p>
   905 	<p>
   841 		<label for="user_pass"><?php _e('Password') ?><br />
   906 		<label for="user_pass"><?php _e('Password') ?><br />
   842 		<input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
   907 		<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input" value="" size="20" /></label>
   843 	</p>
   908 	</p>
   844 	<?php
   909 	<?php
   845 	/**
   910 	/**
   846 	 * Fires following the 'Password' field in the login form.
   911 	 * Fires following the 'Password' field in the login form.
   847 	 *
   912 	 *
   867 <?php if ( ! $interim_login ) { ?>
   932 <?php if ( ! $interim_login ) { ?>
   868 <p id="nav">
   933 <p id="nav">
   869 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
   934 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
   870 	if ( get_option( 'users_can_register' ) ) :
   935 	if ( get_option( 'users_can_register' ) ) :
   871 		$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   936 		$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   872 		/** This filter is documented in wp-login.php */
   937 
       
   938 		/** This filter is documented in wp-includes/general-template.php */
   873 		echo apply_filters( 'register', $registration_url ) . ' | ';
   939 		echo apply_filters( 'register', $registration_url ) . ' | ';
   874 	endif;
   940 	endif;
   875 	?>
   941 	?>
   876 	<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
   942 	<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
   877 <?php endif; ?>
   943 <?php endif; ?>
   879 <?php } ?>
   945 <?php } ?>
   880 
   946 
   881 <script type="text/javascript">
   947 <script type="text/javascript">
   882 function wp_attempt_focus(){
   948 function wp_attempt_focus(){
   883 setTimeout( function(){ try{
   949 setTimeout( function(){ try{
   884 <?php if ( $user_login || $interim_login ) { ?>
   950 <?php if ( $user_login ) { ?>
   885 d = document.getElementById('user_pass');
   951 d = document.getElementById('user_pass');
   886 d.value = '';
   952 d.value = '';
   887 <?php } else { ?>
   953 <?php } else { ?>
   888 d = document.getElementById('user_login');
   954 d = document.getElementById('user_login');
   889 <?php if ( 'invalid_username' == $errors->get_error_code() ) { ?>
   955 <?php if ( 'invalid_username' == $errors->get_error_code() ) { ?>