@@ -768,8 +766,8 @@ function choose_primary_blog() {
|
ID );
- $primary_blog = get_user_meta( $current_user->ID, 'primary_blog', true );
+ $all_blogs = get_blogs_of_user( get_current_user_id() );
+ $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
if ( count( $all_blogs ) > 1 ) {
$found = false;
?>
@@ -783,13 +781,13 @@ function choose_primary_blog() {
ID, 'primary_blog', $blog->userblog_id );
+ update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
}
} elseif ( count( $all_blogs ) == 1 ) {
$blog = array_shift( $all_blogs );
echo $blog->domain;
if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
- update_user_meta( $current_user->ID, 'primary_blog', $blog->userblog_id );
+ update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
} else {
echo "N/A";
}
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index 5f8b6fd0f2..c679193b02 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -1170,8 +1170,6 @@ function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
* @return bool|int False: not locked or locked by current user. Int: user ID of user with lock.
*/
function wp_check_post_lock( $post_id ) {
- global $current_user;
-
if ( !$post = get_post( $post_id ) )
return false;
@@ -1180,7 +1178,7 @@ function wp_check_post_lock( $post_id ) {
$time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 );
- if ( $lock && $lock > time() - $time_window && $last != $current_user->ID )
+ if ( $lock && $lock > time() - $time_window && $last != get_current_user_id() )
return $last;
return false;
}
@@ -1194,10 +1192,9 @@ function wp_check_post_lock( $post_id ) {
* @return bool Returns false if the post doesn't exist of there is no current user
*/
function wp_set_post_lock( $post_id ) {
- global $current_user;
if ( !$post = get_post( $post_id ) )
return false;
- if ( !$current_user || !$current_user->ID )
+ if ( 0 == get_current_user_id() )
return false;
$now = time();
@@ -1252,8 +1249,7 @@ function wp_create_post_autosave( $post_id ) {
if ( $old_autosave = wp_get_post_autosave( $post_id ) ) {
$new_autosave = _wp_post_revision_fields( $_POST, true );
$new_autosave['ID'] = $old_autosave->ID;
- $current_user = wp_get_current_user();
- $new_autosave['post_author'] = $current_user->ID;
+ $new_autosave['post_author'] = get_current_user_id();
return wp_update_post( $new_autosave );
}
@@ -1611,4 +1607,4 @@ tinyMCE.init(tinyMCEPreInit.mceInit);
/* ]]> */
'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen );
@@ -928,7 +928,7 @@ endif; // post_type_supports title ?>
post_type, 'author' ) ) :
- $authors = get_editable_user_ids( $current_user->id, true, $screen->post_type ); // TODO: ROLE SYSTEM
+ $authors = get_editable_user_ids( get_current_user_id(), true, $screen->post_type ); // TODO: ROLE SYSTEM
$authors_dropdown = '';
if ( $authors && count( $authors ) > 1 ) :
$users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, 'echo' => 0);
@@ -1268,7 +1268,7 @@ function post_rows( $posts = array() ) {
* @param unknown_type $mode
*/
function _post_row($a_post, $pending_comments, $mode) {
- global $post, $current_user, $current_screen;
+ global $post, $current_screen;
static $rowclass;
$global_post = $post;
@@ -1276,7 +1276,7 @@ function _post_row($a_post, $pending_comments, $mode) {
setup_postdata($post);
$rowclass = 'alternate' == $rowclass ? '' : 'alternate';
- $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' );
+ $post_owner = ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
$edit_link = get_edit_post_link( $post->ID );
$title = _draft_or_post_title();
$post_type_object = get_post_type_object($post->post_type);
@@ -1794,8 +1794,6 @@ function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_
function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
global $wp_roles;
- $current_user = wp_get_current_user();
-
if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) )
$user_object = new WP_User( (int) $user_object );
$user_object = sanitize_user_object($user_object, 'display');
@@ -1812,7 +1810,7 @@ function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
if ( current_user_can( 'list_users' ) ) {
// Set up the user editing link
// TODO: make profile/user-edit determination a separate function
- if ($current_user->ID == $user_object->ID) {
+ if ( get_current_user_id() == $user_object->ID) {
$edit_link = 'profile.php';
} else {
$edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( esc_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
@@ -1829,9 +1827,9 @@ function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) {
$edit = "$user_object->user_login ";
}
- if ( !is_multisite() && $current_user->ID != $user_object->ID && current_user_can('delete_user', $user_object->ID) )
+ if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('delete_user', $user_object->ID) )
$actions['delete'] = "" . __('Delete') . '';
- if ( is_multisite() && $current_user->ID != $user_object->ID && current_user_can('remove_user', $user_object->ID) )
+ if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('remove_user', $user_object->ID) )
$actions['remove'] = "" . __('Remove') . '';
$actions = apply_filters('user_row_actions', $actions, $user_object);
$action_count = count($actions);
@@ -2224,8 +2222,6 @@ function _wp_comment_row( $comment_id, $mode, $comment_status, $checkbox = true,
* @param unknown_type $mode
*/
function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) {
- global $current_user;
-
// allow plugin to replace the popup content
$content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) );
@@ -2277,7 +2273,7 @@ function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single',
-
+
diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php
index 7a72297534..b31c38bd09 100644
--- a/wp-admin/includes/user.php
+++ b/wp-admin/includes/user.php
@@ -21,13 +21,13 @@
*/
function add_user() {
if ( func_num_args() ) { // The hackiest hack that ever did hack
- global $current_user, $wp_roles;
+ global $wp_roles;
$user_id = (int) func_get_arg( 0 );
if ( isset( $_POST['role'] ) ) {
$new_role = sanitize_text_field( $_POST['role'] );
// Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
- if ( $user_id != $current_user->id || $wp_roles->role_objects[$new_role]->has_cap( 'edit_users' ) ) {
+ if ( $user_id != get_current_user_id() || $wp_roles->role_objects[$new_role]->has_cap( 'edit_users' ) ) {
// If the new role isn't editable by the logged-in user die with error
$editable_roles = get_editable_roles();
if ( empty( $editable_roles[$new_role] ) )
@@ -54,7 +54,7 @@ function add_user() {
* @return int user id of the updated user
*/
function edit_user( $user_id = 0 ) {
- global $current_user, $wp_roles, $wpdb;
+ global $wp_roles, $wpdb;
if ( $user_id != 0 ) {
$update = true;
$user->ID = (int) $user_id;
@@ -79,7 +79,7 @@ function edit_user( $user_id = 0 ) {
$potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false;
// Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
// Multisite super admins can freely edit their blog roles -- they possess all caps.
- if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != $current_user->id || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) )
+ if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != get_current_user_id() || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) )
$user->role = $new_role;
// If the new role isn't editable by the logged-in user die with error
diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php
index 80462f300c..be650f3a4f 100644
--- a/wp-includes/ms-blogs.php
+++ b/wp-includes/ms-blogs.php
@@ -371,7 +371,7 @@ function update_blog_option( $id, $key, $value, $refresh = true ) {
}
function switch_to_blog( $new_blog, $validate = false ) {
- global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache;
+ global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
if ( empty($new_blog) )
$new_blog = $blog_id;
@@ -406,7 +406,8 @@ function switch_to_blog( $new_blog, $validate = false ) {
$wp_roles->__construct();
$wpdb->suppress_errors( false );
}
-
+
+ $current_user = wp_get_current_user();
if ( is_object( $current_user ) )
$current_user->for_blog( $blog_id );
@@ -430,7 +431,7 @@ function switch_to_blog( $new_blog, $validate = false ) {
}
function restore_current_blog() {
- global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache;
+ global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;
if ( !$switched )
return false;
@@ -460,6 +461,7 @@ function restore_current_blog() {
$wpdb->suppress_errors( false );
}
+ $current_user = wp_get_current_user();
if ( is_object( $current_user ) )
$current_user->for_blog( $blog_id );
diff --git a/wp-includes/ms-functions.php b/wp-includes/ms-functions.php
index 93e30bed0b..8f2c6b800c 100644
--- a/wp-includes/ms-functions.php
+++ b/wp-includes/ms-functions.php
@@ -372,8 +372,9 @@ function wpmu_admin_redirect_add_updated_param( $url = '' ) {
}
function is_blog_user( $blog_id = 0 ) {
- global $current_user, $wpdb;
-
+ global $wpdb;
+
+ $current_user = wp_get_current_user();
if ( !$blog_id )
$blog_id = $wpdb->blogid;
@@ -1319,8 +1320,7 @@ function fix_phpmailer_messageid( $phpmailer ) {
function is_user_spammy( $username = 0 ) {
if ( $username == 0 ) {
- global $current_user;
- $user_id = $current_user->ID;
+ $user_id = get_current_user_id();
} else {
$user_id = get_user_id_from_string( $username );
}
@@ -1360,8 +1360,9 @@ function get_dashboard_blog() {
}
function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) {
- global $current_user, $wpdb;
+ global $wpdb;
+ $current_user = wp_get_current_user();
if ( $user_id == 0 )
$user_id = $current_user->ID;
if ( $blog_id == 0 )
diff --git a/wp-signup.php b/wp-signup.php
index cbea126889..28b561a993 100644
--- a/wp-signup.php
+++ b/wp-signup.php
@@ -153,7 +153,8 @@ function validate_user_form() {
}
function signup_another_blog($blogname = '', $blog_title = '', $errors = '') {
- global $current_user, $current_site;
+ global $current_site;
+ $current_user = wp_get_current_user();
if ( ! is_wp_error($errors) ) {
$errors = new WP_Error();
@@ -197,7 +198,7 @@ function signup_another_blog($blogname = '', $blog_title = '', $errors = '') {
}
function validate_another_blog_signup() {
- global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path;
+ global $wpdb, $blogname, $blog_title, $errors, $domain, $path;
$current_user = wp_get_current_user();
if ( !is_user_logged_in() )
die();
|