PageRenderTime 60ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-login.php

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