PageRenderTime 683ms CodeModel.GetById 21ms RepoModel.GetById 2ms app.codeStats 0ms

/wp-login.php

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