diff --git a/wp-admin/admin.php b/wp-admin/admin.php index ab53b4c5da..12d56c429d 100644 --- a/wp-admin/admin.php +++ b/wp-admin/admin.php @@ -17,7 +17,7 @@ nocache_headers(); update_category_cache(); -get_currentuserinfo(); +wp_get_current_user(); $posts_per_page = get_settings('posts_per_page'); $what_to_show = get_settings('what_to_show'); diff --git a/wp-admin/comment.php b/wp-admin/comment.php index 2a97d91724..e431c3d571 100644 --- a/wp-admin/comment.php +++ b/wp-admin/comment.php @@ -26,8 +26,6 @@ case 'editcomment': $editing = true; require_once ('admin-header.php'); - get_currentuserinfo(); - $comment = (int) $_GET['comment']; if ( ! $comment = get_comment($comment) ) diff --git a/wp-admin/edit-form-ajax-cat.php b/wp-admin/edit-form-ajax-cat.php index 06b260aaae..1da142f852 100644 --- a/wp-admin/edit-form-ajax-cat.php +++ b/wp-admin/edit-form-ajax-cat.php @@ -3,8 +3,6 @@ require_once('../wp-config.php'); require_once('admin-functions.php'); require_once('admin-db.php'); -get_currentuserinfo(); - if ( !current_user_can('manage_categories') ) die('-1'); diff --git a/wp-admin/list-manipulation.php b/wp-admin/list-manipulation.php index 623226aa6c..44563b8079 100644 --- a/wp-admin/list-manipulation.php +++ b/wp-admin/list-manipulation.php @@ -3,7 +3,6 @@ require_once('../wp-config.php'); require_once('admin-functions.php'); require_once('admin-db.php'); -get_currentuserinfo(); if ( !is_user_logged_in() ) die('-1'); diff --git a/wp-admin/options.php b/wp-admin/options.php index 8895bcef43..5e479e45d7 100644 --- a/wp-admin/options.php +++ b/wp-admin/options.php @@ -68,8 +68,6 @@ case 'update': if ( get_settings('siteurl') != $old_siteurl || get_settings('home') != $old_home ) { // If home changed, write rewrite rules to new location. $wp_rewrite->flush_rules(); - // Get currently logged in user and password. - get_currentuserinfo(); // Clear cookies for old paths. wp_clearcookie(); // Set cookies for new paths. diff --git a/wp-admin/page-new.php b/wp-admin/page-new.php index 8435c17280..61f77a932b 100644 --- a/wp-admin/page-new.php +++ b/wp-admin/page-new.php @@ -13,8 +13,6 @@ require_once('admin-header.php'); post_type = 'page'; diff --git a/wp-comments-post.php b/wp-comments-post.php index e2ccba6af9..0d2ab03445 100644 --- a/wp-comments-post.php +++ b/wp-comments-post.php @@ -24,11 +24,11 @@ $comment_author_url = trim($_POST['url']); $comment_content = trim($_POST['comment']); // If the user is logged in -get_currentuserinfo(); -if ( $user_ID ) : - $comment_author = $wpdb->escape($user_identity); - $comment_author_email = $wpdb->escape($user_email); - $comment_author_url = $wpdb->escape($user_url); +$user = wp_get_current_user(); +if ( $user->ID ) : + $comment_author = $wpdb->escape($user->display_name); + $comment_author_email = $wpdb->escape($user->user_email); + $comment_author_url = $wpdb->escape($user->user_url); else : if ( get_option('comment_registration') ) die( __('Sorry, you must be logged in to post a comment.') ); @@ -36,7 +36,7 @@ endif; $comment_type = ''; -if ( get_settings('require_name_email') && !$user_ID ) { +if ( get_settings('require_name_email') && !$user->ID ) { if ( 6 > strlen($comment_author_email) || '' == $comment_author ) die( __('Error: please fill the required fields (name, email).') ); elseif ( !is_email($comment_author_email)) @@ -50,7 +50,7 @@ $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_emai wp_new_comment( $commentdata ); -if ( !$user_ID ) : +if ( !$user->ID ) : setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); setcookie('comment_author_url_' . COOKIEHASH, stripslashes(clean_url($comment_author_url)), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index e72f0d1184..3810aa72a2 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -395,7 +395,7 @@ function map_meta_cap($cap, $user_id) { // Capability checking wrapper around the global $current_user object. function current_user_can($capability) { - global $current_user; + $current_user = wp_get_current_user(); $args = array_slice(func_get_args(), 1); $args = array_merge(array($capability), $args); diff --git a/wp-includes/classes.php b/wp-includes/classes.php index abb0f3d8e7..9e22a99e57 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -1587,7 +1587,6 @@ class WP { } function send_headers() { - global $current_user; @header('X-Pingback: '. get_bloginfo('pingback_url')); if ( is_user_logged_in() ) nocache_headers(); @@ -1664,7 +1663,7 @@ class WP { } function init() { - get_currentuserinfo(); + wp_get_current_user(); } function query_posts() { diff --git a/wp-includes/comment-functions.php b/wp-includes/comment-functions.php index a61610aea5..4a5f676685 100644 --- a/wp-includes/comment-functions.php +++ b/wp-includes/comment-functions.php @@ -18,8 +18,6 @@ function comments_template( $file = '/comments.php' ) { $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date"); } - get_currentuserinfo(); - define('COMMENTS_TEMPLATE', true); $include = apply_filters('comments_template', TEMPLATEPATH . $file ); if ( file_exists( $include ) ) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 0c3cda29cb..c0df33f40c 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -303,10 +303,10 @@ function get_option($option) { } function get_user_option( $option, $user = 0 ) { - global $wpdb, $current_user; + global $wpdb; if ( empty($user) ) - $user = $current_user; + $user = wp_get_current_user(); else $user = get_userdata($user); @@ -1176,6 +1176,28 @@ function setup_postdata($post) { return true; } +// Setup global user vars. Used by set_current_user() for back compat. +function setup_userdata($user_id = '') { + global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity; + + if ( '' == $user_id ) + $user = wp_get_current_user(); + else + $user = new WP_User($user_id); + + if ( 0 == $user->ID ) + return; + + $userdata = $user->data; + $user_login = $user->user_login; + $user_level = $user->user_level; + $user_ID = $user->ID; + $user_email = $user->user_email; + $user_url = $user->user_url; + $user_pass_md5 = md5($user->user_pass); + $user_identity = $user->display_name; +} + function is_new_day() { global $day, $previousday; if ( $day != $previousday ) { diff --git a/wp-includes/kses.php b/wp-includes/kses.php index a0bdf2c8da..97bed209a5 100644 --- a/wp-includes/kses.php +++ b/wp-includes/kses.php @@ -528,16 +528,11 @@ function kses_init_filters() { } function kses_init() { - global $current_user; - remove_filter('pre_comment_author', 'wp_filter_kses'); remove_filter('pre_comment_content', 'wp_filter_kses'); remove_filter('content_save_pre', 'wp_filter_post_kses'); remove_filter('title_save_pre', 'wp_filter_kses'); - if (! defined('XMLRPC_REQUEST') ) - get_currentuserinfo(); - if (current_user_can('unfiltered_html') == false) kses_init_filters(); } diff --git a/wp-includes/pluggable-functions.php b/wp-includes/pluggable-functions.php index 6856c1c7e6..cc1030ae9e 100644 --- a/wp-includes/pluggable-functions.php +++ b/wp-includes/pluggable-functions.php @@ -5,21 +5,20 @@ if ( !function_exists('set_current_user') ) : function set_current_user($id, $name = '') { - global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity, $current_user; + return wp_set_current_user($id, $name); +} +endif; - $current_user = ''; +if ( !function_exists('wp_set_current_user') ) : +function wp_set_current_user($id, $name = '') { + global $current_user; - $current_user = new WP_User($id, $name); + if ( isset($current_user) && ($id == $current_user->ID) ) + return $current_user; - $userdata = get_userdatabylogin($user_login); + $current_user = new WP_User($id, $name); - $user_login = $userdata->user_login; - $user_level = $userdata->user_level; - $user_ID = $userdata->ID; - $user_email = $userdata->user_email; - $user_url = $userdata->user_url; - $user_pass_md5 = md5($userdata->user_pass); - $user_identity = $userdata->display_name; + setup_userdata($current_user->ID); do_action('set_current_user'); @@ -27,30 +26,34 @@ function set_current_user($id, $name = '') { } endif; +if ( !function_exists('current_user') ) : +function wp_get_current_user() { + global $current_user; + + get_currentuserinfo(); + + return $current_user; +} +endif; if ( !function_exists('get_currentuserinfo') ) : function get_currentuserinfo() { - global $user_login, $userdata, $user_level, $user_ID, $user_email, $user_url, $user_pass_md5, $user_identity, $current_user; + global $current_user; if ( defined('XMLRPC_REQUEST') && XMLRPC_REQUEST ) return false; + if ( ! empty($current_user) ) + return; + if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[PASS_COOKIE]) || !wp_login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) { - $current_user = new WP_User(0); + wp_set_current_user(0); return false; } - $user_login = $_COOKIE[USER_COOKIE]; - $userdata = get_userdatabylogin($user_login); - $user_level = $userdata->user_level; - $user_ID = $userdata->ID; - $user_email = $userdata->user_email; - $user_url = $userdata->user_url; - $user_pass_md5 = md5($userdata->user_pass); - $user_identity = $userdata->display_name; - if ( empty($current_user) ) - $current_user = new WP_User($user_ID); + $user_login = $_COOKIE[USER_COOKIE]; + wp_set_current_user(0, $user_login); } endif; @@ -201,10 +204,11 @@ endif; if ( !function_exists('is_user_logged_in') ) : function is_user_logged_in() { - global $current_user; + $user = wp_get_current_user(); - if ( $current_user->id == 0 ) + if ( $user->id == 0 ) return false; + return true; } endif; diff --git a/wp-includes/registration-functions.php b/wp-includes/registration-functions.php index 26f0a80402..4805f45dac 100644 --- a/wp-includes/registration-functions.php +++ b/wp-includes/registration-functions.php @@ -101,7 +101,7 @@ function wp_insert_user($userdata) { } function wp_update_user($userdata) { - global $wpdb, $current_user; + global $wpdb; $ID = (int) $userdata['ID']; @@ -122,6 +122,7 @@ function wp_update_user($userdata) { $user_id = wp_insert_user($userdata); // Update the cookies if the password changed. + $current_user = wp_get_current_user(); if( $current_user->id == $ID ) { if ( isset($plaintext_pass) ) { wp_clearcookie(); diff --git a/wp-includes/template-functions-general.php b/wp-includes/template-functions-general.php index 1efe9092e5..4a0fd89c12 100644 --- a/wp-includes/template-functions-general.php +++ b/wp-includes/template-functions-general.php @@ -27,10 +27,7 @@ function get_sidebar() { function wp_loginout() { - global $user_ID; - get_currentuserinfo(); - - if ('' == $user_ID) + if ( ! is_user_logged_in() ) $link = '' . __('Login') . ''; else $link = '' . __('Logout') . ''; @@ -40,16 +37,15 @@ function wp_loginout() { function wp_register( $before = '
  • ', $after = '
  • ' ) { - global $user_ID; - get_currentuserinfo(); - - if ( '' == $user_ID && get_settings('users_can_register') ) - $link = $before . '' . __('Register') . '' . $after; - elseif ( '' == $user_ID && !get_settings('users_can_register') ) - $link = ''; - else + if ( ! is_user_logged_in() ) { + if ( get_settings('users_can_register') ) + $link = $before . '' . __('Register') . '' . $after; + else + $link = ''; + } else { $link = $before . '' . __('Site Admin') . '' . $after; + } echo apply_filters('register', $link); }