Permalink
Browse files

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
  • Loading branch information...
1 parent 2468b66 commit 81e213c211d1646be35551a2172b1470eec48c37 ryan committed Jun 24, 2010
@@ -39,8 +39,8 @@
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">
@@ -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 = '';
@@ -216,7 +216,7 @@ function bump_request_timeout( $val ) {
* @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 ) ) {
@@ -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
@@ -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();
+ ?>
<h2><?php esc_html_e( 'Users' ); ?></h2>
<p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p>
<form action="ms-edit.php?action=dodelete" method="post">
<input type="hidden" name="dodelete" />
- <?php
+ <?php
wp_nonce_field( 'ms-users-delete' );
$site_admins = get_super_admins();
$admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
@@ -311,7 +311,8 @@ function update_option_new_admin_email( $old_value, $value ) {
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 @@ function send_confirmation_on_profile_email() {
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,16 +759,15 @@ 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>
<?php /* translators: My sites label */ ?>
<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
@@ -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 @@ function wp_tiny_mce( $teeny = false, $settings = false ) {
/* ]]> */
</script>
<?php
-}
+}
@@ -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 @@ function inline_edit_row( $screen ) {
<?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,15 +1268,15 @@ 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;
$post = $a_post;
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="" />
@@ -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
@@ -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 );
Oops, something went wrong.

0 comments on commit 81e213c

Please sign in to comment.