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
This commit is contained in:
ryan 2010-06-24 15:01:29 +00:00
parent 2468b66784
commit 81e213c211
11 changed files with 56 additions and 62 deletions

View File

@ -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();
?>
<tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">

View File

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

View File

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

View File

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

View File

@ -178,7 +178,7 @@ 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;
@ -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 "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>";
}
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;
?>
<table class="form-table">
<tr>
@ -768,8 +766,8 @@ function choose_primary_blog() {
<th scope="row"><?php _e( 'Primary Site' ); ?></th>
<td>
<?php
$all_blogs = get_blogs_of_user( $current_user->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() {
<?php
if ( !$found ) {
$blog = array_shift( $all_blogs );
update_user_meta( $current_user->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";
}

View File

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

View File

@ -847,7 +847,7 @@ function get_hidden_columns($screen) {
* @param string $screen
*/
function inline_edit_row( $screen ) {
global $current_user, $mode;
global $mode;
if ( is_string($screen) ) {
$screen = array('id' => 'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen );
@ -928,7 +928,7 @@ endif; // post_type_supports title ?>
<?php endif; // $bulk
if ( post_type_supports( $screen->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 = "<strong>$user_object->user_login</strong><br />";
}
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'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Delete') . '</a>';
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'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=remove&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Remove') . '</a>';
$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',
<br class="clear" />
</p>
<input type="hidden" name="user_ID" id="user_ID" value="<?php echo $current_user->ID; ?>" />
<input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" />
<input type="hidden" name="action" id="action" value="" />
<input type="hidden" name="comment_ID" id="comment_ID" value="" />
<input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" />

View File

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

View File

@ -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;
@ -407,6 +407,7 @@ function switch_to_blog( $new_blog, $validate = false ) {
$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 );

View File

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

View File

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