From 81e213c211d1646be35551a2172b1470eec48c37 Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 24 Jun 2010 15:01:29 +0000 Subject: [PATCH] Use get_current_user() and get_current_user_id() instead of global . Props filofo. see #13934 for trunk git-svn-id: http://svn.automattic.com/wordpress/trunk@15315 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-attachment-rows.php | 4 +-- wp-admin/includes/bookmark.php | 4 +-- wp-admin/includes/class-wp-importer.php | 2 +- wp-admin/includes/meta-boxes.php | 4 +-- wp-admin/includes/ms.php | 40 ++++++++++++------------- wp-admin/includes/post.php | 12 +++----- wp-admin/includes/template.php | 20 +++++-------- wp-admin/includes/user.php | 8 ++--- wp-includes/ms-blogs.php | 8 +++-- wp-includes/ms-functions.php | 11 +++---- wp-signup.php | 5 ++-- 11 files changed, 56 insertions(+), 62 deletions(-) diff --git a/wp-admin/edit-attachment-rows.php b/wp-admin/edit-attachment-rows.php index 0014d7205e..d88316be90 100644 --- a/wp-admin/edit-attachment-rows.php +++ b/wp-admin/edit-attachment-rows.php @@ -39,8 +39,8 @@ elseif ( !$is_trash && $post->post_status == 'trash' ) continue; $alt = ( 'alternate' == $alt ) ? '' : 'alternate'; -global $current_user; -$post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' ); + +$post_owner = ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); $att_title = _draft_or_post_title(); ?> post_status ); ?>' valign="top"> diff --git a/wp-admin/includes/bookmark.php b/wp-admin/includes/bookmark.php index 7dd8baf651..09e5411e59 100644 --- a/wp-admin/includes/bookmark.php +++ b/wp-admin/includes/bookmark.php @@ -128,7 +128,7 @@ function get_link_to_edit( $link_id ) { * @return unknown */ function wp_insert_link( $linkdata, $wp_error = false ) { - global $wpdb, $current_user; + global $wpdb; $defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 ); @@ -166,7 +166,7 @@ function wp_insert_link( $linkdata, $wp_error = false ) { $link_visible = 'Y'; if ( empty( $link_owner ) ) - $link_owner = $current_user->id; + $link_owner = get_current_user_id(); if ( empty( $link_notes ) ) $link_notes = ''; diff --git a/wp-admin/includes/class-wp-importer.php b/wp-admin/includes/class-wp-importer.php index 6376325c24..8115ff2ece 100644 --- a/wp-admin/includes/class-wp-importer.php +++ b/wp-admin/includes/class-wp-importer.php @@ -216,7 +216,7 @@ class WP_Importer { * @return bool */ function is_user_over_quota() { - global $current_user, $current_blog; + global $current_blog; if ( function_exists( 'upload_is_user_over_quota' ) ) { if ( upload_is_user_over_quota( 1 ) ) { diff --git a/wp-admin/includes/meta-boxes.php b/wp-admin/includes/meta-boxes.php index 0f8b339b26..5358874c7b 100644 --- a/wp-admin/includes/meta-boxes.php +++ b/wp-admin/includes/meta-boxes.php @@ -501,8 +501,8 @@ function post_slug_meta_box($post) { * @param object $post */ function post_author_meta_box($post) { - global $current_user, $user_ID; - $authors = get_editable_user_ids( $current_user->id, true, $post->post_type ); // TODO: ROLE SYSTEM + global $user_ID; + $authors = get_editable_user_ids( get_current_user_id(), true, $post->post_type ); // TODO: ROLE SYSTEM if ( $post->post_author && !in_array($post->post_author, $authors) ) $authors[] = $post->post_author; ?> diff --git a/wp-admin/includes/ms.php b/wp-admin/includes/ms.php index ae23b7f80b..23b870d627 100644 --- a/wp-admin/includes/ms.php +++ b/wp-admin/includes/ms.php @@ -178,17 +178,17 @@ function wpmu_delete_user( $id ) { } function confirm_delete_users( $users ) { - global $current_user; + $current_user = wp_get_current_user(); if ( !is_array( $users ) ) return false; - screen_icon(); - ?> + screen_icon(); + ?>

- ID'>$current_user->user_login"; @@ -311,7 +311,8 @@ add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10 add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); function send_confirmation_on_profile_email() { - global $errors, $wpdb, $current_user; + global $errors, $wpdb; + $current_user = wp_get_current_user(); if ( ! is_object($errors) ) $errors = new WP_Error(); @@ -364,8 +365,7 @@ All at ###SITENAME### add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); function new_user_email_admin_notice() { - global $current_user; - if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( $current_user->ID . '_new_email' ) ) + if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) echo "
" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "
"; } add_action( 'admin_notices', 'new_user_email_admin_notice' ); @@ -598,7 +598,6 @@ function sync_category_tag_slugs( $term, $taxonomy ) { add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 ); function redirect_user_to_blog() { - global $current_user; $c = 0; if ( isset( $_GET['c'] ) ) $c = (int) $_GET['c']; @@ -608,7 +607,7 @@ function redirect_user_to_blog() { } $c ++; - $blog = get_active_blog_for_user( $current_user->ID ); + $blog = get_active_blog_for_user( get_current_user_id() ); $dashboard_blog = get_dashboard_blog(); if ( is_object( $blog ) ) { wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case" @@ -619,16 +618,16 @@ function redirect_user_to_blog() { If the user is a member of only 1 blog and the user's primary_blog isn't set to that blog, then update the primary_blog record to match the user's blog */ - $blogs = get_blogs_of_user( $current_user->ID ); + $blogs = get_blogs_of_user( get_current_user_id() ); if ( !empty( $blogs ) ) { foreach( $blogs as $blogid => $blog ) { - if ( $blogid != $dashboard_blog->blog_id && get_user_meta( $current_user->ID , 'primary_blog', true ) == $dashboard_blog->blog_id ) { - update_user_meta( $current_user->ID, 'primary_blog', $blogid ); + if ( $blogid != $dashboard_blog->blog_id && get_user_meta( get_current_user_id() , 'primary_blog', true ) == $dashboard_blog->blog_id ) { + update_user_meta( get_current_user_id(), 'primary_blog', $blogid ); continue; } } - $blog = get_blog_details( get_user_meta( $current_user->ID, 'primary_blog', true ) ); + $blog = get_blog_details( get_user_meta( get_current_user_id(), 'primary_blog', true ) ); wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); exit; } @@ -697,12 +696,12 @@ function secret_salt_warning() { add_action( 'admin_notices', 'secret_salt_warning' ); function admin_notice_feed() { - global $current_user, $current_screen; + global $current_screen; if ( $current_screen->id != 'dashboard' ) return; if ( !empty( $_GET['feed_dismiss'] ) ) { - update_user_option( $current_user->id, 'admin_feed_dismiss', $_GET['feed_dismiss'], true ); + update_user_option( get_current_user_id(), 'admin_feed_dismiss', $_GET['feed_dismiss'], true ); return; } @@ -728,7 +727,7 @@ function admin_notice_feed() { add_action( 'admin_notices', 'admin_notice_feed' ); function site_admin_notice() { - global $current_user, $wp_db_version; + global $wp_db_version; if ( !is_super_admin() ) return false; if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) @@ -760,7 +759,6 @@ function avoid_blog_page_permalink_collision( $data, $postarr ) { add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 ); function choose_primary_blog() { - global $current_user; ?> @@ -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();