wp-login.php 37 KB

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