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