暫無描述

wp-login.php 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449
  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 __DIR__ . '/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. * @since 2.1.0
  26. *
  27. * @global string $error Login error message set by deprecated pluggable wp_login() function
  28. * or plugins replacing it.
  29. * @global bool|string $interim_login Whether interim login modal is being displayed. String 'success'
  30. * upon successful login.
  31. * @global string $action The action that brought the visitor to the login page.
  32. *
  33. * @param string $title Optional. WordPress login Page title to display in the `<title>` element.
  34. * Default 'Log In'.
  35. * @param string $message Optional. Message to display in header. Default empty.
  36. * @param WP_Error $wp_error Optional. The error to pass. Default is a WP_Error instance.
  37. */
  38. function login_header( $title = 'Log In', $message = '', $wp_error = null ) {
  39. global $error, $interim_login, $action;
  40. // Don't index any of these forms.
  41. add_filter( 'wp_robots', 'wp_robots_sensitive_page' );
  42. add_action( 'login_head', 'wp_strict_cross_origin_referrer' );
  43. add_action( 'login_head', 'wp_login_viewport_meta' );
  44. if ( ! is_wp_error( $wp_error ) ) {
  45. $wp_error = new WP_Error();
  46. }
  47. // Shake it!
  48. $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password', 'retrieve_password_email_failure' );
  49. /**
  50. * Filters the error codes array for shaking the login form.
  51. *
  52. * @since 3.0.0
  53. *
  54. * @param array $shake_error_codes Error codes that shake the login form.
  55. */
  56. $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
  57. if ( $shake_error_codes && $wp_error->has_errors() && in_array( $wp_error->get_error_code(), $shake_error_codes, true ) ) {
  58. add_action( 'login_footer', 'wp_shake_js', 12 );
  59. }
  60. $login_title = get_bloginfo( 'name', 'display' );
  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. if ( wp_is_recovery_mode() ) {
  64. /* translators: %s: Login screen title. */
  65. $login_title = sprintf( __( 'Recovery Mode &#8212; %s' ), $login_title );
  66. }
  67. /**
  68. * Filters the title tag content for login page.
  69. *
  70. * @since 4.9.0
  71. *
  72. * @param string $login_title The page title, with extra context added.
  73. * @param string $title The original page title.
  74. */
  75. $login_title = apply_filters( 'login_title', $login_title, $title );
  76. ?><!DOCTYPE html>
  77. <html <?php language_attributes(); ?>>
  78. <head>
  79. <meta http-equiv="Content-Type" content="<?php bloginfo( 'html_type' ); ?>; charset=<?php bloginfo( 'charset' ); ?>" />
  80. <title><?php echo $login_title; ?></title>
  81. <?php
  82. wp_enqueue_style( 'login' );
  83. /*
  84. * Remove all stored post data on logging out.
  85. * This could be added by add_action('login_head'...) like wp_shake_js(),
  86. * but maybe better if it's not removable by plugins.
  87. */
  88. if ( 'loggedout' === $wp_error->get_error_code() ) {
  89. ?>
  90. <script>if("sessionStorage" in window){try{for(var key in sessionStorage){if(key.indexOf("wp-autosave-")!=-1){sessionStorage.removeItem(key)}}}catch(e){}};</script>
  91. <?php
  92. }
  93. /**
  94. * Enqueue scripts and styles for the login page.
  95. *
  96. * @since 3.1.0
  97. */
  98. do_action( 'login_enqueue_scripts' );
  99. /**
  100. * Fires in the login page header after scripts are enqueued.
  101. *
  102. * @since 2.1.0
  103. */
  104. do_action( 'login_head' );
  105. $login_header_url = __( 'https://wordpress.org/' );
  106. /**
  107. * Filters link URL of the header logo above login form.
  108. *
  109. * @since 2.1.0
  110. *
  111. * @param string $login_header_url Login header logo URL.
  112. */
  113. $login_header_url = apply_filters( 'login_headerurl', $login_header_url );
  114. $login_header_title = '';
  115. /**
  116. * Filters the title attribute of the header logo above login form.
  117. *
  118. * @since 2.1.0
  119. * @deprecated 5.2.0 Use {@see 'login_headertext'} instead.
  120. *
  121. * @param string $login_header_title Login header logo title attribute.
  122. */
  123. $login_header_title = apply_filters_deprecated(
  124. 'login_headertitle',
  125. array( $login_header_title ),
  126. '5.2.0',
  127. 'login_headertext',
  128. __( 'Usage of the title attribute on the login logo is not recommended for accessibility reasons. Use the link text instead.' )
  129. );
  130. $login_header_text = empty( $login_header_title ) ? __( 'Powered by WordPress' ) : $login_header_title;
  131. /**
  132. * Filters the link text of the header logo above the login form.
  133. *
  134. * @since 5.2.0
  135. *
  136. * @param string $login_header_text The login header logo link text.
  137. */
  138. $login_header_text = apply_filters( 'login_headertext', $login_header_text );
  139. $classes = array( 'login-action-' . $action, 'wp-core-ui' );
  140. if ( is_rtl() ) {
  141. $classes[] = 'rtl';
  142. }
  143. if ( $interim_login ) {
  144. $classes[] = 'interim-login';
  145. ?>
  146. <style type="text/css">html{background-color: transparent;}</style>
  147. <?php
  148. if ( 'success' === $interim_login ) {
  149. $classes[] = 'interim-login-success';
  150. }
  151. }
  152. $classes[] = ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
  153. /**
  154. * Filters the login page body classes.
  155. *
  156. * @since 3.5.0
  157. *
  158. * @param array $classes An array of body classes.
  159. * @param string $action The action that brought the visitor to the login page.
  160. */
  161. $classes = apply_filters( 'login_body_class', $classes, $action );
  162. ?>
  163. </head>
  164. <body class="login no-js <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
  165. <script type="text/javascript">
  166. document.body.className = document.body.className.replace('no-js','js');
  167. </script>
  168. <?php
  169. /**
  170. * Fires in the login page header after the body tag is opened.
  171. *
  172. * @since 4.6.0
  173. */
  174. do_action( 'login_header' );
  175. ?>
  176. <div id="login">
  177. <h1><a href="<?php echo esc_url( $login_header_url ); ?>"><?php echo $login_header_text; ?></a></h1>
  178. <?php
  179. /**
  180. * Filters the message to display above the login form.
  181. *
  182. * @since 2.1.0
  183. *
  184. * @param string $message Login message text.
  185. */
  186. $message = apply_filters( 'login_message', $message );
  187. if ( ! empty( $message ) ) {
  188. echo $message . "\n";
  189. }
  190. // In case a plugin uses $error rather than the $wp_errors object.
  191. if ( ! empty( $error ) ) {
  192. $wp_error->add( 'error', $error );
  193. unset( $error );
  194. }
  195. if ( $wp_error->has_errors() ) {
  196. $errors = '';
  197. $messages = '';
  198. foreach ( $wp_error->get_error_codes() as $code ) {
  199. $severity = $wp_error->get_error_data( $code );
  200. foreach ( $wp_error->get_error_messages( $code ) as $error_message ) {
  201. if ( 'message' === $severity ) {
  202. $messages .= ' ' . $error_message . "<br />\n";
  203. } else {
  204. $errors .= ' ' . $error_message . "<br />\n";
  205. }
  206. }
  207. }
  208. if ( ! empty( $errors ) ) {
  209. /**
  210. * Filters the error messages displayed above the login form.
  211. *
  212. * @since 2.1.0
  213. *
  214. * @param string $errors Login error message.
  215. */
  216. echo '<div id="login_error">' . apply_filters( 'login_errors', $errors ) . "</div>\n";
  217. }
  218. if ( ! empty( $messages ) ) {
  219. /**
  220. * Filters instructional messages displayed above the login form.
  221. *
  222. * @since 2.5.0
  223. *
  224. * @param string $messages Login messages.
  225. */
  226. echo '<p class="message">' . apply_filters( 'login_messages', $messages ) . "</p>\n";
  227. }
  228. }
  229. } // End of login_header().
  230. /**
  231. * Outputs the footer for the login page.
  232. *
  233. * @since 3.1.0
  234. *
  235. * @global bool|string $interim_login Whether interim login modal is being displayed. String 'success'
  236. * upon successful login.
  237. *
  238. * @param string $input_id Which input to auto-focus.
  239. */
  240. function login_footer( $input_id = '' ) {
  241. global $interim_login;
  242. // Don't allow interim logins to navigate away from the page.
  243. if ( ! $interim_login ) {
  244. ?>
  245. <p id="backtoblog">
  246. <?php
  247. $html_link = sprintf(
  248. '<a href="%s">%s</a>',
  249. esc_url( home_url( '/' ) ),
  250. sprintf(
  251. /* translators: %s: Site title. */
  252. _x( '&larr; Go to %s', 'site' ),
  253. get_bloginfo( 'title', 'display' )
  254. )
  255. );
  256. /**
  257. * Filter the "Go to site" link displayed in the login page footer.
  258. *
  259. * @since 5.7.0
  260. *
  261. * @param string $link HTML link to the home URL of the current site.
  262. */
  263. echo apply_filters( 'login_site_html_link', $html_link );
  264. ?>
  265. </p>
  266. <?php
  267. the_privacy_policy_link( '<div class="privacy-policy-page-link">', '</div>' );
  268. }
  269. ?>
  270. </div><?php // End of <div id="login">. ?>
  271. <?php
  272. if ( ! empty( $input_id ) ) {
  273. ?>
  274. <script type="text/javascript">
  275. try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
  276. if(typeof wpOnload==='function')wpOnload();
  277. </script>
  278. <?php
  279. }
  280. /**
  281. * Fires in the login page footer.
  282. *
  283. * @since 3.1.0
  284. */
  285. do_action( 'login_footer' );
  286. ?>
  287. <div class="clear"></div>
  288. </body>
  289. </html>
  290. <?php
  291. }
  292. /**
  293. * Outputs the JavaScript to handle the form shaking on the login page.
  294. *
  295. * @since 3.0.0
  296. */
  297. function wp_shake_js() {
  298. ?>
  299. <script type="text/javascript">
  300. document.querySelector('form').classList.add('shake');
  301. </script>
  302. <?php
  303. }
  304. /**
  305. * Outputs the viewport meta tag for the login page.
  306. *
  307. * @since 3.7.0
  308. */
  309. function wp_login_viewport_meta() {
  310. ?>
  311. <meta name="viewport" content="width=device-width" />
  312. <?php
  313. }
  314. //
  315. // Main.
  316. //
  317. $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'login';
  318. $errors = new WP_Error();
  319. if ( isset( $_GET['key'] ) ) {
  320. $action = 'resetpass';
  321. }
  322. if ( isset( $_GET['checkemail'] ) ) {
  323. $action = 'checkemail';
  324. }
  325. $default_actions = array(
  326. 'confirm_admin_email',
  327. 'postpass',
  328. 'logout',
  329. 'lostpassword',
  330. 'retrievepassword',
  331. 'resetpass',
  332. 'rp',
  333. 'register',
  334. 'checkemail',
  335. 'confirmaction',
  336. 'login',
  337. WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED,
  338. );
  339. // Validate action so as to default to the login screen.
  340. if ( ! in_array( $action, $default_actions, true ) && false === has_filter( 'login_form_' . $action ) ) {
  341. $action = 'login';
  342. }
  343. nocache_headers();
  344. header( 'Content-Type: ' . get_bloginfo( 'html_type' ) . '; charset=' . get_bloginfo( 'charset' ) );
  345. if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set.
  346. if ( isset( $_SERVER['PATH_INFO'] ) && ( $_SERVER['PATH_INFO'] !== $_SERVER['PHP_SELF'] ) ) {
  347. $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
  348. }
  349. $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
  350. if ( get_option( 'siteurl' ) !== $url ) {
  351. update_option( 'siteurl', $url );
  352. }
  353. }
  354. // Set a cookie now to see if they are supported by the browser.
  355. $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
  356. setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
  357. if ( SITECOOKIEPATH !== COOKIEPATH ) {
  358. setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
  359. }
  360. /**
  361. * Fires when the login form is initialized.
  362. *
  363. * @since 3.2.0
  364. */
  365. do_action( 'login_init' );
  366. /**
  367. * Fires before a specified login form action.
  368. *
  369. * The dynamic portion of the hook name, `$action`, refers to the action
  370. * that brought the visitor to the login form.
  371. *
  372. * Possible hook names include:
  373. *
  374. * - 'login_form_checkemail'
  375. * - 'login_form_confirm_admin_email'
  376. * - 'login_form_confirmaction'
  377. * - 'login_form_entered_recovery_mode'
  378. * - 'login_form_login'
  379. * - 'login_form_logout'
  380. * - 'login_form_lostpassword'
  381. * - 'login_form_postpass'
  382. * - 'login_form_register'
  383. * - 'login_form_resetpass'
  384. * - 'login_form_retrievepassword'
  385. * - 'login_form_rp'
  386. *
  387. * @since 2.8.0
  388. */
  389. do_action( "login_form_{$action}" );
  390. $http_post = ( 'POST' === $_SERVER['REQUEST_METHOD'] );
  391. $interim_login = isset( $_REQUEST['interim-login'] );
  392. /**
  393. * Filters the separator used between login form navigation links.
  394. *
  395. * @since 4.9.0
  396. *
  397. * @param string $login_link_separator The separator used between login form navigation links.
  398. */
  399. $login_link_separator = apply_filters( 'login_link_separator', ' | ' );
  400. switch ( $action ) {
  401. case 'confirm_admin_email':
  402. /*
  403. * Note that `is_user_logged_in()` will return false immediately after logging in
  404. * as the current user is not set, see wp-includes/pluggable.php.
  405. * However this action runs on a redirect after logging in.
  406. */
  407. if ( ! is_user_logged_in() ) {
  408. wp_safe_redirect( wp_login_url() );
  409. exit;
  410. }
  411. if ( ! empty( $_REQUEST['redirect_to'] ) ) {
  412. $redirect_to = $_REQUEST['redirect_to'];
  413. } else {
  414. $redirect_to = admin_url();
  415. }
  416. if ( current_user_can( 'manage_options' ) ) {
  417. $admin_email = get_option( 'admin_email' );
  418. } else {
  419. wp_safe_redirect( $redirect_to );
  420. exit;
  421. }
  422. /**
  423. * Filters the interval for dismissing the admin email confirmation screen.
  424. *
  425. * If `0` (zero) is returned, the "Remind me later" link will not be displayed.
  426. *
  427. * @since 5.3.1
  428. *
  429. * @param int $interval Interval time (in seconds). Default is 3 days.
  430. */
  431. $remind_interval = (int) apply_filters( 'admin_email_remind_interval', 3 * DAY_IN_SECONDS );
  432. if ( ! empty( $_GET['remind_me_later'] ) ) {
  433. if ( ! wp_verify_nonce( $_GET['remind_me_later'], 'remind_me_later_nonce' ) ) {
  434. wp_safe_redirect( wp_login_url() );
  435. exit;
  436. }
  437. if ( $remind_interval > 0 ) {
  438. update_option( 'admin_email_lifespan', time() + $remind_interval );
  439. }
  440. $redirect_to = add_query_arg( 'admin_email_remind_later', 1, $redirect_to );
  441. wp_safe_redirect( $redirect_to );
  442. exit;
  443. }
  444. if ( ! empty( $_POST['correct-admin-email'] ) ) {
  445. if ( ! check_admin_referer( 'confirm_admin_email', 'confirm_admin_email_nonce' ) ) {
  446. wp_safe_redirect( wp_login_url() );
  447. exit;
  448. }
  449. /**
  450. * Filters the interval for redirecting the user to the admin email confirmation screen.
  451. *
  452. * If `0` (zero) is returned, the user will not be redirected.
  453. *
  454. * @since 5.3.0
  455. *
  456. * @param int $interval Interval time (in seconds). Default is 6 months.
  457. */
  458. $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS );
  459. if ( $admin_email_check_interval > 0 ) {
  460. update_option( 'admin_email_lifespan', time() + $admin_email_check_interval );
  461. }
  462. wp_safe_redirect( $redirect_to );
  463. exit;
  464. }
  465. login_header( __( 'Confirm your administration email' ), '', $errors );
  466. /**
  467. * Fires before the admin email confirm form.
  468. *
  469. * @since 5.3.0
  470. *
  471. * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid
  472. * credentials. Note that the error object may not contain any errors.
  473. */
  474. do_action( 'admin_email_confirm', $errors );
  475. ?>
  476. <form class="admin-email-confirm-form" name="admin-email-confirm-form" action="<?php echo esc_url( site_url( 'wp-login.php?action=confirm_admin_email', 'login_post' ) ); ?>" method="post">
  477. <?php
  478. /**
  479. * Fires inside the admin-email-confirm-form form tags, before the hidden fields.
  480. *
  481. * @since 5.3.0
  482. */
  483. do_action( 'admin_email_confirm_form' );
  484. wp_nonce_field( 'confirm_admin_email', 'confirm_admin_email_nonce' );
  485. ?>
  486. <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
  487. <h1 class="admin-email__heading">
  488. <?php _e( 'Administration email verification' ); ?>
  489. </h1>
  490. <p class="admin-email__details">
  491. <?php _e( 'Please verify that the <strong>administration email</strong> for this website is still correct.' ); ?>
  492. <?php
  493. /* translators: URL to the WordPress help section about admin email. */
  494. $admin_email_help_url = __( 'https://wordpress.org/support/article/settings-general-screen/#email-address' );
  495. /* translators: Accessibility text. */
  496. $accessibility_text = sprintf( '<span class="screen-reader-text"> %s</span>', __( '(opens in a new tab)' ) );
  497. printf(
  498. '<a href="%s" rel="noopener" target="_blank">%s%s</a>',
  499. esc_url( $admin_email_help_url ),
  500. __( 'Why is this important?' ),
  501. $accessibility_text
  502. );
  503. ?>
  504. </p>
  505. <p class="admin-email__details">
  506. <?php
  507. printf(
  508. /* translators: %s: Admin email address. */
  509. __( 'Current administration email: %s' ),
  510. '<strong>' . esc_html( $admin_email ) . '</strong>'
  511. );
  512. ?>
  513. </p>
  514. <p class="admin-email__details">
  515. <?php _e( 'This email may be different from your personal email address.' ); ?>
  516. </p>
  517. <div class="admin-email__actions">
  518. <div class="admin-email__actions-primary">
  519. <?php
  520. $change_link = admin_url( 'options-general.php' );
  521. $change_link = add_query_arg( 'highlight', 'confirm_admin_email', $change_link );
  522. ?>
  523. <a class="button button-large" href="<?php echo esc_url( $change_link ); ?>"><?php _e( 'Update' ); ?></a>
  524. <input type="submit" name="correct-admin-email" id="correct-admin-email" class="button button-primary button-large" value="<?php esc_attr_e( 'The email is correct' ); ?>" />
  525. </div>
  526. <?php if ( $remind_interval > 0 ) : ?>
  527. <div class="admin-email__actions-secondary">
  528. <?php
  529. $remind_me_link = wp_login_url( $redirect_to );
  530. $remind_me_link = add_query_arg(
  531. array(
  532. 'action' => 'confirm_admin_email',
  533. 'remind_me_later' => wp_create_nonce( 'remind_me_later_nonce' ),
  534. ),
  535. $remind_me_link
  536. );
  537. ?>
  538. <a href="<?php echo esc_url( $remind_me_link ); ?>"><?php _e( 'Remind me later' ); ?></a>
  539. </div>
  540. <?php endif; ?>
  541. </div>
  542. </form>
  543. <?php
  544. login_footer();
  545. break;
  546. case 'postpass':
  547. if ( ! array_key_exists( 'post_password', $_POST ) ) {
  548. wp_safe_redirect( wp_get_referer() );
  549. exit;
  550. }
  551. require_once ABSPATH . WPINC . '/class-phpass.php';
  552. $hasher = new PasswordHash( 8, true );
  553. /**
  554. * Filters the life span of the post password cookie.
  555. *
  556. * By default, the cookie expires 10 days from creation. To turn this
  557. * into a session cookie, return 0.
  558. *
  559. * @since 3.7.0
  560. *
  561. * @param int $expires The expiry time, as passed to setcookie().
  562. */
  563. $expire = apply_filters( 'post_password_expires', time() + 10 * DAY_IN_SECONDS );
  564. $referer = wp_get_referer();
  565. if ( $referer ) {
  566. $secure = ( 'https' === parse_url( $referer, PHP_URL_SCHEME ) );
  567. } else {
  568. $secure = false;
  569. }
  570. setcookie( 'wp-postpass_' . COOKIEHASH, $hasher->HashPassword( wp_unslash( $_POST['post_password'] ) ), $expire, COOKIEPATH, COOKIE_DOMAIN, $secure );
  571. wp_safe_redirect( wp_get_referer() );
  572. exit;
  573. case 'logout':
  574. check_admin_referer( 'log-out' );
  575. $user = wp_get_current_user();
  576. wp_logout();
  577. if ( ! empty( $_REQUEST['redirect_to'] ) ) {
  578. $redirect_to = $_REQUEST['redirect_to'];
  579. $requested_redirect_to = $redirect_to;
  580. } else {
  581. $redirect_to = add_query_arg(
  582. array(
  583. 'loggedout' => 'true',
  584. 'wp_lang' => get_user_locale( $user ),
  585. ),
  586. wp_login_url()
  587. );
  588. $requested_redirect_to = '';
  589. }
  590. /**
  591. * Filters the log out redirect URL.
  592. *
  593. * @since 4.2.0
  594. *
  595. * @param string $redirect_to The redirect destination URL.
  596. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
  597. * @param WP_User $user The WP_User object for the user that's logging out.
  598. */
  599. $redirect_to = apply_filters( 'logout_redirect', $redirect_to, $requested_redirect_to, $user );
  600. wp_safe_redirect( $redirect_to );
  601. exit;
  602. case 'lostpassword':
  603. case 'retrievepassword':
  604. if ( $http_post ) {
  605. $errors = retrieve_password();
  606. if ( ! is_wp_error( $errors ) ) {
  607. $redirect_to = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm';
  608. wp_safe_redirect( $redirect_to );
  609. exit;
  610. }
  611. }
  612. if ( isset( $_GET['error'] ) ) {
  613. if ( 'invalidkey' === $_GET['error'] ) {
  614. $errors->add( 'invalidkey', __( '<strong>Error</strong>: Your password reset link appears to be invalid. Please request a new link below.' ) );
  615. } elseif ( 'expiredkey' === $_GET['error'] ) {
  616. $errors->add( 'expiredkey', __( '<strong>Error</strong>: Your password reset link has expired. Please request a new link below.' ) );
  617. }
  618. }
  619. $lostpassword_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
  620. /**
  621. * Filters the URL redirected to after submitting the lostpassword/retrievepassword form.
  622. *
  623. * @since 3.0.0
  624. *
  625. * @param string $lostpassword_redirect The redirect destination URL.
  626. */
  627. $redirect_to = apply_filters( 'lostpassword_redirect', $lostpassword_redirect );
  628. /**
  629. * Fires before the lost password form.
  630. *
  631. * @since 1.5.1
  632. * @since 5.1.0 Added the `$errors` parameter.
  633. *
  634. * @param WP_Error $errors A `WP_Error` object containing any errors generated by using invalid
  635. * credentials. Note that the error object may not contain any errors.
  636. */
  637. do_action( 'lost_password', $errors );
  638. login_header( __( 'Lost Password' ), '<p class="message">' . __( 'Please enter your username or email address. You will receive an email message with instructions on how to reset your password.' ) . '</p>', $errors );
  639. $user_login = '';
  640. if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
  641. $user_login = wp_unslash( $_POST['user_login'] );
  642. }
  643. ?>
  644. <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
  645. <p>
  646. <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
  647. <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
  648. </p>
  649. <?php
  650. /**
  651. * Fires inside the lostpassword form tags, before the hidden fields.
  652. *
  653. * @since 2.1.0
  654. */
  655. do_action( 'lostpassword_form' );
  656. ?>
  657. <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
  658. <p class="submit">
  659. <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Get New Password' ); ?>" />
  660. </p>
  661. </form>
  662. <p id="nav">
  663. <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
  664. <?php
  665. if ( get_option( 'users_can_register' ) ) {
  666. $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
  667. echo esc_html( $login_link_separator );
  668. /** This filter is documented in wp-includes/general-template.php */
  669. echo apply_filters( 'register', $registration_url );
  670. }
  671. ?>
  672. </p>
  673. <?php
  674. login_footer( 'user_login' );
  675. break;
  676. case 'resetpass':
  677. case 'rp':
  678. list( $rp_path ) = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) );
  679. $rp_cookie = 'wp-resetpass-' . COOKIEHASH;
  680. if ( isset( $_GET['key'] ) && isset( $_GET['login'] ) ) {
  681. $value = sprintf( '%s:%s', wp_unslash( $_GET['login'] ), wp_unslash( $_GET['key'] ) );
  682. setcookie( $rp_cookie, $value, 0, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
  683. wp_safe_redirect( remove_query_arg( array( 'key', 'login' ) ) );
  684. exit;
  685. }
  686. if ( isset( $_COOKIE[ $rp_cookie ] ) && 0 < strpos( $_COOKIE[ $rp_cookie ], ':' ) ) {
  687. list( $rp_login, $rp_key ) = explode( ':', wp_unslash( $_COOKIE[ $rp_cookie ] ), 2 );
  688. $user = check_password_reset_key( $rp_key, $rp_login );
  689. if ( isset( $_POST['pass1'] ) && ! hash_equals( $rp_key, $_POST['rp_key'] ) ) {
  690. $user = false;
  691. }
  692. } else {
  693. $user = false;
  694. }
  695. if ( ! $user || is_wp_error( $user ) ) {
  696. setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
  697. if ( $user && $user->get_error_code() === 'expired_key' ) {
  698. wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=expiredkey' ) );
  699. } else {
  700. wp_redirect( site_url( 'wp-login.php?action=lostpassword&error=invalidkey' ) );
  701. }
  702. exit;
  703. }
  704. $errors = new WP_Error();
  705. if ( isset( $_POST['pass1'] ) && $_POST['pass1'] !== $_POST['pass2'] ) {
  706. $errors->add( 'password_reset_mismatch', __( '<strong>Error</strong>: The passwords do not match.' ) );
  707. }
  708. /**
  709. * Fires before the password reset procedure is validated.
  710. *
  711. * @since 3.5.0
  712. *
  713. * @param WP_Error $errors WP Error object.
  714. * @param WP_User|WP_Error $user WP_User object if the login and reset key match. WP_Error object otherwise.
  715. */
  716. do_action( 'validate_password_reset', $errors, $user );
  717. if ( ( ! $errors->has_errors() ) && isset( $_POST['pass1'] ) && ! empty( $_POST['pass1'] ) ) {
  718. reset_password( $user, $_POST['pass1'] );
  719. setcookie( $rp_cookie, ' ', time() - YEAR_IN_SECONDS, $rp_path, COOKIE_DOMAIN, is_ssl(), true );
  720. 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>' );
  721. login_footer();
  722. exit;
  723. }
  724. wp_enqueue_script( 'utils' );
  725. wp_enqueue_script( 'user-profile' );
  726. login_header( __( 'Reset Password' ), '<p class="message reset-pass">' . __( 'Enter your new password below or generate one.' ) . '</p>', $errors );
  727. ?>
  728. <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( network_site_url( 'wp-login.php?action=resetpass', 'login_post' ) ); ?>" method="post" autocomplete="off">
  729. <input type="hidden" id="user_login" value="<?php echo esc_attr( $rp_login ); ?>" autocomplete="off" />
  730. <div class="user-pass1-wrap">
  731. <p>
  732. <label for="pass1"><?php _e( 'New password' ); ?></label>
  733. </p>
  734. <div class="wp-pwd">
  735. <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" />
  736. <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Hide password' ); ?>">
  737. <span class="dashicons dashicons-hidden" aria-hidden="true"></span>
  738. </button>
  739. <div id="pass-strength-result" class="hide-if-no-js" aria-live="polite"><?php _e( 'Strength indicator' ); ?></div>
  740. </div>
  741. <div class="pw-weak">
  742. <input type="checkbox" name="pw_weak" id="pw-weak" class="pw-checkbox" />
  743. <label for="pw-weak"><?php _e( 'Confirm use of weak password' ); ?></label>
  744. </div>
  745. </div>
  746. <p class="user-pass2-wrap">
  747. <label for="pass2"><?php _e( 'Confirm new password' ); ?></label>
  748. <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" />
  749. </p>
  750. <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
  751. <br class="clear" />
  752. <?php
  753. /**
  754. * Fires following the 'Strength indicator' meter in the user password reset form.
  755. *
  756. * @since 3.9.0
  757. *
  758. * @param WP_User $user User object of the user whose password is being reset.
  759. */
  760. do_action( 'resetpass_form', $user );
  761. ?>
  762. <input type="hidden" name="rp_key" value="<?php echo esc_attr( $rp_key ); ?>" />
  763. <p class="submit reset-pass-submit">
  764. <button type="button" class="button wp-generate-pw hide-if-no-js" aria-expanded="true"><?php _e( 'Generate Password' ); ?></button>
  765. <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Save Password' ); ?>" />
  766. </p>
  767. </form>
  768. <p id="nav">
  769. <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
  770. <?php
  771. if ( get_option( 'users_can_register' ) ) {
  772. $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
  773. echo esc_html( $login_link_separator );
  774. /** This filter is documented in wp-includes/general-template.php */
  775. echo apply_filters( 'register', $registration_url );
  776. }
  777. ?>
  778. </p>
  779. <?php
  780. login_footer( 'user_pass' );
  781. break;
  782. case 'register':
  783. if ( is_multisite() ) {
  784. /**
  785. * Filters the Multisite sign up URL.
  786. *
  787. * @since 3.0.0
  788. *
  789. * @param string $sign_up_url The sign up URL.
  790. */
  791. wp_redirect( apply_filters( 'wp_signup_location', network_site_url( 'wp-signup.php' ) ) );
  792. exit;
  793. }
  794. if ( ! get_option( 'users_can_register' ) ) {
  795. wp_redirect( site_url( 'wp-login.php?registration=disabled' ) );
  796. exit;
  797. }
  798. $user_login = '';
  799. $user_email = '';
  800. if ( $http_post ) {
  801. if ( isset( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
  802. $user_login = wp_unslash( $_POST['user_login'] );
  803. }
  804. if ( isset( $_POST['user_email'] ) && is_string( $_POST['user_email'] ) ) {
  805. $user_email = wp_unslash( $_POST['user_email'] );
  806. }
  807. $errors = register_new_user( $user_login, $user_email );
  808. if ( ! is_wp_error( $errors ) ) {
  809. $redirect_to = ! empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
  810. wp_safe_redirect( $redirect_to );
  811. exit;
  812. }
  813. }
  814. $registration_redirect = ! empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
  815. /**
  816. * Filters the registration redirect URL.
  817. *
  818. * @since 3.0.0
  819. *
  820. * @param string $registration_redirect The redirect destination URL.
  821. */
  822. $redirect_to = apply_filters( 'registration_redirect', $registration_redirect );
  823. login_header( __( 'Registration Form' ), '<p class="message register">' . __( 'Register For This Site' ) . '</p>', $errors );
  824. ?>
  825. <form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
  826. <p>
  827. <label for="user_login"><?php _e( 'Username' ); ?></label>
  828. <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr( wp_unslash( $user_login ) ); ?>" size="20" autocapitalize="off" />
  829. </p>
  830. <p>
  831. <label for="user_email"><?php _e( 'Email' ); ?></label>
  832. <input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" />
  833. </p>
  834. <?php
  835. /**
  836. * Fires following the 'Email' field in the user registration form.
  837. *
  838. * @since 2.1.0
  839. */
  840. do_action( 'register_form' );
  841. ?>
  842. <p id="reg_passmail">
  843. <?php _e( 'Registration confirmation will be emailed to you.' ); ?>
  844. </p>
  845. <br class="clear" />
  846. <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
  847. <p class="submit">
  848. <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Register' ); ?>" />
  849. </p>
  850. </form>
  851. <p id="nav">
  852. <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
  853. <?php echo esc_html( $login_link_separator ); ?>
  854. <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
  855. </p>
  856. <?php
  857. login_footer( 'user_login' );
  858. break;
  859. case 'checkemail':
  860. $redirect_to = admin_url();
  861. $errors = new WP_Error();
  862. if ( 'confirm' === $_GET['checkemail'] ) {
  863. $errors->add(
  864. 'confirm',
  865. sprintf(
  866. /* translators: %s: Link to the login page. */
  867. __( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ),
  868. wp_login_url()
  869. ),
  870. 'message'
  871. );
  872. } elseif ( 'registered' === $_GET['checkemail'] ) {
  873. $errors->add(
  874. 'registered',
  875. sprintf(
  876. /* translators: %s: Link to the login page. */
  877. __( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ),
  878. wp_login_url()
  879. ),
  880. 'message'
  881. );
  882. }
  883. /** This action is documented in wp-login.php */
  884. $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
  885. login_header( __( 'Check your email' ), '', $errors );
  886. login_footer();
  887. break;
  888. case 'confirmaction':
  889. if ( ! isset( $_GET['request_id'] ) ) {
  890. wp_die( __( 'Missing request ID.' ) );
  891. }
  892. if ( ! isset( $_GET['confirm_key'] ) ) {
  893. wp_die( __( 'Missing confirm key.' ) );
  894. }
  895. $request_id = (int) $_GET['request_id'];
  896. $key = sanitize_text_field( wp_unslash( $_GET['confirm_key'] ) );
  897. $result = wp_validate_user_request_key( $request_id, $key );
  898. if ( is_wp_error( $result ) ) {
  899. wp_die( $result );
  900. }
  901. /**
  902. * Fires an action hook when the account action has been confirmed by the user.
  903. *
  904. * Using this you can assume the user has agreed to perform the action by
  905. * clicking on the link in the confirmation email.
  906. *
  907. * After firing this action hook the page will redirect to wp-login a callback
  908. * redirects or exits first.
  909. *
  910. * @since 4.9.6
  911. *
  912. * @param int $request_id Request ID.
  913. */
  914. do_action( 'user_request_action_confirmed', $request_id );
  915. $message = _wp_privacy_account_request_confirmed_message( $request_id );
  916. login_header( __( 'User action confirmed.' ), $message );
  917. login_footer();
  918. exit;
  919. case 'login':
  920. default:
  921. $secure_cookie = '';
  922. $customize_login = isset( $_REQUEST['customize-login'] );
  923. if ( $customize_login ) {
  924. wp_enqueue_script( 'customize-base' );
  925. }
  926. // If the user wants SSL but the session is not SSL, force a secure cookie.
  927. if ( ! empty( $_POST['log'] ) && ! force_ssl_admin() ) {
  928. $user_name = sanitize_user( wp_unslash( $_POST['log'] ) );
  929. $user = get_user_by( 'login', $user_name );
  930. if ( ! $user && strpos( $user_name, '@' ) ) {
  931. $user = get_user_by( 'email', $user_name );
  932. }
  933. if ( $user ) {
  934. if ( get_user_option( 'use_ssl', $user->ID ) ) {
  935. $secure_cookie = true;
  936. force_ssl_admin( true );
  937. }
  938. }
  939. }
  940. if ( isset( $_REQUEST['redirect_to'] ) ) {
  941. $redirect_to = $_REQUEST['redirect_to'];
  942. // Redirect to HTTPS if user wants SSL.
  943. if ( $secure_cookie && false !== strpos( $redirect_to, 'wp-admin' ) ) {
  944. $redirect_to = preg_replace( '|^http://|', 'https://', $redirect_to );
  945. }
  946. } else {
  947. $redirect_to = admin_url();
  948. }
  949. $reauth = empty( $_REQUEST['reauth'] ) ? false : true;
  950. $user = wp_signon( array(), $secure_cookie );
  951. if ( empty( $_COOKIE[ LOGGED_IN_COOKIE ] ) ) {
  952. if ( headers_sent() ) {
  953. $user = new WP_Error(
  954. 'test_cookie',
  955. sprintf(
  956. /* translators: 1: Browser cookie documentation URL, 2: Support forums URL. */
  957. __( '<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>.' ),
  958. __( 'https://wordpress.org/support/article/cookies/' ),
  959. __( 'https://wordpress.org/support/forums/' )
  960. )
  961. );
  962. } elseif ( isset( $_POST['testcookie'] ) && empty( $_COOKIE[ TEST_COOKIE ] ) ) {
  963. // If cookies are disabled, we can't log in even with a valid user and password.
  964. $user = new WP_Error(
  965. 'test_cookie',
  966. sprintf(
  967. /* translators: %s: Browser cookie documentation URL. */
  968. __( '<strong>Error</strong>: Cookies are blocked or not supported by your browser. You must <a href="%s">enable cookies</a> to use WordPress.' ),
  969. __( 'https://wordpress.org/support/article/cookies/#enable-cookies-in-your-browser' )
  970. )
  971. );
  972. }
  973. }
  974. $requested_redirect_to = isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '';
  975. /**
  976. * Filters the login redirect URL.
  977. *
  978. * @since 3.0.0
  979. *
  980. * @param string $redirect_to The redirect destination URL.
  981. * @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
  982. * @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.
  983. */
  984. $redirect_to = apply_filters( 'login_redirect', $redirect_to, $requested_redirect_to, $user );
  985. if ( ! is_wp_error( $user ) && ! $reauth ) {
  986. if ( $interim_login ) {
  987. $message = '<p class="message">' . __( 'You have logged in successfully.' ) . '</p>';
  988. $interim_login = 'success';
  989. login_header( '', $message );
  990. ?>
  991. </div>
  992. <?php
  993. /** This action is documented in wp-login.php */
  994. do_action( 'login_footer' );
  995. if ( $customize_login ) {
  996. ?>
  997. <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
  998. <?php
  999. }
  1000. ?>
  1001. </body></html>
  1002. <?php
  1003. exit;
  1004. }
  1005. // Check if it is time to add a redirect to the admin email confirmation screen.
  1006. if ( is_a( $user, 'WP_User' ) && $user->exists() && $user->has_cap( 'manage_options' ) ) {
  1007. $admin_email_lifespan = (int) get_option( 'admin_email_lifespan' );
  1008. // If `0` (or anything "falsey" as it is cast to int) is returned, the user will not be redirected
  1009. // to the admin email confirmation screen.
  1010. /** This filter is documented in wp-login.php */
  1011. $admin_email_check_interval = (int) apply_filters( 'admin_email_check_interval', 6 * MONTH_IN_SECONDS );
  1012. if ( $admin_email_check_interval > 0 && time() > $admin_email_lifespan ) {
  1013. $redirect_to = add_query_arg(
  1014. array(
  1015. 'action' => 'confirm_admin_email',
  1016. 'wp_lang' => get_user_locale( $user ),
  1017. ),
  1018. wp_login_url( $redirect_to )
  1019. );
  1020. }
  1021. }
  1022. if ( ( empty( $redirect_to ) || 'wp-admin/' === $redirect_to || admin_url() === $redirect_to ) ) {
  1023. // 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.
  1024. if ( is_multisite() && ! get_active_blog_for_user( $user->ID ) && ! is_super_admin( $user->ID ) ) {
  1025. $redirect_to = user_admin_url();
  1026. } elseif ( is_multisite() && ! $user->has_cap( 'read' ) ) {
  1027. $redirect_to = get_dashboard_url( $user->ID );
  1028. } elseif ( ! $user->has_cap( 'edit_posts' ) ) {
  1029. $redirect_to = $user->has_cap( 'read' ) ? admin_url( 'profile.php' ) : home_url();
  1030. }
  1031. wp_redirect( $redirect_to );
  1032. exit;
  1033. }
  1034. wp_safe_redirect( $redirect_to );
  1035. exit;
  1036. }
  1037. $errors = $user;
  1038. // Clear errors if loggedout is set.
  1039. if ( ! empty( $_GET['loggedout'] ) || $reauth ) {
  1040. $errors = new WP_Error();
  1041. }
  1042. if ( empty( $_POST ) && $errors->get_error_codes() === array( 'empty_username', 'empty_password' ) ) {
  1043. $errors = new WP_Error( '', '' );
  1044. }
  1045. if ( $interim_login ) {
  1046. if ( ! $errors->has_errors() ) {
  1047. $errors->add( 'expired', __( 'Your session has expired. Please log in to continue where you left off.' ), 'message' );
  1048. }
  1049. } else {
  1050. // Some parts of this script use the main login form to display a message.
  1051. if ( isset( $_GET['loggedout'] ) && $_GET['loggedout'] ) {
  1052. $errors->add( 'loggedout', __( 'You are now logged out.' ), 'message' );
  1053. } elseif ( isset( $_GET['registration'] ) && 'disabled' === $_GET['registration'] ) {
  1054. $errors->add( 'registerdisabled', __( '<strong>Error</strong>: User registration is currently not allowed.' ) );
  1055. } elseif ( strpos( $redirect_to, 'about.php?updated' ) ) {
  1056. $errors->add( 'updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to see what&#8217;s new.' ), 'message' );
  1057. } elseif ( WP_Recovery_Mode_Link_Service::LOGIN_ACTION_ENTERED === $action ) {
  1058. $errors->add( 'enter_recovery_mode', __( 'Recovery Mode Initialized. Please log in to continue.' ), 'message' );
  1059. } elseif ( isset( $_GET['redirect_to'] ) && false !== strpos( $_GET['redirect_to'], 'wp-admin/authorize-application.php' ) ) {
  1060. $query_component = wp_parse_url( $_GET['redirect_to'], PHP_URL_QUERY );
  1061. parse_str( $query_component, $query );
  1062. if ( ! empty( $query['app_name'] ) ) {
  1063. /* translators: 1: Website name, 2: Application name. */
  1064. $message = sprintf( 'Please log in to %1$s to authorize %2$s to connect to your account.', get_bloginfo( 'name', 'display' ), '<strong>' . esc_html( $query['app_name'] ) . '</strong>' );
  1065. } else {
  1066. /* translators: %s: Website name. */
  1067. $message = sprintf( 'Please log in to %s to proceed with authorization.', get_bloginfo( 'name', 'display' ) );
  1068. }
  1069. $errors->add( 'authorize_application', $message, 'message' );
  1070. }
  1071. }
  1072. /**
  1073. * Filters the login page errors.
  1074. *
  1075. * @since 3.6.0
  1076. *
  1077. * @param WP_Error $errors WP Error object.
  1078. * @param string $redirect_to Redirect destination URL.
  1079. */
  1080. $errors = apply_filters( 'wp_login_errors', $errors, $redirect_to );
  1081. // Clear any stale cookies.
  1082. if ( $reauth ) {
  1083. wp_clear_auth_cookie();
  1084. }
  1085. login_header( __( 'Log In' ), '', $errors );
  1086. if ( isset( $_POST['log'] ) ) {
  1087. $user_login = ( 'incorrect_password' === $errors->get_error_code() || 'empty_password' === $errors->get_error_code() ) ? esc_attr( wp_unslash( $_POST['log'] ) ) : '';
  1088. }
  1089. $rememberme = ! empty( $_POST['rememberme'] );
  1090. if ( $errors->has_errors() ) {
  1091. $aria_describedby_error = ' aria-describedby="login_error"';
  1092. } else {
  1093. $aria_describedby_error = '';
  1094. }
  1095. wp_enqueue_script( 'user-profile' );
  1096. ?>
  1097. <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
  1098. <p>
  1099. <label for="user_login"><?php _e( 'Username or Email Address' ); ?></label>
  1100. <input type="text" name="log" id="user_login"<?php echo $aria_describedby_error; ?> class="input" value="<?php echo esc_attr( $user_login ); ?>" size="20" autocapitalize="off" />
  1101. </p>
  1102. <div class="user-pass-wrap">
  1103. <label for="user_pass"><?php _e( 'Password' ); ?></label>
  1104. <div class="wp-pwd">
  1105. <input type="password" name="pwd" id="user_pass"<?php echo $aria_describedby_error; ?> class="input password-input" value="" size="20" />
  1106. <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Show password' ); ?>">
  1107. <span class="dashicons dashicons-visibility" aria-hidden="true"></span>
  1108. </button>
  1109. </div>
  1110. </div>
  1111. <?php
  1112. /**
  1113. * Fires following the 'Password' field in the login form.
  1114. *
  1115. * @since 2.1.0
  1116. */
  1117. do_action( 'login_form' );
  1118. ?>
  1119. <p class="forgetmenot"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <label for="rememberme"><?php esc_html_e( 'Remember Me' ); ?></label></p>
  1120. <p class="submit">
  1121. <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e( 'Log In' ); ?>" />
  1122. <?php
  1123. if ( $interim_login ) {
  1124. ?>
  1125. <input type="hidden" name="interim-login" value="1" />
  1126. <?php
  1127. } else {
  1128. ?>
  1129. <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
  1130. <?php
  1131. }
  1132. if ( $customize_login ) {
  1133. ?>
  1134. <input type="hidden" name="customize-login" value="1" />
  1135. <?php
  1136. }
  1137. ?>
  1138. <input type="hidden" name="testcookie" value="1" />
  1139. </p>
  1140. </form>
  1141. <?php
  1142. if ( ! $interim_login ) {
  1143. ?>
  1144. <p id="nav">
  1145. <?php
  1146. if ( get_option( 'users_can_register' ) ) {
  1147. $registration_url = sprintf( '<a href="%s">%s</a>', esc_url( wp_registration_url() ), __( 'Register' ) );
  1148. /** This filter is documented in wp-includes/general-template.php */
  1149. echo apply_filters( 'register', $registration_url );
  1150. echo esc_html( $login_link_separator );
  1151. }
  1152. ?>
  1153. <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>"><?php _e( 'Lost your password?' ); ?></a>
  1154. </p>
  1155. <?php
  1156. }
  1157. $login_script = 'function wp_attempt_focus() {';
  1158. $login_script .= 'setTimeout( function() {';
  1159. $login_script .= 'try {';
  1160. if ( $user_login ) {
  1161. $login_script .= 'd = document.getElementById( "user_pass" ); d.value = "";';
  1162. } else {
  1163. $login_script .= 'd = document.getElementById( "user_login" );';
  1164. if ( $errors->get_error_code() === 'invalid_username' ) {
  1165. $login_script .= 'd.value = "";';
  1166. }
  1167. }
  1168. $login_script .= 'd.focus(); d.select();';
  1169. $login_script .= '} catch( er ) {}';
  1170. $login_script .= '}, 200);';
  1171. $login_script .= "}\n"; // End of wp_attempt_focus().
  1172. /**
  1173. * Filters whether to print the call to `wp_attempt_focus()` on the login screen.
  1174. *
  1175. * @since 4.8.0
  1176. *
  1177. * @param bool $print Whether to print the function call. Default true.
  1178. */
  1179. if ( apply_filters( 'enable_login_autofocus', true ) && ! $error ) {
  1180. $login_script .= "wp_attempt_focus();\n";
  1181. }
  1182. // Run `wpOnload()` if defined.
  1183. $login_script .= "if ( typeof wpOnload === 'function' ) { wpOnload() }";
  1184. ?>
  1185. <script type="text/javascript">
  1186. <?php echo $login_script; ?>
  1187. </script>
  1188. <?php
  1189. if ( $interim_login ) {
  1190. ?>
  1191. <script type="text/javascript">
  1192. ( function() {
  1193. try {
  1194. var i, links = document.getElementsByTagName( 'a' );
  1195. for ( i in links ) {
  1196. if ( links[i].href ) {
  1197. links[i].target = '_blank';
  1198. links[i].rel = 'noopener';
  1199. }
  1200. }
  1201. } catch( er ) {}
  1202. }());
  1203. </script>
  1204. <?php
  1205. }
  1206. login_footer();
  1207. break;
  1208. } // End action switch.