692 * @since 2.5 |
692 * @since 2.5 |
693 */ |
693 */ |
694 function wp_clear_auth_cookie() { |
694 function wp_clear_auth_cookie() { |
695 do_action('clear_auth_cookie'); |
695 do_action('clear_auth_cookie'); |
696 |
696 |
697 setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); |
697 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); |
698 setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN); |
698 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH, COOKIE_DOMAIN ); |
699 setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); |
699 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); |
700 setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN); |
700 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN ); |
701 setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
701 setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
702 setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
702 setcookie( LOGGED_IN_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
703 |
703 |
704 // Old cookies |
704 // Old cookies |
705 setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
705 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
706 setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
706 setcookie( AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
707 setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
707 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
708 setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
708 setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
709 |
709 |
710 // Even older cookies |
710 // Even older cookies |
711 setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
711 setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
712 setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); |
712 setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN ); |
713 setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
713 setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
714 setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); |
714 setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN ); |
715 } |
715 } |
716 endif; |
716 endif; |
717 |
717 |
718 if ( !function_exists('is_user_logged_in') ) : |
718 if ( !function_exists('is_user_logged_in') ) : |
719 /** |
719 /** |
746 |
746 |
747 $secure = apply_filters('secure_auth_redirect', $secure); |
747 $secure = apply_filters('secure_auth_redirect', $secure); |
748 |
748 |
749 // If https is required and request is http, redirect |
749 // If https is required and request is http, redirect |
750 if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { |
750 if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { |
751 if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { |
751 if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { |
752 wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); |
752 wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
753 exit(); |
753 exit(); |
754 } else { |
754 } else { |
755 wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
755 wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
756 exit(); |
756 exit(); |
757 } |
757 } |
758 } |
758 } |
759 |
759 |
760 if ( is_user_admin() ) |
760 if ( is_user_admin() ) |
765 if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) { |
765 if ( $user_id = wp_validate_auth_cookie( '', $scheme) ) { |
766 do_action('auth_redirect', $user_id); |
766 do_action('auth_redirect', $user_id); |
767 |
767 |
768 // If the user wants ssl but the session is not ssl, redirect. |
768 // If the user wants ssl but the session is not ssl, redirect. |
769 if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { |
769 if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) { |
770 if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) { |
770 if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) { |
771 wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI'])); |
771 wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) ); |
772 exit(); |
772 exit(); |
773 } else { |
773 } else { |
774 wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); |
774 wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
775 exit(); |
775 exit(); |
776 } |
776 } |
777 } |
777 } |
778 |
778 |
779 return; // The cookie is good so we're done |
779 return; // The cookie is good so we're done |
780 } |
780 } |
781 |
781 |
782 // The cookie is no good so force login |
782 // The cookie is no good so force login |
783 nocache_headers(); |
783 nocache_headers(); |
784 |
784 |
785 if ( is_ssl() ) |
785 $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
786 $proto = 'https://'; |
|
787 else |
|
788 $proto = 'http://'; |
|
789 |
|
790 $redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; |
|
791 |
786 |
792 $login_url = wp_login_url($redirect, true); |
787 $login_url = wp_login_url($redirect, true); |
793 |
788 |
794 wp_redirect($login_url); |
789 wp_redirect($login_url); |
795 exit(); |
790 exit(); |
1254 * @return bool Whether the nonce check passed or failed. |
1249 * @return bool Whether the nonce check passed or failed. |
1255 */ |
1250 */ |
1256 function wp_verify_nonce($nonce, $action = -1) { |
1251 function wp_verify_nonce($nonce, $action = -1) { |
1257 $user = wp_get_current_user(); |
1252 $user = wp_get_current_user(); |
1258 $uid = (int) $user->ID; |
1253 $uid = (int) $user->ID; |
|
1254 if ( ! $uid ) |
|
1255 $uid = apply_filters( 'nonce_user_logged_out', $uid, $action ); |
1259 |
1256 |
1260 $i = wp_nonce_tick(); |
1257 $i = wp_nonce_tick(); |
1261 |
1258 |
1262 // Nonce generated 0-12 hours ago |
1259 // Nonce generated 0-12 hours ago |
1263 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce ) |
1260 if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce ) |
1534 // Strip the first eight, leaving the remainder for the next call to wp_rand(). |
1533 // Strip the first eight, leaving the remainder for the next call to wp_rand(). |
1535 $rnd_value = substr($rnd_value, 8); |
1534 $rnd_value = substr($rnd_value, 8); |
1536 |
1535 |
1537 $value = abs(hexdec($value)); |
1536 $value = abs(hexdec($value)); |
1538 |
1537 |
|
1538 // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. |
|
1539 $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff |
|
1540 |
1539 // Reduce the value to be within the min - max range |
1541 // Reduce the value to be within the min - max range |
1540 // 4294967295 = 0xffffffff = max random number |
|
1541 if ( $max != 0 ) |
1542 if ( $max != 0 ) |
1542 $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1))); |
1543 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); |
1543 |
1544 |
1544 return abs(intval($value)); |
1545 return abs(intval($value)); |
1545 } |
1546 } |
1546 endif; |
1547 endif; |
1547 |
1548 |
1575 * |
1576 * |
1576 * @since 2.5 |
1577 * @since 2.5 |
1577 * @param int|string|object $id_or_email A user ID, email address, or comment object |
1578 * @param int|string|object $id_or_email A user ID, email address, or comment object |
1578 * @param int $size Size of the avatar image |
1579 * @param int $size Size of the avatar image |
1579 * @param string $default URL to a default image to use if no avatar is available |
1580 * @param string $default URL to a default image to use if no avatar is available |
1580 * @param string $alt Alternate text to use in image tag. Defaults to blank |
1581 * @param string $alt Alternative text to use in image tag. Defaults to blank |
1581 * @return string <img> tag for the user's avatar |
1582 * @return string <img> tag for the user's avatar |
1582 */ |
1583 */ |
1583 function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) { |
1584 function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) { |
1584 if ( ! get_option('show_avatars') ) |
1585 if ( ! get_option('show_avatars') ) |
1585 return false; |
1586 return false; |