]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/pluggable.php
Wordpress 3.5.2
[autoinstalls/wordpress.git] / wp-includes / pluggable.php
index ac308a99666fa90cecb9e141ad4d6d1774223d86..83afefab805df6f7dc921aeb48b630169025be27 100644 (file)
@@ -529,7 +529,7 @@ function wp_validate_auth_cookie($cookie = '', $scheme = '') {
 
        // Allow a grace period for POST and AJAX requests
        if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] )
 
        // Allow a grace period for POST and AJAX requests
        if ( defined('DOING_AJAX') || 'POST' == $_SERVER['REQUEST_METHOD'] )
-               $expired += 3600;
+               $expired += HOUR_IN_SECONDS;
 
        // Quick check to see if an honest cookie has expired
        if ( $expired < time() ) {
 
        // Quick check to see if an honest cookie has expired
        if ( $expired < time() ) {
@@ -694,24 +694,24 @@ if ( !function_exists('wp_clear_auth_cookie') ) :
 function wp_clear_auth_cookie() {
        do_action('clear_auth_cookie');
 
 function wp_clear_auth_cookie() {
        do_action('clear_auth_cookie');
 
-       setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
-       setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
-       setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
-       setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
-       setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
-       setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
+       setcookie( AUTH_COOKIE,        ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH,   COOKIE_DOMAIN );
+       setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, ADMIN_COOKIE_PATH,   COOKIE_DOMAIN );
+       setcookie( AUTH_COOKIE,        ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
+       setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN );
+       setcookie( LOGGED_IN_COOKIE,   ' ', time() - YEAR_IN_SECONDS, COOKIEPATH,          COOKIE_DOMAIN );
+       setcookie( LOGGED_IN_COOKIE,   ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH,      COOKIE_DOMAIN );
 
        // Old cookies
 
        // Old cookies
-       setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
-       setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
-       setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
-       setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
+       setcookie( AUTH_COOKIE,        ' ', time() - YEAR_IN_SECONDS, COOKIEPATH,     COOKIE_DOMAIN );
+       setcookie( AUTH_COOKIE,        ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
+       setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH,     COOKIE_DOMAIN );
+       setcookie( SECURE_AUTH_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
 
        // Even older cookies
 
        // Even older cookies
-       setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
-       setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
-       setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
-       setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
+       setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH,     COOKIE_DOMAIN );
+       setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH,     COOKIE_DOMAIN );
+       setcookie( USER_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
+       setcookie( PASS_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
 }
 endif;
 
 }
 endif;
 
@@ -748,11 +748,11 @@ function auth_redirect() {
 
        // If https is required and request is http, redirect
        if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
 
        // If https is required and request is http, redirect
        if ( $secure && !is_ssl() && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
-               if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
-                       wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
+               if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
+                       wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
                        exit();
                } else {
                        exit();
                } else {
-                       wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+                       wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
                        exit();
                }
        }
                        exit();
                }
        }
@@ -767,11 +767,11 @@ function auth_redirect() {
 
                // If the user wants ssl but the session is not ssl, redirect.
                if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
 
                // If the user wants ssl but the session is not ssl, redirect.
                if ( !$secure && get_user_option('use_ssl', $user_id) && false !== strpos($_SERVER['REQUEST_URI'], 'wp-admin') ) {
-                       if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
-                               wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']));
+                       if ( 0 === strpos( $_SERVER['REQUEST_URI'], 'http' ) ) {
+                               wp_redirect( set_url_scheme( $_SERVER['REQUEST_URI'], 'https' ) );
                                exit();
                        } else {
                                exit();
                        } else {
-                               wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
+                               wp_redirect( 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
                                exit();
                        }
                }
                                exit();
                        }
                }
