wp/wp-login.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
    12 require( dirname(__FILE__) . '/wp-load.php' );
    12 require( dirname(__FILE__) . '/wp-load.php' );
    13 
    13 
    14 // Redirect to https login if forced to use SSL
    14 // Redirect to https login if forced to use SSL
    15 if ( force_ssl_admin() && ! is_ssl() ) {
    15 if ( force_ssl_admin() && ! is_ssl() ) {
    16 	if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
    16 	if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
    17 		wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
    17 		wp_safe_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
    18 		exit();
    18 		exit();
    19 	} else {
    19 	} else {
    20 		wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    20 		wp_safe_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
    21 		exit();
    21 		exit();
    22 	}
    22 	}
    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 login Page title to display in the `<title>` element.
    28  * @param string   $title    Optional. WordPress login Page title to display in the `<title>` element.
    29  *                           Default 'Log In'.
    29  *                           Default 'Log In'.
    30  * @param string   $message  Optional. Message to display in header. Default empty.
    30  * @param string   $message  Optional. Message to display in header. Default empty.
    31  * @param WP_Error $wp_error Optional. The error to pass. Default empty.
    31  * @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance.
    32  */
    32  */
    33 function login_header( $title = 'Log In', $message = '', $wp_error = '' ) {
    33 function login_header( $title = 'Log In', $message = '', $wp_error = null ) {
    34 	global $error, $interim_login, $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 	add_action( 'login_head', 'wp_login_viewport_meta' );
    40 		add_action( 'login_head', 'wp_login_viewport_meta' );
    40 
    41 
    41 	if ( ! is_wp_error( $wp_error ) ) {
    42 	if ( empty($wp_error) )
       
    43 		$wp_error = new WP_Error();
    42 		$wp_error = new WP_Error();
       
    43 	}
    44 
    44 
    45 	// Shake it!
    45 	// Shake it!
    46 	$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
    46 	$shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
    47 	/**
    47 	/**
    48 	 * Filter the error codes array for shaking the login form.
    48 	 * Filters the error codes array for shaking the login form.
    49 	 *
    49 	 *
    50 	 * @since 3.0.0
    50 	 * @since 3.0.0
    51 	 *
    51 	 *
    52 	 * @param array $shake_error_codes Error codes that shake the login form.
    52 	 * @param array $shake_error_codes Error codes that shake the login form.
    53 	 */
    53 	 */
    54 	$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
    54 	$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
    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 
       
    59 	$login_title = get_bloginfo( 'name', 'display' );
       
    60 
       
    61 	/* translators: Login screen title. 1: Login screen name, 2: Network or site name */
       
    62 	$login_title = sprintf( __( '%1$s &lsaquo; %2$s &#8212; WordPress' ), $title, $login_title );
       
    63 
       
    64 	/**
       
    65 	 * Filters the title tag content for login page.
       
    66 	 *
       
    67 	 * @since 4.9.0
       
    68 	 *
       
    69 	 * @param string $login_title The page title, with extra context added.
       
    70 	 * @param string $title       The original page title.
       
    71 	 */
       
    72 	$login_title = apply_filters( 'login_title', $login_title, $title );
    58 
    73 
    59 	?><!DOCTYPE html>
    74 	?><!DOCTYPE html>
    60 	<!--[if IE 8]>
    75 	<!--[if IE 8]>
    61 		<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
    76 		<html xmlns="http://www.w3.org/1999/xhtml" class="ie8" <?php language_attributes(); ?>>
    62 	<![endif]-->
    77 	<![endif]-->
    63 	<!--[if !(IE 8) ]><!-->
    78 	<!--[if !(IE 8) ]><!-->
    64 		<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    79 		<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
    65 	<!--<![endif]-->
    80 	<!--<![endif]-->
    66 	<head>
    81 	<head>
    67 	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    82 	<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
    68 	<title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
    83 	<title><?php echo $login_title; ?></title>
    69 	<?php
    84 	<?php
    70 
    85 
    71 	wp_admin_css( 'login', true );
    86 	wp_enqueue_style( 'login' );
    72 
    87 
    73 	/*
    88 	/*
    74 	 * Remove all stored post data on logging out.
    89 	 * Remove all stored post data on logging out.
    75 	 * This could be added by add_action('login_head'...) like wp_shake_js(),
    90 	 * This could be added by add_action('login_head'...) like wp_shake_js(),
    76 	 * but maybe better if it's not removable by plugins
    91 	 * but maybe better if it's not removable by plugins
    85 	 * Enqueue scripts and styles for the login page.
   100 	 * Enqueue scripts and styles for the login page.
    86 	 *
   101 	 *
    87 	 * @since 3.1.0
   102 	 * @since 3.1.0
    88 	 */
   103 	 */
    89 	do_action( 'login_enqueue_scripts' );
   104 	do_action( 'login_enqueue_scripts' );
       
   105 
    90 	/**
   106 	/**
    91 	 * Fires in the login page header after scripts are enqueued.
   107 	 * Fires in the login page header after scripts are enqueued.
    92 	 *
   108 	 *
    93 	 * @since 2.1.0
   109 	 * @since 2.1.0
    94 	 */
   110 	 */
    95 	do_action( 'login_head' );
   111 	do_action( 'login_head' );
    96 
   112 
    97 	if ( is_multisite() ) {
   113 	if ( is_multisite() ) {
    98 		$login_header_url   = network_home_url();
   114 		$login_header_url   = network_home_url();
    99 		$login_header_title = get_current_site()->site_name;
   115 		$login_header_title = get_network()->site_name;
   100 	} else {
   116 	} else {
   101 		$login_header_url   = __( 'https://wordpress.org/' );
   117 		$login_header_url   = __( 'https://wordpress.org/' );
   102 		$login_header_title = __( 'Powered by WordPress' );
   118 		$login_header_title = __( 'Powered by WordPress' );
   103 	}
   119 	}
   104 
   120 
   105 	/**
   121 	/**
   106 	 * Filter link URL of the header logo above login form.
   122 	 * Filters link URL of the header logo above login form.
   107 	 *
   123 	 *
   108 	 * @since 2.1.0
   124 	 * @since 2.1.0
   109 	 *
   125 	 *
   110 	 * @param string $login_header_url Login header logo URL.
   126 	 * @param string $login_header_url Login header logo URL.
   111 	 */
   127 	 */
   112 	$login_header_url = apply_filters( 'login_headerurl', $login_header_url );
   128 	$login_header_url = apply_filters( 'login_headerurl', $login_header_url );
   113 	/**
   129 
   114 	 * Filter the title attribute of the header logo above login form.
   130 	/**
       
   131 	 * Filters the title attribute of the header logo above login form.
   115 	 *
   132 	 *
   116 	 * @since 2.1.0
   133 	 * @since 2.1.0
   117 	 *
   134 	 *
   118 	 * @param string $login_header_title Login header logo title attribute.
   135 	 * @param string $login_header_title Login header logo title attribute.
   119 	 */
   136 	 */
   120 	$login_header_title = apply_filters( 'login_headertitle', $login_header_title );
   137 	$login_header_title = apply_filters( 'login_headertitle', $login_header_title );
   121 
   138 
       
   139 	/*
       
   140 	 * To match the URL/title set above, Multisite sites have the blog name,
       
   141 	 * while single sites get the header title.
       
   142 	 */
       
   143 	if ( is_multisite() ) {
       
   144 		$login_header_text = get_bloginfo( 'name', 'display' );
       
   145 	} else {
       
   146 		$login_header_text = $login_header_title;
       
   147 	}
       
   148 
   122 	$classes = array( 'login-action-' . $action, 'wp-core-ui' );
   149 	$classes = array( 'login-action-' . $action, 'wp-core-ui' );
   123 	if ( wp_is_mobile() )
       
   124 		$classes[] = 'mobile';
       
   125 	if ( is_rtl() )
   150 	if ( is_rtl() )
   126 		$classes[] = 'rtl';
   151 		$classes[] = 'rtl';
   127 	if ( $interim_login ) {
   152 	if ( $interim_login ) {
   128 		$classes[] = 'interim-login';
   153 		$classes[] = 'interim-login';
   129 		?>
   154 		?>
   134 			$classes[] = 'interim-login-success';
   159 			$classes[] = 'interim-login-success';
   135 	}
   160 	}
   136 	$classes[] =' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
   161 	$classes[] =' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
   137 
   162 
   138 	/**
   163 	/**
   139 	 * Filter the login page body classes.
   164 	 * Filters the login page body classes.
   140 	 *
   165 	 *
   141 	 * @since 3.5.0
   166 	 * @since 3.5.0
   142 	 *
   167 	 *
   143 	 * @param array  $classes An array of body classes.
   168 	 * @param array  $classes An array of body classes.
   144 	 * @param string $action  The action that brought the visitor to the login page.
   169 	 * @param string $action  The action that brought the visitor to the login page.
   146 	$classes = apply_filters( 'login_body_class', $classes, $action );
   171 	$classes = apply_filters( 'login_body_class', $classes, $action );
   147 
   172 
   148 	?>
   173 	?>
   149 	</head>
   174 	</head>
   150 	<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
   175 	<body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
       
   176 	<?php
       
   177 	/**
       
   178 	 * Fires in the login page header after the body tag is opened.
       
   179 	 *
       
   180 	 * @since 4.6.0
       
   181 	 */
       
   182 	do_action( 'login_header' );
       
   183 	?>
   151 	<div id="login">
   184 	<div id="login">
   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>
   185 		<h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>" tabindex="-1"><?php echo $login_header_text; ?></a></h1>
   153 	<?php
   186 	<?php
   154 
   187 
   155 	unset( $login_header_url, $login_header_title );
   188 	unset( $login_header_url, $login_header_title );
   156 
   189 
   157 	/**
   190 	/**
   158 	 * Filter the message to display above the login form.
   191 	 * Filters the message to display above the login form.
   159 	 *
   192 	 *
   160 	 * @since 2.1.0
   193 	 * @since 2.1.0
   161 	 *
   194 	 *
   162 	 * @param string $message Login message text.
   195 	 * @param string $message Login message text.
   163 	 */
   196 	 */
   183 					$errors .= '	' . $error_message . "<br />\n";
   216 					$errors .= '	' . $error_message . "<br />\n";
   184 			}
   217 			}
   185 		}
   218 		}
   186 		if ( ! empty( $errors ) ) {
   219 		if ( ! empty( $errors ) ) {
   187 			/**
   220 			/**
   188 			 * Filter the error messages displayed above the login form.
   221 			 * Filters the error messages displayed above the login form.
   189 			 *
   222 			 *
   190 			 * @since 2.1.0
   223 			 * @since 2.1.0
   191 			 *
   224 			 *
   192 			 * @param string $errors Login error message.
   225 			 * @param string $errors Login error message.
   193 			 */
   226 			 */
   194 			echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
   227 			echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
   195 		}
   228 		}
   196 		if ( ! empty( $messages ) ) {
   229 		if ( ! empty( $messages ) ) {
   197 			/**
   230 			/**
   198 			 * Filter instructional messages displayed above the login form.
   231 			 * Filters instructional messages displayed above the login form.
   199 			 *
   232 			 *
   200 			 * @since 2.5.0
   233 			 * @since 2.5.0
   201 			 *
   234 			 *
   202 			 * @param string $messages Login messages.
   235 			 * @param string $messages Login messages.
   203 			 */
   236 			 */
   214 function login_footer($input_id = '') {
   247 function login_footer($input_id = '') {
   215 	global $interim_login;
   248 	global $interim_login;
   216 
   249 
   217 	// Don't allow interim logins to navigate away from the page.
   250 	// Don't allow interim logins to navigate away from the page.
   218 	if ( ! $interim_login ): ?>
   251 	if ( ! $interim_login ): ?>
   219 	<p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr_e( 'Are you lost?' ); ?>"><?php printf( __( '&larr; Back to %s' ), get_bloginfo( 'title', 'display' ) ); ?></a></p>
   252 	<p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php
       
   253 		/* translators: %s: site title */
       
   254 		printf( _x( '&larr; Back to %s', 'site' ), get_bloginfo( 'title', 'display' ) );
       
   255 	?></a></p>
       
   256 	<?php the_privacy_policy_link( '<div class="privacy-policy-page-link">', '</div>' ); ?>
   220 	<?php endif; ?>
   257 	<?php endif; ?>
   221 
   258 
   222 	</div>
   259 	</div>
   223 
   260 
   224 	<?php if ( !empty($input_id) ) : ?>
   261 	<?php if ( !empty($input_id) ) : ?>
   239 	</body>
   276 	</body>
   240 	</html>
   277 	</html>
   241 	<?php
   278 	<?php
   242 }
   279 }
   243 
   280 
       
   281 /**
       
   282  * @since 3.0.0
       
   283  */
   244 function wp_shake_js() {
   284 function wp_shake_js() {
   245 	if ( wp_is_mobile() )
       
   246 		return;
       
   247 ?>
   285 ?>
   248 <script type="text/javascript">
   286 <script type="text/javascript">
   249 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
   287 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
   250 function s(id,pos){g(id).left=pos+'px';}
   288 function s(id,pos){g(id).left=pos+'px';}
   251 function g(id){return document.getElementById(id).style;}
   289 function g(id){return document.getElementById(id).style;}
   253 addLoadEvent(function(){ var p=new Array(15,30,15,0,-15,-30,-15,0);p=p.concat(p.concat(p));var i=document.forms[0].id;g(i).position='relative';shake(i,p,20);});
   291 addLoadEvent(function(){ var p=new Array(15,30,15,0,-15,-30,-15,0);p=p.concat(p.concat(p));var i=document.forms[0].id;g(i).position='relative';shake(i,p,20);});
   254 </script>
   292 </script>
   255 <?php
   293 <?php
   256 }
   294 }
   257 
   295 
       
   296 /**
       
   297  * @since 3.7.0
       
   298  */
   258 function wp_login_viewport_meta() {
   299 function wp_login_viewport_meta() {
   259 	?>
   300 	?>
   260 	<meta name="viewport" content="width=device-width" />
   301 	<meta name="viewport" content="width=device-width" />
   261 	<?php
   302 	<?php
   262 }
   303 }
   263 
   304 
   264 /**
   305 /**
   265  * Handles sending password retrieval email to user.
   306  * Handles sending password retrieval email to user.
   266  *
   307  *
   267  * @global wpdb         $wpdb      WordPress database abstraction object.
       
   268  * @global PasswordHash $wp_hasher Portable PHP password hashing framework.
       
   269  *
       
   270  * @return bool|WP_Error True: when finish. WP_Error on error
   308  * @return bool|WP_Error True: when finish. WP_Error on error
   271  */
   309  */
   272 function retrieve_password() {
   310 function retrieve_password() {
   273 	global $wpdb, $wp_hasher;
       
   274 
       
   275 	$errors = new WP_Error();
   311 	$errors = new WP_Error();
   276 
   312 
   277 	if ( empty( $_POST['user_login'] ) ) {
   313 	if ( empty( $_POST['user_login'] ) || ! is_string( $_POST['user_login'] ) ) {
   278 		$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
   314 		$errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or email address.'));
   279 	} elseif ( strpos( $_POST['user_login'], '@' ) ) {
   315 	} elseif ( strpos( $_POST['user_login'], '@' ) ) {
   280 		$user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
   316 		$user_data = get_user_by( 'email', trim( wp_unslash( $_POST['user_login'] ) ) );
   281 		if ( empty( $user_data ) )
   317 		if ( empty( $user_data ) )
   282 			$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
   318 			$errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
   283 	} else {
   319 	} else {
   284 		$login = trim($_POST['user_login']);
   320 		$login = trim($_POST['user_login']);
   285 		$user_data = get_user_by('login', $login);
   321 		$user_data = get_user_by('login', $login);
   287 
   323 
   288 	/**
   324 	/**
   289 	 * Fires before errors are returned from a password reset request.
   325 	 * Fires before errors are returned from a password reset request.
   290 	 *
   326 	 *
   291 	 * @since 2.1.0
   327 	 * @since 2.1.0
   292 	 */
   328 	 * @since 4.4.0 Added the `$errors` parameter.
   293 	do_action( 'lostpassword_post' );
   329 	 *
       
   330 	 * @param WP_Error $errors A WP_Error object containing any errors generated
       
   331 	 *                         by using invalid credentials.
       
   332 	 */
       
   333 	do_action( 'lostpassword_post', $errors );
   294 
   334 
   295 	if ( $errors->get_error_code() )
   335 	if ( $errors->get_error_code() )
   296 		return $errors;
   336 		return $errors;
   297 
   337 
   298 	if ( !$user_data ) {
   338 	if ( !$user_data ) {
   299 		$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
   339 		$errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or email.'));
   300 		return $errors;
   340 		return $errors;
   301 	}
   341 	}
   302 
   342 
   303 	// Redefining user_login ensures we return the right case in the email.
   343 	// Redefining user_login ensures we return the right case in the email.
   304 	$user_login = $user_data->user_login;
   344 	$user_login = $user_data->user_login;
   305 	$user_email = $user_data->user_email;
   345 	$user_email = $user_data->user_email;
   306 
   346 	$key = get_password_reset_key( $user_data );
   307 	/**
   347 
   308 	 * Fires before a new password is retrieved.
   348 	if ( is_wp_error( $key ) ) {
   309 	 *
   349 		return $key;
   310 	 * @since 1.5.0
   350 	}
   311 	 * @deprecated 1.5.1 Misspelled. Use 'retrieve_password' hook instead.
   351 
   312 	 *
   352 	if ( is_multisite() ) {
   313 	 * @param string $user_login The user login name.
   353 		$site_name = get_network()->site_name;
   314 	 */
   354 	} else {
   315 	do_action( 'retreive_password', $user_login );
       
   316 
       
   317 	/**
       
   318 	 * Fires before a new password is retrieved.
       
   319 	 *
       
   320 	 * @since 1.5.1
       
   321 	 *
       
   322 	 * @param string $user_login The user login name.
       
   323 	 */
       
   324 	do_action( 'retrieve_password', $user_login );
       
   325 
       
   326 	/**
       
   327 	 * Filter whether to allow a password to be reset.
       
   328 	 *
       
   329 	 * @since 2.7.0
       
   330 	 *
       
   331 	 * @param bool true           Whether to allow the password to be reset. Default true.
       
   332 	 * @param int  $user_data->ID The ID of the user attempting to reset a password.
       
   333 	 */
       
   334 	$allow = apply_filters( 'allow_password_reset', true, $user_data->ID );
       
   335 
       
   336 	if ( ! $allow ) {
       
   337 		return new WP_Error( 'no_password_reset', __('Password reset is not allowed for this user') );
       
   338 	} elseif ( is_wp_error( $allow ) ) {
       
   339 		return $allow;
       
   340 	}
       
   341 
       
   342 	// Generate something random for a password reset key.
       
   343 	$key = wp_generate_password( 20, false );
       
   344 
       
   345 	/**
       
   346 	 * Fires when a password reset key is generated.
       
   347 	 *
       
   348 	 * @since 2.5.0
       
   349 	 *
       
   350 	 * @param string $user_login The username for the user.
       
   351 	 * @param string $key        The generated password reset key.
       
   352 	 */
       
   353 	do_action( 'retrieve_password_key', $user_login, $key );
       
   354 
       
   355 	// Now insert the key, hashed, into the DB.
       
   356 	if ( empty( $wp_hasher ) ) {
       
   357 		require_once ABSPATH . WPINC . '/class-phpass.php';
       
   358 		$wp_hasher = new PasswordHash( 8, true );
       
   359 	}
       
   360 	$hashed = $wp_hasher->HashPassword( $key );
       
   361 	$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user_login ) );
       
   362 
       
   363 	$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
       
   364 	$message .= network_home_url( '/' ) . "\r\n\r\n";
       
   365 	$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
       
   366 	$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
       
   367 	$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
       
   368 	$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
       
   369 
       
   370 	if ( is_multisite() )
       
   371 		$blogname = $GLOBALS['current_site']->site_name;
       
   372 	else
       
   373 		/*
   355 		/*
   374 		 * The blogname option is escaped with esc_html on the way into the database
   356 		 * 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.
   357 		 * in sanitize_option we want to reverse this for the plain text arena of emails.
   376 		 */
   358 		 */
   377 		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
   359 		$site_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
   378 
   360 	}
   379 	$title = sprintf( __('[%s] Password Reset'), $blogname );
   361 
   380 
   362 	$message = __( 'Someone has requested a password reset for the following account:' ) . "\r\n\r\n";
   381 	/**
   363 	/* translators: %s: site name */
   382 	 * Filter the subject of the password reset email.
   364 	$message .= sprintf( __( 'Site Name: %s'), $site_name ) . "\r\n\r\n";
       
   365 	/* translators: %s: user login */
       
   366 	$message .= sprintf( __( 'Username: %s'), $user_login ) . "\r\n\r\n";
       
   367 	$message .= __( 'If this was a mistake, just ignore this email and nothing will happen.' ) . "\r\n\r\n";
       
   368 	$message .= __( 'To reset your password, visit the following address:' ) . "\r\n\r\n";
       
   369 	$message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user_login ), 'login' ) . ">\r\n";
       
   370 
       
   371 	/* translators: Password reset email subject. %s: Site name */
       
   372 	$title = sprintf( __( '[%s] Password Reset' ), $site_name );
       
   373 
       
   374 	/**
       
   375 	 * Filters the subject of the password reset email.
   383 	 *
   376 	 *
   384 	 * @since 2.8.0
   377 	 * @since 2.8.0
   385 	 *
   378 	 * @since 4.4.0 Added the `$user_login` and `$user_data` parameters.
   386 	 * @param string $title Default email title.
   379 	 *
   387 	 */
   380 	 * @param string  $title      Default email title.
   388 	$title = apply_filters( 'retrieve_password_title', $title );
   381 	 * @param string  $user_login The username for the user.
   389 
   382 	 * @param WP_User $user_data  WP_User object.
   390 	/**
   383 	 */
   391 	 * Filter the message body of the password reset mail.
   384 	$title = apply_filters( 'retrieve_password_title', $title, $user_login, $user_data );
       
   385 
       
   386 	/**
       
   387 	 * Filters the message body of the password reset mail.
       
   388 	 *
       
   389 	 * If the filtered message is empty, the password reset email will not be sent.
   392 	 *
   390 	 *
   393 	 * @since 2.8.0
   391 	 * @since 2.8.0
   394 	 * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
   392 	 * @since 4.1.0 Added `$user_login` and `$user_data` parameters.
   395 	 *
   393 	 *
   396 	 * @param string  $message    Default mail message.
   394 	 * @param string  $message    Default mail message.
   399 	 * @param WP_User $user_data  WP_User object.
   397 	 * @param WP_User $user_data  WP_User object.
   400 	 */
   398 	 */
   401 	$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
   399 	$message = apply_filters( 'retrieve_password_message', $message, $key, $user_login, $user_data );
   402 
   400 
   403 	if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
   401 	if ( $message && !wp_mail( $user_email, wp_specialchars_decode( $title ), $message ) )
   404 		wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
   402 		wp_die( __('The email could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function.') );
   405 
   403 
   406 	return true;
   404 	return true;
   407 }
   405 }
   408 
   406 
   409 //
   407 //
   415 
   413 
   416 if ( isset($_GET['key']) )
   414 if ( isset($_GET['key']) )
   417 	$action = 'resetpass';
   415 	$action = 'resetpass';
   418 
   416 
   419 // validate action so as to default to the login screen
   417 // validate action so as to default to the login screen
   420 if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login' ), true ) && false === has_filter( 'login_form_' . $action ) )
   418 if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login', 'confirmaction' ), true ) && false === has_filter( 'login_form_' . $action ) )
   421 	$action = 'login';
   419 	$action = 'login';
   422 
   420 
   423 nocache_headers();
   421 nocache_headers();
   424 
   422 
   425 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
   423 header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
   432 	if ( $url != get_option( 'siteurl' ) )
   430 	if ( $url != get_option( 'siteurl' ) )
   433 		update_option( 'siteurl', $url );
   431 		update_option( 'siteurl', $url );
   434 }
   432 }
   435 
   433 
   436 //Set a cookie now to see if they are supported by the browser.
   434 //Set a cookie now to see if they are supported by the browser.
   437 $secure = ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) && 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
   435 $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
   438 setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
   436 setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
   439 if ( SITECOOKIEPATH != COOKIEPATH )
   437 if ( SITECOOKIEPATH != COOKIEPATH )
   440 	setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
   438 	setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
       
   439 
       
   440 $lang            = ! empty( $_GET['wp_lang'] ) ? sanitize_text_field( $_GET['wp_lang'] ) : '';
       
   441 $switched_locale = switch_to_locale( $lang );
   441 
   442 
   442 /**
   443 /**
   443  * Fires when the login form is initialized.
   444  * Fires when the login form is initialized.
   444  *
   445  *
   445  * @since 3.2.0
   446  * @since 3.2.0
   446  */
   447  */
   447 do_action( 'login_init' );
   448 do_action( 'login_init' );
       
   449 
   448 /**
   450 /**
   449  * Fires before a specified login form action.
   451  * Fires before a specified login form action.
   450  *
   452  *
   451  * The dynamic portion of the hook name, `$action`, refers to the action
   453  * The dynamic portion of the hook name, `$action`, refers to the action
   452  * that brought the visitor to the login form. Actions include 'postpass',
   454  * that brought the visitor to the login form. Actions include 'postpass',
   453  * 'logout', 'lostpassword', etc.
   455  * 'logout', 'lostpassword', etc.
   454  *
   456  *
   455  * @since 2.8.0
   457  * @since 2.8.0
   456  */
   458  */
   457 do_action( 'login_form_' . $action );
   459 do_action( "login_form_{$action}" );
   458 
   460 
   459 $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
   461 $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
   460 $interim_login = isset($_REQUEST['interim-login']);
   462 $interim_login = isset($_REQUEST['interim-login']);
   461 
   463 
       
   464 /**
       
   465  * Filters the separator used between login form navigation links.
       
   466  *
       
   467  * @since 4.9.0
       
   468  *
       
   469  * @param string $login_link_separator The separator used between login form navigation links.
       
   470  */
       
   471 $login_link_separator = apply_filters( 'login_link_separator', ' | ' );
       
   472 
   462 switch ($action) {
   473 switch ($action) {
   463 
   474 
   464 case 'postpass' :
   475 case 'postpass' :
       
   476 	if ( ! array_key_exists( 'post_password', $_POST ) ) {
       
   477 		wp_safe_redirect( wp_get_referer() );
       
   478 		exit();
       
   479 	}
       
   480 
   465 	require_once ABSPATH . WPINC . '/class-phpass.php';
   481 	require_once ABSPATH . WPINC . '/class-phpass.php';
   466 	$hasher = new PasswordHash( 8, true );
   482 	$hasher = new PasswordHash( 8, true );
   467 
   483 
   468 	/**
   484 	/**
   469 	 * Filter the life span of the post password cookie.
   485 	 * Filters the life span of the post password cookie.
   470 	 *
   486 	 *
   471 	 * By default, the cookie expires 10 days from creation. To turn this
   487 	 * By default, the cookie expires 10 days from creation. To turn this
   472 	 * into a session cookie, return 0.
   488 	 * into a session cookie, return 0.
   473 	 *
   489 	 *
   474 	 * @since 3.7.0
   490 	 * @since 3.7.0
   475 	 *
   491 	 *
   476 	 * @param int $expires The expiry time, as passed to setcookie().
   492 	 * @param int $expires The expiry time, as passed to setcookie().
   477 	 */
   493 	 */
   478 	$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
   494 	$expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
   479 	$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) );
   495 	$referer = wp_get_referer();
       
   496 	if ( $referer ) {
       
   497 		$secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
       
   498 	} else {
       
   499 		$secure = false;
       
   500 	}
   480 	setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
   501 	setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
       
   502 
       
   503 	if ( $switched_locale ) {
       
   504 	    restore_previous_locale();
       
   505 	}
   481 
   506 
   482 	wp_safe_redirect( wp_get_referer() );
   507 	wp_safe_redirect( wp_get_referer() );
   483 	exit();
   508 	exit();
   484 
   509 
   485 case 'logout' :
   510 case 'logout' :
   494 	} else {
   519 	} else {
   495 		$redirect_to = 'wp-login.php?loggedout=true';
   520 		$redirect_to = 'wp-login.php?loggedout=true';
   496 		$requested_redirect_to = '';
   521 		$requested_redirect_to = '';
   497 	}
   522 	}
   498 
   523 
   499 	/**
   524 	if ( $switched_locale ) {
   500 	 * Filter the log out redirect URL.
   525 	    restore_previous_locale();
       
   526 	}
       
   527 
       
   528 	/**
       
   529 	 * Filters the log out redirect URL.
   501 	 *
   530 	 *
   502 	 * @since 4.2.0
   531 	 * @since 4.2.0
   503 	 *
   532 	 *
   504 	 * @param string  $redirect_to           The redirect destination URL.
   533 	 * @param string  $redirect_to           The redirect destination URL.
   505 	 * @param string  $requested_redirect_to The requested redirect destination URL passed as a parameter.
   534 	 * @param string  $requested_redirect_to The requested redirect destination URL passed as a parameter.
   520 			exit();
   549 			exit();
   521 		}
   550 		}
   522 	}
   551 	}
   523 
   552 
   524 	if ( isset( $_GET['error'] ) ) {
   553 	if ( isset( $_GET['error'] ) ) {
   525 		if ( 'invalidkey' == $_GET['error'] )
   554 		if ( 'invalidkey' == $_GET['error'] ) {
   526 			$errors->add( 'invalidkey', __( 'Sorry, that key does not appear to be valid.' ) );
   555 			$errors->add( 'invalidkey', __( 'Your password reset link appears to be invalid. Please request a new link below.' ) );
   527 		elseif ( 'expiredkey' == $_GET['error'] )
   556 		} elseif ( 'expiredkey' == $_GET['error'] ) {
   528 			$errors->add( 'expiredkey', __( 'Sorry, that key has expired. Please try again.' ) );
   557 			$errors->add( 'expiredkey', __( 'Your password reset link has expired. Please request a new link below.' ) );
       
   558 		}
   529 	}
   559 	}
   530 
   560 
   531 	$lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   561 	$lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   532 	/**
   562 	/**
   533 	 * Filter the URL redirected to after submitting the lostpassword/retrievepassword form.
   563 	 * Filters the URL redirected to after submitting the lostpassword/retrievepassword form.
   534 	 *
   564 	 *
   535 	 * @since 3.0.0
   565 	 * @since 3.0.0
   536 	 *
   566 	 *
   537 	 * @param string $lostpassword_redirect The redirect destination URL.
   567 	 * @param string $lostpassword_redirect The redirect destination URL.
   538 	 */
   568 	 */
   545 	 */
   575 	 */
   546 	do_action( 'lost_password' );
   576 	do_action( 'lost_password' );
   547 
   577 
   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);
   578 	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);
   549 
   579 
   550 	$user_login = isset($_POST['user_login']) ? wp_unslash($_POST['user_login']) : '';
   580 	$user_login = '';
       
   581 
       
   582 	if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
       
   583 		$user_login = wp_unslash( $_POST['user_login'] );
       
   584 	}
   551 
   585 
   552 ?>
   586 ?>
   553 
   587 
   554 <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
   588 <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
   555 	<p>
   589 	<p>
   556 		<label for="user_login" ><?php _e('Username or E-mail:') ?><br />
   590 		<label for="user_login" ><?php _e( 'Username or Email Address' ); ?><br />
   557 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
   591 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
   558 	</p>
   592 	</p>
   559 	<?php
   593 	<?php
   560 	/**
   594 	/**
   561 	 * Fires inside the lostpassword form tags, before the hidden fields.
   595 	 * Fires inside the lostpassword form tags, before the hidden fields.
   571 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
   605 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
   572 <?php
   606 <?php
   573 if ( get_option( 'users_can_register' ) ) :
   607 if ( get_option( 'users_can_register' ) ) :
   574 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   608 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   575 
   609 
       
   610 	echo esc_html( $login_link_separator );
       
   611 
   576 	/** This filter is documented in wp-includes/general-template.php */
   612 	/** This filter is documented in wp-includes/general-template.php */
   577 	echo ' | ' . apply_filters( 'register', $registration_url );
   613 	echo apply_filters( 'register', $registration_url );
   578 endif;
   614 endif;
   579 ?>
   615 ?>
   580 </p>
   616 </p>
   581 
   617 
   582 <?php
   618 <?php
   583 login_footer('user_login');
   619 login_footer('user_login');
       
   620 
       
   621 if ( $switched_locale ) {
       
   622     restore_previous_locale();
       
   623 }
       
   624 
   584 break;
   625 break;
   585 
   626 
   586 case 'resetpass' :
   627 case 'resetpass' :
   587 case 'rp' :
   628 case 'rp' :
   588 	list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
   629 	list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
   643 
   684 
   644 ?>
   685 ?>
   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">
   686 <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
   646 	<input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
   687 	<input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
   647 
   688 
   648 	<p>
   689 	<div class="user-pass1-wrap">
   649 		<label for="pass1"><?php _e('New password') ?><br />
   690 		<p>
   650 		<input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" /></label>
   691 			<label for="pass1"><?php _e( 'New password' ) ?></label>
       
   692 		</p>
       
   693 
       
   694 		<div class="wp-pwd">
       
   695 			<div class="password-input-wrapper">
       
   696 				<input type="password" data-reveal="1" data-pw="<?php echo esc_attr( wp_generate_password( 16 ) ); ?>" name="pass1" id="pass1" class="input password-input" size="24" value="" autocomplete="off" aria-describedby="pass-strength-result" />
       
   697 				<span class="button button-secondary wp-hide-pw hide-if-no-js">
       
   698 					<span class="dashicons dashicons-hidden"></span>
       
   699 				</span>
       
   700 			</div>
       
   701 			<div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e( 'Strength indicator' ); ?></div>
       
   702 		</div>
       
   703 		<div class="pw-weak">
       
   704 			<label>
       
   705 				<input type="checkbox" name="pw_weak" class="pw-checkbox" />
       
   706 				<?php _e( 'Confirm use of weak password' ); ?>
       
   707 			</label>
       
   708 		</div>
       
   709 	</div>
       
   710 
       
   711 	<p class="user-pass2-wrap">
       
   712 		<label for="pass2"><?php _e( 'Confirm new password' ) ?></label><br />
       
   713 		<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" />
   651 	</p>
   714 	</p>
   652 	<p>
   715 
   653 		<label for="pass2"><?php _e('Confirm new password') ?><br />
       
   654 		<input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /></label>
       
   655 	</p>
       
   656 
       
   657 	<div id="pass-strength-result" class="hide-if-no-js"><?php _e('Strength indicator'); ?></div>
       
   658 	<p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
   716 	<p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
   659 	<br class="clear" />
   717 	<br class="clear" />
   660 
   718 
   661 	<?php
   719 	<?php
   662 	/**
   720 	/**
   676 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
   734 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
   677 <?php
   735 <?php
   678 if ( get_option( 'users_can_register' ) ) :
   736 if ( get_option( 'users_can_register' ) ) :
   679 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   737 	$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   680 
   738 
       
   739 	echo esc_html( $login_link_separator );
       
   740 
   681 	/** This filter is documented in wp-includes/general-template.php */
   741 	/** This filter is documented in wp-includes/general-template.php */
   682 	echo ' | ' . apply_filters( 'register', $registration_url );
   742 	echo apply_filters( 'register', $registration_url );
   683 endif;
   743 endif;
   684 ?>
   744 ?>
   685 </p>
   745 </p>
   686 
   746 
   687 <?php
   747 <?php
   688 login_footer('user_pass');
   748 login_footer('user_pass');
       
   749 
       
   750 if ( $switched_locale ) {
       
   751     restore_previous_locale();
       
   752 }
       
   753 
   689 break;
   754 break;
   690 
   755 
   691 case 'register' :
   756 case 'register' :
   692 	if ( is_multisite() ) {
   757 	if ( is_multisite() ) {
   693 		/**
   758 		/**
   694 		 * Filter the Multisite sign up URL.
   759 		 * Filters the Multisite sign up URL.
   695 		 *
   760 		 *
   696 		 * @since 3.0.0
   761 		 * @since 3.0.0
   697 		 *
   762 		 *
   698 		 * @param string $sign_up_url The sign up URL.
   763 		 * @param string $sign_up_url The sign up URL.
   699 		 */
   764 		 */
   706 		exit();
   771 		exit();
   707 	}
   772 	}
   708 
   773 
   709 	$user_login = '';
   774 	$user_login = '';
   710 	$user_email = '';
   775 	$user_email = '';
       
   776 
   711 	if ( $http_post ) {
   777 	if ( $http_post ) {
   712 		$user_login = $_POST['user_login'];
   778 		if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
   713 		$user_email = $_POST['user_email'];
   779 			$user_login = $_POST['user_login'];
       
   780 		}
       
   781 
       
   782 		if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) {
       
   783 			$user_email = wp_unslash( $_POST['user_email'] );
       
   784 		}
       
   785 
   714 		$errors = register_new_user($user_login, $user_email);
   786 		$errors = register_new_user($user_login, $user_email);
   715 		if ( !is_wp_error($errors) ) {
   787 		if ( !is_wp_error($errors) ) {
   716 			$redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
   788 			$redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
   717 			wp_safe_redirect( $redirect_to );
   789 			wp_safe_redirect( $redirect_to );
   718 			exit();
   790 			exit();
   719 		}
   791 		}
   720 	}
   792 	}
   721 
   793 
   722 	$registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   794 	$registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   723 	/**
   795 	/**
   724 	 * Filter the registration redirect URL.
   796 	 * Filters the registration redirect URL.
   725 	 *
   797 	 *
   726 	 * @since 3.0.0
   798 	 * @since 3.0.0
   727 	 *
   799 	 *
   728 	 * @param string $registration_redirect The redirect destination URL.
   800 	 * @param string $registration_redirect The redirect destination URL.
   729 	 */
   801 	 */
   730 	$redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
   802 	$redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
   731 	login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
   803 	login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
   732 ?>
   804 ?>
   733 
   805 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
   734 <form name="registerform" id="registerform" action="<?php echo esc_url( site_url('wp-login.php?action=register', 'login_post') ); ?>" method="post" novalidate="novalidate">
       
   735 	<p>
   806 	<p>
   736 		<label for="user_login"><?php _e('Username') ?><br />
   807 		<label for="user_login"><?php _e('Username') ?><br />
   737 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label>
   808 		<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="20" /></label>
   738 	</p>
   809 	</p>
   739 	<p>
   810 	<p>
   740 		<label for="user_email"><?php _e('E-mail') ?><br />
   811 		<label for="user_email"><?php _e('Email') ?><br />
   741 		<input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label>
   812 		<input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label>
   742 	</p>
   813 	</p>
   743 	<?php
   814 	<?php
   744 	/**
   815 	/**
   745 	 * Fires following the 'E-mail' field in the user registration form.
   816 	 * Fires following the 'Email' field in the user registration form.
   746 	 *
   817 	 *
   747 	 * @since 2.1.0
   818 	 * @since 2.1.0
   748 	 */
   819 	 */
   749 	do_action( 'register_form' );
   820 	do_action( 'register_form' );
   750 	?>
   821 	?>
   751 	<p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
   822 	<p id="reg_passmail"><?php _e( 'Registration confirmation will be emailed to you.' ); ?></p>
   752 	<br class="clear" />
   823 	<br class="clear" />
   753 	<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
   824 	<input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
   754 	<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Register'); ?>" /></p>
   825 	<p class="submit"><input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Register'); ?>" /></p>
   755 </form>
   826 </form>
   756 
   827 
   757 <p id="nav">
   828 <p id="nav">
   758 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
   829 <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
   759 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ) ?>"><?php _e( 'Lost your password?' ); ?></a>
   830 <?php echo esc_html( $login_link_separator ); ?>
       
   831 <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
   760 </p>
   832 </p>
   761 
   833 
   762 <?php
   834 <?php
   763 login_footer('user_login');
   835 login_footer('user_login');
       
   836 
       
   837 if ( $switched_locale ) {
       
   838     restore_previous_locale();
       
   839 }
       
   840 
   764 break;
   841 break;
       
   842 
       
   843 case 'confirmaction' :
       
   844 	if ( ! isset( $_GET['request_id'] ) ) {
       
   845 		wp_die( __( 'Invalid request.' ) );
       
   846 	}
       
   847 
       
   848 	$request_id = (int) $_GET['request_id'];
       
   849 
       
   850 	if ( isset( $_GET['confirm_key'] ) ) {
       
   851 		$key    = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) );
       
   852 		$result = wp_validate_user_request_key( $request_id, $key );
       
   853 	} else {
       
   854 		$result = new WP_Error( 'invalid_key', __( 'Invalid key' ) );
       
   855 	}
       
   856 
       
   857 	if ( is_wp_error( $result ) ) {
       
   858 		wp_die( $result );
       
   859 	}
       
   860 	
       
   861 	/**
       
   862 	 * Fires an action hook when the account action has been confirmed by the user.
       
   863 	 * 
       
   864 	 * Using this you can assume the user has agreed to perform the action by
       
   865 	 * clicking on the link in the confirmation email.
       
   866 	 * 
       
   867 	 * After firing this action hook the page will redirect to wp-login a callback
       
   868 	 * redirects or exits first.
       
   869 	 *
       
   870 	 * @param int $request_id Request ID.
       
   871 	 */
       
   872 	do_action( 'user_request_action_confirmed', $request_id );
       
   873 
       
   874 	$message = _wp_privacy_account_request_confirmed_message( $request_id );
       
   875 
       
   876 	login_header( __( 'User action confirmed.' ), $message );
       
   877 	login_footer();
       
   878 	exit;
   765 
   879 
   766 case 'login' :
   880 case 'login' :
   767 default:
   881 default:
   768 	$secure_cookie = '';
   882 	$secure_cookie = '';
   769 	$customize_login = isset( $_REQUEST['customize-login'] );
   883 	$customize_login = isset( $_REQUEST['customize-login'] );
   771 		wp_enqueue_script( 'customize-base' );
   885 		wp_enqueue_script( 'customize-base' );
   772 
   886 
   773 	// If the user wants ssl but the session is not ssl, force a secure cookie.
   887 	// If the user wants ssl but the session is not ssl, force a secure cookie.
   774 	if ( !empty($_POST['log']) && !force_ssl_admin() ) {
   888 	if ( !empty($_POST['log']) && !force_ssl_admin() ) {
   775 		$user_name = sanitize_user($_POST['log']);
   889 		$user_name = sanitize_user($_POST['log']);
   776 		if ( $user = get_user_by('login', $user_name) ) {
   890 		$user = get_user_by( 'login', $user_name );
       
   891 
       
   892 		if ( ! $user && strpos( $user_name, '@' ) ) {
       
   893 			$user = get_user_by( 'email', $user_name );
       
   894 		}
       
   895 
       
   896 		if ( $user ) {
   777 			if ( get_user_option('use_ssl', $user->ID) ) {
   897 			if ( get_user_option('use_ssl', $user->ID) ) {
   778 				$secure_cookie = true;
   898 				$secure_cookie = true;
   779 				force_ssl_admin(true);
   899 				force_ssl_admin(true);
   780 			}
   900 			}
   781 		}
   901 		}
   790 		$redirect_to = admin_url();
   910 		$redirect_to = admin_url();
   791 	}
   911 	}
   792 
   912 
   793 	$reauth = empty($_REQUEST['reauth']) ? false : true;
   913 	$reauth = empty($_REQUEST['reauth']) ? false : true;
   794 
   914 
   795 	$user = wp_signon( '', $secure_cookie );
   915 	$user = wp_signon( array(), $secure_cookie );
   796 
   916 
   797 	if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
   917 	if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
   798 		if ( headers_sent() ) {
   918 		if ( headers_sent() ) {
       
   919 			/* translators: 1: Browser cookie documentation URL, 2: Support forums URL */
   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>.' ),
   920 			$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>.' ),
   800 				__( 'https://codex.wordpress.org/Cookies' ), __( 'https://wordpress.org/support/' ) ) );
   921 				__( 'https://codex.wordpress.org/Cookies' ), __( 'https://wordpress.org/support/' ) ) );
   801 		} elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
   922 		} elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
   802 			// If cookies are disabled we can't log in even with a valid user+pass
   923 			// If cookies are disabled we can't log in even with a valid user+pass
       
   924 			/* translators: 1: Browser cookie documentation URL */
   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.' ),
   925 			$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.' ),
   804 				__( 'https://codex.wordpress.org/Cookies' ) ) );
   926 				__( 'https://codex.wordpress.org/Cookies' ) ) );
   805 		}
   927 		}
   806 	}
   928 	}
   807 
   929 
   808 	$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   930 	$requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
   809 	/**
   931 	/**
   810 	 * Filter the login redirect URL.
   932 	 * Filters the login redirect URL.
   811 	 *
   933 	 *
   812 	 * @since 3.0.0
   934 	 * @since 3.0.0
   813 	 *
   935 	 *
   814 	 * @param string           $redirect_to           The redirect destination URL.
   936 	 * @param string           $redirect_to           The redirect destination URL.
   815 	 * @param string           $requested_redirect_to The requested redirect destination URL passed as a parameter.
   937 	 * @param string           $requested_redirect_to The requested redirect destination URL passed as a parameter.
   838 			if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )
   960 			if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )
   839 				$redirect_to = user_admin_url();
   961 				$redirect_to = user_admin_url();
   840 			elseif ( is_multisite() && !$user->has_cap('read') )
   962 			elseif ( is_multisite() && !$user->has_cap('read') )
   841 				$redirect_to = get_dashboard_url( $user->ID );
   963 				$redirect_to = get_dashboard_url( $user->ID );
   842 			elseif ( !$user->has_cap('edit_posts') )
   964 			elseif ( !$user->has_cap('edit_posts') )
   843 				$redirect_to = admin_url('profile.php');
   965 				$redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
       
   966 
       
   967 			wp_redirect( $redirect_to );
       
   968 			exit();
   844 		}
   969 		}
   845 		wp_safe_redirect($redirect_to);
   970 		wp_safe_redirect($redirect_to);
   846 		exit();
   971 		exit();
   847 	}
   972 	}
   848 
   973 
   851 	if ( !empty($_GET['loggedout']) || $reauth )
   976 	if ( !empty($_GET['loggedout']) || $reauth )
   852 		$errors = new WP_Error();
   977 		$errors = new WP_Error();
   853 
   978 
   854 	if ( $interim_login ) {
   979 	if ( $interim_login ) {
   855 		if ( ! $errors->get_error_code() )
   980 		if ( ! $errors->get_error_code() )
   856 			$errors->add('expired', __('Session expired. Please log in again. You will not move away from this page.'), 'message');
   981 			$errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' );
   857 	} else {
   982 	} else {
   858 		// Some parts of this script use the main login form to display a message
   983 		// Some parts of this script use the main login form to display a message
   859 		if		( isset($_GET['loggedout']) && true == $_GET['loggedout'] )
   984 		if		( isset($_GET['loggedout']) && true == $_GET['loggedout'] )
   860 			$errors->add('loggedout', __('You are now logged out.'), 'message');
   985 			$errors->add('loggedout', __('You are now logged out.'), 'message');
   861 		elseif	( isset($_GET['registration']) && 'disabled' == $_GET['registration'] )
   986 		elseif	( isset($_GET['registration']) && 'disabled' == $_GET['registration'] )
   862 			$errors->add('registerdisabled', __('User registration is currently not allowed.'));
   987 			$errors->add('registerdisabled', __('User registration is currently not allowed.'));
   863 		elseif	( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
   988 		elseif	( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
   864 			$errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
   989 			$errors->add('confirm', __('Check your email for the confirmation link.'), 'message');
   865 		elseif	( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
   990 		elseif	( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
   866 			$errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
   991 			$errors->add('newpass', __('Check your email for your new password.'), 'message');
   867 		elseif	( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
   992 		elseif	( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
   868 			$errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
   993 			$errors->add('registered', __('Registration complete. Please check your email.'), 'message');
   869 		elseif ( strpos( $redirect_to, 'about.php?updated' ) )
   994 		elseif ( strpos( $redirect_to, 'about.php?updated' ) )
   870 			$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
   995 			$errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
   871 	}
   996 	}
   872 
   997 
   873 	/**
   998 	/**
   874 	 * Filter the login page errors.
   999 	 * Filters the login page errors.
   875 	 *
  1000 	 *
   876 	 * @since 3.6.0
  1001 	 * @since 3.6.0
   877 	 *
  1002 	 *
   878 	 * @param object $errors      WP Error object.
  1003 	 * @param object $errors      WP Error object.
   879 	 * @param string $redirect_to Redirect destination URL.
  1004 	 * @param string $redirect_to Redirect destination URL.
   897 	}
  1022 	}
   898 ?>
  1023 ?>
   899 
  1024 
   900 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
  1025 <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
   901 	<p>
  1026 	<p>
   902 		<label for="user_login"><?php _e('Username') ?><br />
  1027 		<label for="user_login"><?php _e( 'Username or Email Address' ); ?><br />
   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>
  1028 		<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>
   904 	</p>
  1029 	</p>
   905 	<p>
  1030 	<p>
   906 		<label for="user_pass"><?php _e('Password') ?><br />
  1031 		<label for="user_pass"><?php _e( 'Password' ); ?><br />
   907 		<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input" value="" size="20" /></label>
  1032 		<input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input" value="" size="20" /></label>
   908 	</p>
  1033 	</p>
   909 	<?php
  1034 	<?php
   910 	/**
  1035 	/**
   911 	 * Fires following the 'Password' field in the login form.
  1036 	 * Fires following the 'Password' field in the login form.
   912 	 *
  1037 	 *
   913 	 * @since 2.1.0
  1038 	 * @since 2.1.0
   914 	 */
  1039 	 */
   915 	do_action( 'login_form' );
  1040 	do_action( 'login_form' );
   916 	?>
  1041 	?>
   917 	<p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <?php esc_attr_e('Remember Me'); ?></label></p>
  1042 	<p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <?php esc_html_e( 'Remember Me' ); ?></label></p>
   918 	<p class="submit">
  1043 	<p class="submit">
   919 		<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
  1044 		<input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
   920 <?php	if ( $interim_login ) { ?>
  1045 <?php	if ( $interim_login ) { ?>
   921 		<input type="hidden" name="interim-login" value="1" />
  1046 		<input type="hidden" name="interim-login" value="1" />
   922 <?php	} else { ?>
  1047 <?php	} else { ?>
   934 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
  1059 <?php if ( ! isset( $_GET['checkemail'] ) || ! in_array( $_GET['checkemail'], array( 'confirm', 'newpass' ) ) ) :
   935 	if ( get_option( 'users_can_register' ) ) :
  1060 	if ( get_option( 'users_can_register' ) ) :
   936 		$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
  1061 		$registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
   937 
  1062 
   938 		/** This filter is documented in wp-includes/general-template.php */
  1063 		/** This filter is documented in wp-includes/general-template.php */
   939 		echo apply_filters( 'register', $registration_url ) . ' | ';
  1064 		echo apply_filters( 'register', $registration_url );
       
  1065 
       
  1066 		echo esc_html( $login_link_separator );
   940 	endif;
  1067 	endif;
   941 	?>
  1068 	?>
   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>
  1069 	<a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
   943 <?php endif; ?>
  1070 <?php endif; ?>
   944 </p>
  1071 </p>
   945 <?php } ?>
  1072 <?php } ?>
   946 
  1073 
   947 <script type="text/javascript">
  1074 <script type="text/javascript">
   962 d.select();
  1089 d.select();
   963 } catch(e){}
  1090 } catch(e){}
   964 }, 200);
  1091 }, 200);
   965 }
  1092 }
   966 
  1093 
   967 <?php if ( !$error ) { ?>
  1094 <?php
       
  1095 /**
       
  1096  * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
       
  1097  *
       
  1098  * @since 4.8.0
       
  1099  *
       
  1100  * @param bool $print Whether to print the function call. Default true.
       
  1101  */
       
  1102 if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) { ?>
   968 wp_attempt_focus();
  1103 wp_attempt_focus();
   969 <?php } ?>
  1104 <?php } ?>
   970 if(typeof wpOnload=='function')wpOnload();
  1105 if(typeof wpOnload=='function')wpOnload();
   971 <?php if ( $interim_login ) { ?>
  1106 <?php if ( $interim_login ) { ?>
   972 (function(){
  1107 (function(){
   981 <?php } ?>
  1116 <?php } ?>
   982 </script>
  1117 </script>
   983 
  1118 
   984 <?php
  1119 <?php
   985 login_footer();
  1120 login_footer();
       
  1121 
       
  1122 if ( $switched_locale ) {
       
  1123     restore_previous_locale();
       
  1124 }
       
  1125 
   986 break;
  1126 break;
   987 } // end action switch
  1127 } // end action switch