PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wordpress/wp-login.php

https://bitbucket.org/mpizza/aws-pizza
PHP | 746 lines | 524 code | 131 blank | 91 comment | 148 complexity | 1e8e7a9f1f094b813c9fa9c7990d68f6 MD5 | raw file
  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_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
  16. exit();
  17. } else {
  18. wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
  19. exit();
  20. }
  21. }
  22. /**
  23. * Outputs the header for the login page.
  24. *
  25. * @uses do_action() Calls the 'login_head' for outputting HTML in the Log In
  26. * header.
  27. * @uses apply_filters() Calls 'login_headerurl' for the top login link.
  28. * @uses apply_filters() Calls 'login_headertitle' for the top login title.
  29. * @uses apply_filters() Calls 'login_message' on the message to display in the
  30. * header.
  31. * @uses $error The error global, which is checked for displaying errors.
  32. *
  33. * @param string $title Optional. WordPress Log In Page title to display in
  34. * <title/> element.
  35. * @param string $message Optional. Message to display in header.
  36. * @param WP_Error $wp_error Optional. WordPress Error Object
  37. */
  38. function login_header($title = 'Log In', $message = '', $wp_error = '') {
  39. global $error, $interim_login, $current_site, $action;
  40. // Don't index any of these forms
  41. add_action( 'login_head', 'wp_no_robots' );
  42. if ( empty($wp_error) )
  43. $wp_error = new WP_Error();
  44. // Shake it!
  45. $shake_error_codes = array( 'empty_password', 'empty_email', 'invalid_email', 'invalidcombo', 'empty_username', 'invalid_username', 'incorrect_password' );
  46. $shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );
  47. if ( $shake_error_codes && $wp_error->get_error_code() && in_array( $wp_error->get_error_code(), $shake_error_codes ) )
  48. add_action( 'login_head', 'wp_shake_js', 12 );
  49. ?><!DOCTYPE html>
  50. <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
  51. <head>
  52. <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />
  53. <title><?php bloginfo('name'); ?> &rsaquo; <?php echo $title; ?></title>
  54. <?php
  55. wp_admin_css( 'wp-admin', true );
  56. wp_admin_css( 'colors-fresh', true );
  57. if ( wp_is_mobile() ) { ?>
  58. <meta name="viewport" content="width=320; initial-scale=0.9; maximum-scale=1.0; user-scalable=0;" /><?php
  59. }
  60. do_action( 'login_enqueue_scripts' );
  61. do_action( 'login_head' );
  62. if ( is_multisite() ) {
  63. $login_header_url = network_home_url();
  64. $login_header_title = $current_site->site_name;
  65. } else {
  66. $login_header_url = __( 'http://wordpress.org/' );
  67. $login_header_title = __( 'Powered by WordPress' );
  68. }
  69. $login_header_url = apply_filters( 'login_headerurl', $login_header_url );
  70. $login_header_title = apply_filters( 'login_headertitle', $login_header_title );
  71. // Don't allow interim logins to navigate away from the page.
  72. if ( $interim_login )
  73. $login_header_url = '#';
  74. $classes = array( 'login-action-' . $action, 'wp-core-ui' );
  75. if ( wp_is_mobile() )
  76. $classes[] = 'mobile';
  77. if ( is_rtl() )
  78. $classes[] = 'rtl';
  79. $classes = apply_filters( 'login_body_class', $classes, $action );
  80. ?>
  81. </head>
  82. <body class="login <?php echo esc_attr( implode( ' ', $classes ) ); ?>">
  83. <div id="login">
  84. <h1><a href="<?php echo esc_url( $login_header_url ); ?>" title="<?php echo esc_attr( $login_header_title ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  85. <?php
  86. unset( $login_header_url, $login_header_title );
  87. $message = apply_filters('login_message', $message);
  88. if ( !empty( $message ) )
  89. echo $message . "\n";
  90. // In case a plugin uses $error rather than the $wp_errors object
  91. if ( !empty( $error ) ) {
  92. $wp_error->add('error', $error);
  93. unset($error);
  94. }
  95. if ( $wp_error->get_error_code() ) {
  96. $errors = '';
  97. $messages = '';
  98. foreach ( $wp_error->get_error_codes() as $code ) {
  99. $severity = $wp_error->get_error_data($code);
  100. foreach ( $wp_error->get_error_messages($code) as $error ) {
  101. if ( 'message' == $severity )
  102. $messages .= ' ' . $error . "<br />\n";
  103. else
  104. $errors .= ' ' . $error . "<br />\n";
  105. }
  106. }
  107. if ( !empty($errors) )
  108. echo '<div id="login_error">' . apply_filters('login_errors', $errors) . "</div>\n";
  109. if ( !empty($messages) )
  110. echo '<p class="message">' . apply_filters('login_messages', $messages) . "</p>\n";
  111. }
  112. } // End of login_header()
  113. /**
  114. * Outputs the footer for the login page.
  115. *
  116. * @param string $input_id Which input to auto-focus
  117. */
  118. function login_footer($input_id = '') {
  119. global $interim_login;
  120. // Don't allow interim logins to navigate away from the page.
  121. if ( ! $interim_login ): ?>
  122. <p id="backtoblog"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php esc_attr_e( 'Are you lost?' ); ?>"><?php printf( __( '&larr; Back to %s' ), get_bloginfo( 'title', 'display' ) ); ?></a></p>
  123. <?php endif; ?>
  124. </div>
  125. <?php if ( !empty($input_id) ) : ?>
  126. <script type="text/javascript">
  127. try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
  128. if(typeof wpOnload=='function')wpOnload();
  129. </script>
  130. <?php endif; ?>
  131. <?php do_action('login_footer'); ?>
  132. <div class="clear"></div>
  133. </body>
  134. </html>
  135. <?php
  136. }
  137. function wp_shake_js() {
  138. if ( wp_is_mobile() )
  139. return;
  140. ?>
  141. <script type="text/javascript">
  142. 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();}}};
  143. function s(id,pos){g(id).left=pos+'px';}
  144. function g(id){return document.getElementById(id).style;}
  145. 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){}}}
  146. 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);});
  147. </script>
  148. <?php
  149. }
  150. /**
  151. * Handles sending password retrieval email to user.
  152. *
  153. * @uses $wpdb WordPress Database object
  154. *
  155. * @return bool|WP_Error True: when finish. WP_Error on error
  156. */
  157. function retrieve_password() {
  158. global $wpdb, $current_site;
  159. $errors = new WP_Error();
  160. if ( empty( $_POST['user_login'] ) ) {
  161. $errors->add('empty_username', __('<strong>ERROR</strong>: Enter a username or e-mail address.'));
  162. } else if ( strpos( $_POST['user_login'], '@' ) ) {
  163. $user_data = get_user_by( 'email', trim( $_POST['user_login'] ) );
  164. if ( empty( $user_data ) )
  165. $errors->add('invalid_email', __('<strong>ERROR</strong>: There is no user registered with that email address.'));
  166. } else {
  167. $login = trim($_POST['user_login']);
  168. $user_data = get_user_by('login', $login);
  169. }
  170. do_action('lostpassword_post');
  171. if ( $errors->get_error_code() )
  172. return $errors;
  173. if ( !$user_data ) {
  174. $errors->add('invalidcombo', __('<strong>ERROR</strong>: Invalid username or e-mail.'));
  175. return $errors;
  176. }
  177. // redefining user_login ensures we return the right case in the email
  178. $user_login = $user_data->user_login;
  179. $user_email = $user_data->user_email;
  180. do_action('retreive_password', $user_login); // Misspelled and deprecated
  181. do_action('retrieve_password', $user_login);
  182. $allow = apply_filters('allow_password_reset', true, $user_data->ID);
  183. if ( ! $allow )
  184. return new WP_Error('no_password_reset', __('Password reset is not allowed for this user'));
  185. else if ( is_wp_error($allow) )
  186. return $allow;
  187. $key = $wpdb->get_var($wpdb->prepare("SELECT user_activation_key FROM $wpdb->users WHERE user_login = %s", $user_login));
  188. if ( empty($key) ) {
  189. // Generate something random for a key...
  190. $key = wp_generate_password(20, false);
  191. do_action('retrieve_password_key', $user_login, $key);
  192. // Now insert the new md5 key into the db
  193. $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
  194. }
  195. $message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
  196. $message .= network_home_url( '/' ) . "\r\n\r\n";
  197. $message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
  198. $message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
  199. $message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
  200. $message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login') . ">\r\n";
  201. if ( is_multisite() )
  202. $blogname = $GLOBALS['current_site']->site_name;
  203. else
  204. // The blogname option is escaped with esc_html on the way into the database in sanitize_option
  205. // we want to reverse this for the plain text arena of emails.
  206. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  207. $title = sprintf( __('[%s] Password Reset'), $blogname );
  208. $title = apply_filters('retrieve_password_title', $title);
  209. $message = apply_filters('retrieve_password_message', $message, $key);
  210. if ( $message && !wp_mail($user_email, $title, $message) )
  211. wp_die( __('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...') );
  212. return true;
  213. }
  214. /**
  215. * Retrieves a user row based on password reset key and login
  216. *
  217. * @uses $wpdb WordPress Database object
  218. *
  219. * @param string $key Hash to validate sending user's password
  220. * @param string $login The user login
  221. * @return object|WP_Error User's database row on success, error object for invalid keys
  222. */
  223. function check_password_reset_key($key, $login) {
  224. global $wpdb;
  225. $key = preg_replace('/[^a-z0-9]/i', '', $key);
  226. if ( empty( $key ) || !is_string( $key ) )
  227. return new WP_Error('invalid_key', __('Invalid key'));
  228. if ( empty($login) || !is_string($login) )
  229. return new WP_Error('invalid_key', __('Invalid key'));
  230. $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE user_activation_key = %s AND user_login = %s", $key, $login));
  231. if ( empty( $user ) )
  232. return new WP_Error('invalid_key', __('Invalid key'));
  233. return $user;
  234. }
  235. /**
  236. * Handles resetting the user's password.
  237. *
  238. * @param object $user The user
  239. * @param string $new_pass New password for the user in plaintext
  240. */
  241. function reset_password($user, $new_pass) {
  242. do_action('password_reset', $user, $new_pass);
  243. wp_set_password($new_pass, $user->ID);
  244. wp_password_change_notification($user);
  245. }
  246. /**
  247. * Handles registering a new user.
  248. *
  249. * @param string $user_login User's username for logging in
  250. * @param string $user_email User's email address to send password and add
  251. * @return int|WP_Error Either user's ID or error on failure.
  252. */
  253. function register_new_user( $user_login, $user_email ) {
  254. $errors = new WP_Error();
  255. $sanitized_user_login = sanitize_user( $user_login );
  256. $user_email = apply_filters( 'user_registration_email', $user_email );
  257. // Check the username
  258. if ( $sanitized_user_login == '' ) {
  259. $errors->add( 'empty_username', __( '<strong>ERROR</strong>: Please enter a username.' ) );
  260. } elseif ( ! validate_username( $user_login ) ) {
  261. $errors->add( 'invalid_username', __( '<strong>ERROR</strong>: This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
  262. $sanitized_user_login = '';
  263. } elseif ( username_exists( $sanitized_user_login ) ) {
  264. $errors->add( 'username_exists', __( '<strong>ERROR</strong>: This username is already registered. Please choose another one.' ) );
  265. }
  266. // Check the e-mail address
  267. if ( $user_email == '' ) {
  268. $errors->add( 'empty_email', __( '<strong>ERROR</strong>: Please type your e-mail address.' ) );
  269. } elseif ( ! is_email( $user_email ) ) {
  270. $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: The email address isn&#8217;t correct.' ) );
  271. $user_email = '';
  272. } elseif ( email_exists( $user_email ) ) {
  273. $errors->add( 'email_exists', __( '<strong>ERROR</strong>: This email is already registered, please choose another one.' ) );
  274. }
  275. do_action( 'register_post', $sanitized_user_login, $user_email, $errors );
  276. $errors = apply_filters( 'registration_errors', $errors, $sanitized_user_login, $user_email );
  277. if ( $errors->get_error_code() )
  278. return $errors;
  279. $user_pass = wp_generate_password( 12, false);
  280. $user_id = wp_create_user( $sanitized_user_login, $user_pass, $user_email );
  281. if ( ! $user_id ) {
  282. $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you... please contact the <a href="mailto:%s">webmaster</a> !' ), get_option( 'admin_email' ) ) );
  283. return $errors;
  284. }
  285. update_user_option( $user_id, 'default_password_nag', true, true ); //Set up the Password change nag.
  286. wp_new_user_notification( $user_id, $user_pass );
  287. return $user_id;
  288. }
  289. //
  290. // Main
  291. //
  292. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login';
  293. $errors = new WP_Error();
  294. if ( isset($_GET['key']) )
  295. $action = 'resetpass';
  296. // validate action so as to default to the login screen
  297. if ( !in_array( $action, array( 'postpass', 'logout', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'login' ), true ) && false === has_filter( 'login_form_' . $action ) )
  298. $action = 'login';
  299. nocache_headers();
  300. header('Content-Type: '.get_bloginfo('html_type').'; charset='.get_bloginfo('charset'));
  301. if ( defined( 'RELOCATE' ) && RELOCATE ) { // Move flag is set
  302. if ( isset( $_SERVER['PATH_INFO'] ) && ($_SERVER['PATH_INFO'] != $_SERVER['PHP_SELF']) )
  303. $_SERVER['PHP_SELF'] = str_replace( $_SERVER['PATH_INFO'], '', $_SERVER['PHP_SELF'] );
  304. $url = dirname( set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ) );
  305. if ( $url != get_option( 'siteurl' ) )
  306. update_option( 'siteurl', $url );
  307. }
  308. //Set a cookie now to see if they are supported by the browser.
  309. setcookie(TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN);
  310. if ( SITECOOKIEPATH != COOKIEPATH )
  311. setcookie(TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN);
  312. // allow plugins to override the default actions, and to add extra actions if they want
  313. do_action( 'login_init' );
  314. do_action( 'login_form_' . $action );
  315. $http_post = ('POST' == $_SERVER['REQUEST_METHOD']);
  316. switch ($action) {
  317. case 'postpass' :
  318. if ( empty( $wp_hasher ) ) {
  319. require_once( ABSPATH . 'wp-includes/class-phpass.php' );
  320. // By default, use the portable hash from phpass
  321. $wp_hasher = new PasswordHash(8, true);
  322. }
  323. // 10 days
  324. setcookie( 'wp-postpass_' . COOKIEHASH, $wp_hasher->HashPassword( stripslashes( $_POST['post_password'] ) ), time() + 10 * DAY_IN_SECONDS, COOKIEPATH );
  325. wp_safe_redirect( wp_get_referer() );
  326. exit();
  327. break;
  328. case 'logout' :
  329. check_admin_referer('log-out');
  330. wp_logout();
  331. $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?loggedout=true';
  332. wp_safe_redirect( $redirect_to );
  333. exit();
  334. break;
  335. case 'lostpassword' :
  336. case 'retrievepassword' :
  337. if ( $http_post ) {
  338. $errors = retrieve_password();
  339. if ( !is_wp_error($errors) ) {
  340. $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?checkemail=confirm';
  341. wp_safe_redirect( $redirect_to );
  342. exit();
  343. }
  344. }
  345. if ( isset($_GET['error']) && 'invalidkey' == $_GET['error'] ) $errors->add('invalidkey', __('Sorry, that key does not appear to be valid.'));
  346. $redirect_to = apply_filters( 'lostpassword_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
  347. do_action('lost_password');
  348. 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);
  349. $user_login = isset($_POST['user_login']) ? stripslashes($_POST['user_login']) : '';
  350. ?>
  351. <form name="lostpasswordform" id="lostpasswordform" action="<?php echo esc_url( site_url( 'wp-login.php?action=lostpassword', 'login_post' ) ); ?>" method="post">
  352. <p>
  353. <label for="user_login" ><?php _e('Username or E-mail:') ?><br />
  354. <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
  355. </p>
  356. <?php do_action('lostpassword_form'); ?>
  357. <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
  358. <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>
  359. </form>
  360. <p id="nav">
  361. <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e('Log in') ?></a>
  362. <?php if ( get_option( 'users_can_register' ) ) : ?>
  363. | <a href="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login' ) ); ?>"><?php _e( 'Register' ); ?></a>
  364. <?php endif; ?>
  365. </p>
  366. <?php
  367. login_footer('user_login');
  368. break;
  369. case 'resetpass' :
  370. case 'rp' :
  371. $user = check_password_reset_key($_GET['key'], $_GET['login']);
  372. if ( is_wp_error($user) ) {
  373. wp_redirect( site_url('wp-login.php?action=lostpassword&error=invalidkey') );
  374. exit;
  375. }
  376. $errors = new WP_Error();
  377. if ( isset($_POST['pass1']) && $_POST['pass1'] != $_POST['pass2'] )
  378. $errors->add( 'password_reset_mismatch', __( 'The passwords do not match.' ) );
  379. do_action( 'validate_password_reset', $errors, $user );
  380. if ( ( ! $errors->get_error_code() ) && isset( $_POST['pass1'] ) && !empty( $_POST['pass1'] ) ) {
  381. reset_password($user, $_POST['pass1']);
  382. 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>' );
  383. login_footer();
  384. exit;
  385. }
  386. wp_enqueue_script('utils');
  387. wp_enqueue_script('user-profile');
  388. login_header(__('Reset Password'), '<p class="message reset-pass">' . __('Enter your new password below.') . '</p>', $errors );
  389. ?>
  390. <form name="resetpassform" id="resetpassform" action="<?php echo esc_url( site_url( 'wp-login.php?action=resetpass&key=' . urlencode( $_GET['key'] ) . '&login=' . urlencode( $_GET['login'] ), 'login_post' ) ); ?>" method="post">
  391. <input type="hidden" id="user_login" value="<?php echo esc_attr( $_GET['login'] ); ?>" autocomplete="off" />
  392. <p>
  393. <label for="pass1"><?php _e('New password') ?><br />
  394. <input type="password" name="pass1" id="pass1" class="input" size="20" value="" autocomplete="off" /></label>
  395. </p>
  396. <p>
  397. <label for="pass2"><?php _e('Confirm new password') ?><br />
  398. <input type="password" name="pass2" id="pass2" class="input" size="20" value="" autocomplete="off" /></label>
  399. </p>
  400. <div id="pass-strength-result" class="hide-if-no-js"><?php _e('Strength indicator'); ?></div>
  401. <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).'); ?></p>
  402. <br class="clear" />
  403. <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>
  404. </form>
  405. <p id="nav">
  406. <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a>
  407. <?php if ( get_option( 'users_can_register' ) ) : ?>
  408. | <a href="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login' ) ); ?>"><?php _e( 'Register' ); ?></a>
  409. <?php endif; ?>
  410. </p>
  411. <?php
  412. login_footer('user_pass');
  413. break;
  414. case 'register' :
  415. if ( is_multisite() ) {
  416. // Multisite uses wp-signup.php
  417. wp_redirect( apply_filters( 'wp_signup_location', network_site_url('wp-signup.php') ) );
  418. exit;
  419. }
  420. if ( !get_option('users_can_register') ) {
  421. wp_redirect( site_url('wp-login.php?registration=disabled') );
  422. exit();
  423. }
  424. $user_login = '';
  425. $user_email = '';
  426. if ( $http_post ) {
  427. $user_login = $_POST['user_login'];
  428. $user_email = $_POST['user_email'];
  429. $errors = register_new_user($user_login, $user_email);
  430. if ( !is_wp_error($errors) ) {
  431. $redirect_to = !empty( $_POST['redirect_to'] ) ? $_POST['redirect_to'] : 'wp-login.php?checkemail=registered';
  432. wp_safe_redirect( $redirect_to );
  433. exit();
  434. }
  435. }
  436. $redirect_to = apply_filters( 'registration_redirect', !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '' );
  437. login_header(__('Registration Form'), '<p class="message register">' . __('Register For This Site') . '</p>', $errors);
  438. ?>
  439. <form name="registerform" id="registerform" action="<?php echo esc_url( site_url('wp-login.php?action=register', 'login_post') ); ?>" method="post">
  440. <p>
  441. <label for="user_login"><?php _e('Username') ?><br />
  442. <input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(stripslashes($user_login)); ?>" size="20" /></label>
  443. </p>
  444. <p>
  445. <label for="user_email"><?php _e('E-mail') ?><br />
  446. <input type="text" name="user_email" id="user_email" class="input" value="<?php echo esc_attr(stripslashes($user_email)); ?>" size="25" /></label>
  447. </p>
  448. <?php do_action('register_form'); ?>
  449. <p id="reg_passmail"><?php _e('A password will be e-mailed to you.') ?></p>
  450. <br class="clear" />
  451. <input type="hidden" name="redirect_to" value="<?php echo esc_attr( $redirect_to ); ?>" />
  452. <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>
  453. </form>
  454. <p id="nav">
  455. <a href="<?php echo esc_url( wp_login_url() ); ?>"><?php _e( 'Log in' ); ?></a> |
  456. <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ) ?>"><?php _e( 'Lost your password?' ); ?></a>
  457. </p>
  458. <?php
  459. login_footer('user_login');
  460. break;
  461. case 'login' :
  462. default:
  463. $secure_cookie = '';
  464. $interim_login = isset($_REQUEST['interim-login']);
  465. $customize_login = isset( $_REQUEST['customize-login'] );
  466. if ( $customize_login )
  467. wp_enqueue_script( 'customize-base' );
  468. // If the user wants ssl but the session is not ssl, force a secure cookie.
  469. if ( !empty($_POST['log']) && !force_ssl_admin() ) {
  470. $user_name = sanitize_user($_POST['log']);
  471. if ( $user = get_user_by('login', $user_name) ) {
  472. if ( get_user_option('use_ssl', $user->ID) ) {
  473. $secure_cookie = true;
  474. force_ssl_admin(true);
  475. }
  476. }
  477. }
  478. if ( isset( $_REQUEST['redirect_to'] ) ) {
  479. $redirect_to = $_REQUEST['redirect_to'];
  480. // Redirect to https if user wants ssl
  481. if ( $secure_cookie && false !== strpos($redirect_to, 'wp-admin') )
  482. $redirect_to = preg_replace('|^http://|', 'https://', $redirect_to);
  483. } else {
  484. $redirect_to = admin_url();
  485. }
  486. $reauth = empty($_REQUEST['reauth']) ? false : true;
  487. // If the user was redirected to a secure login form from a non-secure admin page, and secure login is required but secure admin is not, then don't use a secure
  488. // cookie and redirect back to the referring non-secure admin page. This allows logins to always be POSTed over SSL while allowing the user to choose visiting
  489. // the admin via http or https.
  490. if ( !$secure_cookie && is_ssl() && force_ssl_login() && !force_ssl_admin() && ( 0 !== strpos($redirect_to, 'https') ) && ( 0 === strpos($redirect_to, 'http') ) )
  491. $secure_cookie = false;
  492. $user = wp_signon('', $secure_cookie);
  493. $redirect_to = apply_filters('login_redirect', $redirect_to, isset( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : '', $user);
  494. if ( !is_wp_error($user) && !$reauth ) {
  495. if ( $interim_login ) {
  496. $message = '<p class="message">' . __('You have logged in successfully.') . '</p>';
  497. login_header( '', $message ); ?>
  498. <?php if ( ! $customize_login ) : ?>
  499. <script type="text/javascript">setTimeout( function(){window.close()}, 8000);</script>
  500. <p class="alignright">
  501. <input type="button" class="button-primary" value="<?php esc_attr_e('Close'); ?>" onclick="window.close()" /></p>
  502. <?php endif; ?>
  503. </div>
  504. <?php do_action( 'login_footer' ); ?>
  505. <?php if ( $customize_login ) : ?>
  506. <script type="text/javascript">setTimeout( function(){ new wp.customize.Messenger({ url: '<?php echo wp_customize_url(); ?>', channel: 'login' }).send('login') }, 1000 );</script>
  507. <?php endif; ?>
  508. </body></html>
  509. <?php exit;
  510. }
  511. if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
  512. // 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.
  513. if ( is_multisite() && !get_active_blog_for_user($user->ID) && !is_super_admin( $user->ID ) )
  514. $redirect_to = user_admin_url();
  515. elseif ( is_multisite() && !$user->has_cap('read') )
  516. $redirect_to = get_dashboard_url( $user->ID );
  517. elseif ( !$user->has_cap('edit_posts') )
  518. $redirect_to = admin_url('profile.php');
  519. }
  520. wp_safe_redirect($redirect_to);
  521. exit();
  522. }
  523. $errors = $user;
  524. // Clear errors if loggedout is set.
  525. if ( !empty($_GET['loggedout']) || $reauth )
  526. $errors = new WP_Error();
  527. // If cookies are disabled we can't log in even with a valid user+pass
  528. if ( isset($_POST['testcookie']) && empty($_COOKIE[TEST_COOKIE]) )
  529. $errors->add('test_cookie', __("<strong>ERROR</strong>: Cookies are blocked or not supported by your browser. You must <a href='http://www.google.com/cookies.html'>enable cookies</a> to use WordPress."));
  530. // Some parts of this script use the main login form to display a message
  531. if ( isset($_GET['loggedout']) && true == $_GET['loggedout'] )
  532. $errors->add('loggedout', __('You are now logged out.'), 'message');
  533. elseif ( isset($_GET['registration']) && 'disabled' == $_GET['registration'] )
  534. $errors->add('registerdisabled', __('User registration is currently not allowed.'));
  535. elseif ( isset($_GET['checkemail']) && 'confirm' == $_GET['checkemail'] )
  536. $errors->add('confirm', __('Check your e-mail for the confirmation link.'), 'message');
  537. elseif ( isset($_GET['checkemail']) && 'newpass' == $_GET['checkemail'] )
  538. $errors->add('newpass', __('Check your e-mail for your new password.'), 'message');
  539. elseif ( isset($_GET['checkemail']) && 'registered' == $_GET['checkemail'] )
  540. $errors->add('registered', __('Registration complete. Please check your e-mail.'), 'message');
  541. elseif ( $interim_login )
  542. $errors->add('expired', __('Your session has expired. Please log-in again.'), 'message');
  543. elseif ( strpos( $redirect_to, 'about.php?updated' ) )
  544. $errors->add('updated', __( '<strong>You have successfully updated WordPress!</strong> Please log back in to experience the awesomeness.' ), 'message' );
  545. // Clear any stale cookies.
  546. if ( $reauth )
  547. wp_clear_auth_cookie();
  548. login_header(__('Log In'), '', $errors);
  549. if ( isset($_POST['log']) )
  550. $user_login = ( 'incorrect_password' == $errors->get_error_code() || 'empty_password' == $errors->get_error_code() ) ? esc_attr(stripslashes($_POST['log'])) : '';
  551. $rememberme = ! empty( $_POST['rememberme'] );
  552. ?>
  553. <form name="loginform" id="loginform" action="<?php echo esc_url( site_url( 'wp-login.php', 'login_post' ) ); ?>" method="post">
  554. <p>
  555. <label for="user_login"><?php _e('Username') ?><br />
  556. <input type="text" name="log" id="user_login" class="input" value="<?php echo esc_attr($user_login); ?>" size="20" /></label>
  557. </p>
  558. <p>
  559. <label for="user_pass"><?php _e('Password') ?><br />
  560. <input type="password" name="pwd" id="user_pass" class="input" value="" size="20" /></label>
  561. </p>
  562. <?php do_action('login_form'); ?>
  563. <p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever" <?php checked( $rememberme ); ?> /> <?php esc_attr_e('Remember Me'); ?></label></p>
  564. <p class="submit">
  565. <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="<?php esc_attr_e('Log In'); ?>" />
  566. <?php if ( $interim_login ) { ?>
  567. <input type="hidden" name="interim-login" value="1" />
  568. <?php } else { ?>
  569. <input type="hidden" name="redirect_to" value="<?php echo esc_attr($redirect_to); ?>" />
  570. <?php } ?>
  571. <?php if ( $customize_login ) : ?>
  572. <input type="hidden" name="customize-login" value="1" />
  573. <?php endif; ?>
  574. <input type="hidden" name="testcookie" value="1" />
  575. </p>
  576. </form>
  577. <?php if ( !$interim_login ) { ?>
  578. <p id="nav">
  579. <?php if ( isset($_GET['checkemail']) && in_array( $_GET['checkemail'], array('confirm', 'newpass') ) ) : ?>
  580. <?php elseif ( get_option('users_can_register') ) : ?>
  581. <a href="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login' ) ); ?>"><?php _e( 'Register' ); ?></a> |
  582. <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
  583. <?php else : ?>
  584. <a href="<?php echo esc_url( wp_lostpassword_url() ); ?>" title="<?php esc_attr_e( 'Password Lost and Found' ); ?>"><?php _e( 'Lost your password?' ); ?></a>
  585. <?php endif; ?>
  586. </p>
  587. <?php } ?>
  588. <script type="text/javascript">
  589. function wp_attempt_focus(){
  590. setTimeout( function(){ try{
  591. <?php if ( $user_login || $interim_login ) { ?>
  592. d = document.getElementById('user_pass');
  593. d.value = '';
  594. <?php } else { ?>
  595. d = document.getElementById('user_login');
  596. <?php if ( 'invalid_username' == $errors->get_error_code() ) { ?>
  597. if( d.value != '' )
  598. d.value = '';
  599. <?php
  600. }
  601. }?>
  602. d.focus();
  603. d.select();
  604. } catch(e){}
  605. }, 200);
  606. }
  607. <?php if ( !$error ) { ?>
  608. wp_attempt_focus();
  609. <?php } ?>
  610. if(typeof wpOnload=='function')wpOnload();
  611. </script>
  612. <?php
  613. login_footer();
  614. break;
  615. } // end action switch