PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-login.php

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