@@ -782,12 +782,7 @@ function auth_redirect() {
        // The cookie is no good so force login
        nocache_headers();
 
        // The cookie is no good so force login
        nocache_headers();
 
-       if ( is_ssl() )
-               $proto = 'https://';
-       else
-               $proto = 'http://';
-
-       $redirect = ( strpos($_SERVER['REQUEST_URI'], '/options.php') && wp_get_referer() ) ? wp_get_referer() : $proto . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+       $redirect = ( strpos( $_SERVER['REQUEST_URI'], '/options.php' ) && wp_get_referer() ) ? wp_get_referer() : set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
 
        $login_url = wp_login_url($redirect, true);
 
 
        $login_url = wp_login_url($redirect, true);
 
@@ -1195,7 +1190,7 @@ if ( !function_exists('wp_new_user_notification') ) :
  * @param string $plaintext_pass Optional. The user's plaintext password
  */
 function wp_new_user_notification($user_id, $plaintext_pass = '') {
  * @param string $plaintext_pass Optional. The user's plaintext password
  */
 function wp_new_user_notification($user_id, $plaintext_pass = '') {
-       $user = new WP_User($user_id);
+       $user = get_userdata( $user_id );
 
        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);
 
        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);
@@ -1234,7 +1229,7 @@ if ( !function_exists('wp_nonce_tick') ) :
  * @return int
  */
 function wp_nonce_tick() {
  * @return int
  */
 function wp_nonce_tick() {
-       $nonce_life = apply_filters('nonce_life', 86400);
+       $nonce_life = apply_filters( 'nonce_life', DAY_IN_SECONDS );
 
        return ceil(time() / ( $nonce_life / 2 ));
 }
 
        return ceil(time() / ( $nonce_life / 2 ));
 }
@@ -1256,14 +1251,16 @@ if ( !function_exists('wp_verify_nonce') ) :
 function wp_verify_nonce($nonce, $action = -1) {
        $user = wp_get_current_user();
        $uid = (int) $user->ID;
 function wp_verify_nonce($nonce, $action = -1) {
        $user = wp_get_current_user();
        $uid = (int) $user->ID;
+       if ( ! $uid )
+               $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
 
        $i = wp_nonce_tick();
 
        // Nonce generated 0-12 hours ago
 
        $i = wp_nonce_tick();
 
        // Nonce generated 0-12 hours ago
-       if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) == $nonce )
+       if ( substr(wp_hash($i . $action . $uid, 'nonce'), -12, 10) === $nonce )
                return 1;
        // Nonce generated 12-24 hours ago
                return 1;
        // Nonce generated 12-24 hours ago
-       if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) == $nonce )
+       if ( substr(wp_hash(($i - 1) . $action . $uid, 'nonce'), -12, 10) === $nonce )
                return 2;
        // Invalid nonce
        return false;
                return 2;
        // Invalid nonce
        return false;
@@ -1282,6 +1279,8 @@ if ( !function_exists('wp_create_nonce') ) :
 function wp_create_nonce($action = -1) {
        $user = wp_get_current_user();
        $uid = (int) $user->ID;
 function wp_create_nonce($action = -1) {
        $user = wp_get_current_user();
        $uid = (int) $user->ID;
+       if ( ! $uid )
+               $uid = apply_filters( 'nonce_user_logged_out', $uid, $action );
 
        $i = wp_nonce_tick();
 
 
        $i = wp_nonce_tick();
 
@@ -1501,13 +1500,13 @@ function wp_generate_password( $length = 12, $special_chars = true, $extra_speci
 endif;
 
 if ( !function_exists('wp_rand') ) :
 endif;
 
 if ( !function_exists('wp_rand') ) :
- /**
+/**
  * Generates a random number
  *
  * @since 2.6.2
  *
  * Generates a random number
  *
  * @since 2.6.2
  *
- * @param int $min Lower limit for the generated number (optional, default is 0)
- * @param int $max Upper limit for the generated number (optional, default is 4294967295)
+ * @param int $min Lower limit for the generated number
+ * @param int $max Upper limit for the generated number
  * @return int A random number between min and max
  */
 function wp_rand( $min = 0, $max = 0 ) {
  * @return int A random number between min and max
  */
 function wp_rand( $min = 0, $max = 0 ) {
@@ -1536,10 +1535,12 @@ function wp_rand( $min = 0, $max = 0 ) {
 
        $value = abs(hexdec($value));
 
 
        $value = abs(hexdec($value));
 
+       // 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.
+       $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff
+
        // Reduce the value to be within the min - max range
        // Reduce the value to be within the min - max range
-       // 4294967295 = 0xffffffff = max random number
        if ( $max != 0 )
        if ( $max != 0 )
-               $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
+               $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 );
 
        return abs(intval($value));
 }
 
        return abs(intval($value));
 }
@@ -1577,7 +1578,7 @@ if ( !function_exists( 'get_avatar' ) ) :
  * @param int|string|object $id_or_email A user ID,  email address, or comment object
  * @param int $size Size of the avatar image
  * @param string $default URL to a default image to use if no avatar is available
  * @param int|string|object $id_or_email A user ID,  email address, or comment object
  * @param int $size Size of the avatar image
  * @param string $default URL to a default image to use if no avatar is available
- * @param string $alt Alternate text to use in image tag. Defaults to blank
+ * @param string $alt Alternative text to use in image tag. Defaults to blank
  * @return string <img> tag for the user's avatar
 */
 function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
  * @return string <img> tag for the user's avatar
 */
 function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
@@ -1639,7 +1640,7 @@ function get_avatar( $id_or_email, $size = '96', $default = '', $alt = false ) {
        if ( 'mystery' == $default )
                $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
        elseif ( 'blank' == $default )
        if ( 'mystery' == $default )
                $default = "$host/avatar/ad516503a11cd5ca435acc9bb6523536?s={$size}"; // ad516503a11cd5ca435acc9bb6523536 == md5('unknown@gravatar.com')
        elseif ( 'blank' == $default )
-               $default = includes_url('images/blank.gif');
+               $default = $email ? 'blank' : includes_url( 'images/blank.gif' );
        elseif ( !empty($email) && 'gravatar_default' == $default )
                $default = '';
        elseif ( 'gravatar_default' == $default )
        elseif ( !empty($email) && 'gravatar_default' == $default )
                $default = '';
        elseif ( 'gravatar_default' == $default )