current user cleanup

git-svn-id: http://svn.automattic.com/wordpress/trunk@3566 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2006-02-22 19:08:55 +00:00
parent e06ed8c9b6
commit 5322fc2faa
15 changed files with 73 additions and 67 deletions

View File

@ -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');

View File

@ -26,8 +26,6 @@ case 'editcomment':
$editing = true;
require_once ('admin-header.php');
get_currentuserinfo();
$comment = (int) $_GET['comment'];
if ( ! $comment = get_comment($comment) )

View File

@ -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');

View File

@ -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');

View File

@ -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.

View File

@ -13,8 +13,6 @@ require_once('admin-header.php');
<?php
if ( current_user_can('edit_pages') ) {
$action = 'post';
get_currentuserinfo();
$post = get_default_post_to_edit();
$post->post_type = 'page';

View File

@ -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);

View File

@ -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);

View File

@ -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() {

View File

@ -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 ) )

View File

@ -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 ) {

View File

@ -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();
}

View File

@ -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;

View File

@ -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();

View File

@ -27,10 +27,7 @@ function get_sidebar() {
function wp_loginout() {
global $user_ID;
get_currentuserinfo();
if ('' == $user_ID)
if ( ! is_user_logged_in() )
$link = '<a href="' . get_settings('siteurl') . '/wp-login.php">' . __('Login') . '</a>';
else
$link = '<a href="' . get_settings('siteurl') . '/wp-login.php?action=logout">' . __('Logout') . '</a>';
@ -40,16 +37,15 @@ function wp_loginout() {
function wp_register( $before = '<li>', $after = '</li>' ) {
global $user_ID;
get_currentuserinfo();
if ( '' == $user_ID && get_settings('users_can_register') )
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
elseif ( '' == $user_ID && !get_settings('users_can_register') )
$link = '';
else
if ( ! is_user_logged_in() ) {
if ( get_settings('users_can_register') )
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-register.php">' . __('Register') . '</a>' . $after;
else
$link = '';
} else {
$link = $before . '<a href="' . get_settings('siteurl') . '/wp-admin/">' . __('Site Admin') . '</a>' . $after;
}
echo apply_filters('register', $link);
}