Make WordPress Core

Ticket #13045: wp-login.2.php

File wp-login.2.php, 25.3 KB (added by F J Kaiser, 15 years ago)

from 3.0-nightly build (download 50 min ago)

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