WordPress.org

Make WordPress Core

Ticket #13934: current-user-assumptions.13934.diff

File current-user-assumptions.13934.diff, 18.4 KB (added by filosofo, 4 years ago)
  • wp-signup.php

     
    153153} 
    154154 
    155155function signup_another_blog($blogname = '', $blog_title = '', $errors = '') { 
    156         global $current_user, $current_site; 
     156        global $current_site; 
     157        $current_user = wp_get_current_user(); 
    157158 
    158159        if ( ! is_wp_error($errors) ) { 
    159160                $errors = new WP_Error(); 
     
    197198} 
    198199 
    199200function validate_another_blog_signup() { 
    200         global $wpdb, $current_user, $blogname, $blog_title, $errors, $domain, $path; 
     201        global $wpdb, $blogname, $blog_title, $errors, $domain, $path; 
    201202        $current_user = wp_get_current_user(); 
    202203        if ( !is_user_logged_in() ) 
    203204                die(); 
  • wp-includes/ms-blogs.php

     
    371371} 
    372372 
    373373function switch_to_blog( $new_blog, $validate = false ) { 
    374         global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache; 
     374        global $wpdb, $table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; 
    375375 
    376376        if ( empty($new_blog) ) 
    377377                $new_blog = $blog_id; 
     
    406406                        $wp_roles->__construct(); 
    407407                $wpdb->suppress_errors( false ); 
    408408        } 
    409  
     409  
     410        $current_user = wp_get_current_user(); 
    410411        if ( is_object( $current_user ) ) 
    411412                $current_user->for_blog( $blog_id ); 
    412413 
     
    430431} 
    431432 
    432433function restore_current_blog() { 
    433         global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $current_user, $wp_object_cache; 
     434        global $table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache; 
    434435 
    435436        if ( !$switched ) 
    436437                return false; 
     
    460461                $wpdb->suppress_errors( false ); 
    461462        } 
    462463 
     464        $current_user = wp_get_current_user(); 
    463465        if ( is_object( $current_user ) ) 
    464466                $current_user->for_blog( $blog_id ); 
    465467 
  • wp-includes/ms-functions.php

     
    372372} 
    373373 
    374374function is_blog_user( $blog_id = 0 ) { 
    375         global $current_user, $wpdb; 
    376  
     375        global $wpdb; 
     376  
     377        $current_user = wp_get_current_user(); 
    377378        if ( !$blog_id ) 
    378379                $blog_id = $wpdb->blogid; 
    379380 
     
    13191320 
    13201321function is_user_spammy( $username = 0 ) { 
    13211322        if ( $username == 0 ) { 
    1322                 global $current_user; 
    1323                 $user_id = $current_user->ID; 
     1323                $user_id = get_current_user_id(); 
    13241324        } else { 
    13251325                $user_id = get_user_id_from_string( $username ); 
    13261326        } 
     
    13601360} 
    13611361 
    13621362function is_user_option_local( $key, $user_id = 0, $blog_id = 0 ) { 
    1363         global $current_user, $wpdb; 
     1363        global $wpdb; 
    13641364 
     1365        $current_user = wp_get_current_user(); 
    13651366        if ( $user_id == 0 ) 
    13661367                $user_id = $current_user->ID; 
    13671368        if ( $blog_id == 0 ) 
  • wp-admin/includes/bookmark.php

     
    128128 * @return unknown 
    129129 */ 
    130130function wp_insert_link( $linkdata, $wp_error = false ) { 
    131         global $wpdb, $current_user; 
     131        global $wpdb; 
    132132 
    133133        $defaults = array( 'link_id' => 0, 'link_name' => '', 'link_url' => '', 'link_rating' => 0 ); 
    134134 
     
    166166                $link_visible = 'Y'; 
    167167 
    168168        if ( empty( $link_owner ) ) 
    169                 $link_owner = $current_user->id; 
     169                $link_owner = get_current_user_id(); 
    170170 
    171171        if ( empty( $link_notes ) ) 
    172172                $link_notes = ''; 
  • wp-admin/includes/post.php

     
    11701170 * @return bool|int False: not locked or locked by current user. Int: user ID of user with lock. 
    11711171 */ 
    11721172function wp_check_post_lock( $post_id ) { 
    1173         global $current_user; 
    1174  
    11751173        if ( !$post = get_post( $post_id ) ) 
    11761174                return false; 
    11771175 
     
    11801178 
    11811179        $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ); 
    11821180 
    1183         if ( $lock && $lock > time() - $time_window && $last != $current_user->ID ) 
     1181        if ( $lock && $lock > time() - $time_window && $last != get_current_user_id() ) 
    11841182                return $last; 
    11851183        return false; 
    11861184} 
     
    11941192 * @return bool Returns false if the post doesn't exist of there is no current user 
    11951193 */ 
    11961194function wp_set_post_lock( $post_id ) { 
    1197         global $current_user; 
    11981195        if ( !$post = get_post( $post_id ) ) 
    11991196                return false; 
    1200         if ( !$current_user || !$current_user->ID ) 
     1197        if ( 0 == get_current_user_id() ) 
    12011198                return false; 
    12021199 
    12031200        $now = time(); 
     
    12521249        if ( $old_autosave = wp_get_post_autosave( $post_id ) ) { 
    12531250                $new_autosave = _wp_post_revision_fields( $_POST, true ); 
    12541251                $new_autosave['ID'] = $old_autosave->ID; 
    1255                 $current_user = wp_get_current_user(); 
    1256                 $new_autosave['post_author'] = $current_user->ID; 
     1252                $new_autosave['post_author'] = get_current_user_id(); 
    12571253                return wp_update_post( $new_autosave ); 
    12581254        } 
    12591255 
     
    16111607/* ]]> */ 
    16121608</script> 
    16131609<?php 
    1614 } 
    1615  No newline at end of file 
     1610} 
  • wp-admin/includes/meta-boxes.php

     
    501501 * @param object $post 
    502502 */ 
    503503function post_author_meta_box($post) { 
    504         global $current_user, $user_ID; 
    505         $authors = get_editable_user_ids( $current_user->id, true, $post->post_type ); // TODO: ROLE SYSTEM 
     504        global $user_ID; 
     505        $authors = get_editable_user_ids( get_current_user_id(), true, $post->post_type ); // TODO: ROLE SYSTEM 
    506506        if ( $post->post_author && !in_array($post->post_author, $authors) ) 
    507507                $authors[] = $post->post_author; 
    508508?> 
  • wp-admin/includes/template.php

     
    847847 * @param string $screen 
    848848 */ 
    849849function inline_edit_row( $screen ) { 
    850         global $current_user, $mode; 
     850        global $mode; 
    851851 
    852852        if ( is_string($screen) ) { 
    853853                $screen = array('id' => 'edit-' . $screen, 'base' => 'edit', 'post_type' => $screen ); 
     
    928928<?php endif; // $bulk 
    929929 
    930930        if ( post_type_supports( $screen->post_type, 'author' ) ) : 
    931                 $authors = get_editable_user_ids( $current_user->id, true, $screen->post_type ); // TODO: ROLE SYSTEM 
     931                $authors = get_editable_user_ids( get_current_user_id(), true, $screen->post_type ); // TODO: ROLE SYSTEM 
    932932                $authors_dropdown = ''; 
    933933                if ( $authors && count( $authors ) > 1 ) : 
    934934                        $users_opt = array('include' => $authors, 'name' => 'post_author', 'class'=> 'authors', 'multi' => 1, 'echo' => 0); 
     
    12691269 * @param unknown_type $mode 
    12701270 */ 
    12711271function _post_row($a_post, $pending_comments, $mode) { 
    1272         global $post, $current_user, $current_screen; 
     1272        global $post, $current_screen; 
    12731273        static $rowclass; 
    12741274 
    12751275        $global_post = $post; 
     
    12771277        setup_postdata($post); 
    12781278 
    12791279        $rowclass = 'alternate' == $rowclass ? '' : 'alternate'; 
    1280         $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' ); 
     1280        $post_owner = ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); 
    12811281        $edit_link = get_edit_post_link( $post->ID ); 
    12821282        $title = _draft_or_post_title(); 
    12831283        $post_type_object = get_post_type_object($post->post_type); 
     
    17951795function user_row( $user_object, $style = '', $role = '', $numposts = 0 ) { 
    17961796        global $wp_roles; 
    17971797 
    1798         $current_user = wp_get_current_user(); 
    1799  
    18001798        if ( !( is_object( $user_object) && is_a( $user_object, 'WP_User' ) ) ) 
    18011799                $user_object = new WP_User( (int) $user_object ); 
    18021800        $user_object = sanitize_user_object($user_object, 'display'); 
     
    18131811        if ( current_user_can( 'list_users' ) ) { 
    18141812                // Set up the user editing link 
    18151813                // TODO: make profile/user-edit determination a separate function 
    1816                 if ($current_user->ID == $user_object->ID) { 
     1814                if ( get_current_user_id() == $user_object->ID) { 
    18171815                        $edit_link = 'profile.php'; 
    18181816                } else { 
    18191817                        $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" ) ); 
     
    18301828                        $edit = "<strong>$user_object->user_login</strong><br />"; 
    18311829                } 
    18321830 
    1833                 if ( !is_multisite() && $current_user->ID != $user_object->ID && current_user_can('delete_user', $user_object->ID) ) 
     1831                if ( !is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('delete_user', $user_object->ID) ) 
    18341832                        $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=delete&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Delete') . "</a>"; 
    1835                 if ( is_multisite() && $current_user->ID != $user_object->ID && current_user_can('remove_user', $user_object->ID) ) 
     1833                if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can('remove_user', $user_object->ID) ) 
    18361834                        $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url("users.php?action=remove&amp;user=$user_object->ID", 'bulk-users') . "'>" . __('Remove') . "</a>"; 
    18371835                $actions = apply_filters('user_row_actions', $actions, $user_object); 
    18381836                $action_count = count($actions); 
     
    22252223 * @param unknown_type $mode 
    22262224 */ 
    22272225function wp_comment_reply($position = '1', $checkbox = false, $mode = 'single', $table_row = true) { 
    2228         global $current_user; 
    2229  
    22302226        // allow plugin to replace the popup content 
    22312227        $content = apply_filters( 'wp_comment_reply', '', array('position' => $position, 'checkbox' => $checkbox, 'mode' => $mode) ); 
    22322228 
     
    22782274        <br class="clear" /> 
    22792275        </p> 
    22802276 
    2281         <input type="hidden" name="user_ID" id="user_ID" value="<?php echo $current_user->ID; ?>" /> 
     2277        <input type="hidden" name="user_ID" id="user_ID" value="<?php echo get_current_user_id(); ?>" /> 
    22822278        <input type="hidden" name="action" id="action" value="" /> 
    22832279        <input type="hidden" name="comment_ID" id="comment_ID" value="" /> 
    22842280        <input type="hidden" name="comment_post_ID" id="comment_post_ID" value="" /> 
  • wp-admin/includes/user.php

     
    2121 */ 
    2222function add_user() { 
    2323        if ( func_num_args() ) { // The hackiest hack that ever did hack 
    24                 global $current_user, $wp_roles; 
     24                global $wp_roles; 
    2525                $user_id = (int) func_get_arg( 0 ); 
    2626 
    2727                if ( isset( $_POST['role'] ) ) { 
    2828                        $new_role = sanitize_text_field( $_POST['role'] ); 
    2929                        // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. 
    30                         if ( $user_id != $current_user->id || $wp_roles->role_objects[$new_role]->has_cap( 'edit_users' ) ) { 
     30                        if ( $user_id != get_current_user_id() || $wp_roles->role_objects[$new_role]->has_cap( 'edit_users' ) ) { 
    3131                                // If the new role isn't editable by the logged-in user die with error 
    3232                                $editable_roles = get_editable_roles(); 
    3333                                if ( empty( $editable_roles[$new_role] ) ) 
     
    5454 * @return int user id of the updated user 
    5555 */ 
    5656function edit_user( $user_id = 0 ) { 
    57         global $current_user, $wp_roles, $wpdb; 
     57        global $wp_roles, $wpdb; 
    5858        if ( $user_id != 0 ) { 
    5959                $update = true; 
    6060                $user->ID = (int) $user_id; 
     
    7979                $potential_role = isset($wp_roles->role_objects[$new_role]) ? $wp_roles->role_objects[$new_role] : false; 
    8080                // Don't let anyone with 'edit_users' (admins) edit their own role to something without it. 
    8181                // Multisite super admins can freely edit their blog roles -- they possess all caps. 
    82                 if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != $current_user->id || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) ) 
     82                if ( ( is_multisite() && current_user_can( 'manage_sites' ) ) || $user_id != get_current_user_id() || ($potential_role && $potential_role->has_cap( 'edit_users' ) ) ) 
    8383                        $user->role = $new_role; 
    8484 
    8585                // If the new role isn't editable by the logged-in user die with error 
  • wp-admin/includes/ms.php

     
    178178} 
    179179 
    180180function confirm_delete_users( $users ) { 
    181         global $current_user; 
     181        $current_user = wp_get_current_user(); 
    182182        if ( !is_array( $users ) ) 
    183183                return false; 
    184184 
    185     screen_icon(); 
    186     ?> 
     185        screen_icon(); 
     186        ?> 
    187187        <h2><?php esc_html_e( 'Users' ); ?></h2> 
    188188        <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p> 
    189189        <form action="ms-edit.php?action=dodelete" method="post"> 
    190190        <input type="hidden" name="dodelete" /> 
    191     <?php 
     191        <?php 
    192192        wp_nonce_field( 'ms-users-delete' ); 
    193193        $site_admins = get_super_admins(); 
    194194        $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>"; 
     
    311311add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 ); 
    312312 
    313313function send_confirmation_on_profile_email() { 
    314         global $errors, $wpdb, $current_user; 
     314        global $errors, $wpdb; 
     315        $current_user = wp_get_current_user(); 
    315316        if ( ! is_object($errors) ) 
    316317                $errors = new WP_Error(); 
    317318 
     
    364365add_action( 'personal_options_update', 'send_confirmation_on_profile_email' ); 
    365366 
    366367function new_user_email_admin_notice() { 
    367         global $current_user; 
    368         if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( $current_user->ID . '_new_email' ) ) 
     368        if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) ) 
    369369                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>"; 
    370370} 
    371371add_action( 'admin_notices', 'new_user_email_admin_notice' ); 
     
    598598add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 ); 
    599599 
    600600function redirect_user_to_blog() { 
    601         global $current_user; 
    602601        $c = 0; 
    603602        if ( isset( $_GET['c'] ) ) 
    604603                $c = (int) $_GET['c']; 
     
    608607        } 
    609608        $c ++; 
    610609 
    611         $blog = get_active_blog_for_user( $current_user->ID ); 
     610        $blog = get_active_blog_for_user( get_current_user_id() ); 
    612611        $dashboard_blog = get_dashboard_blog(); 
    613612        if ( is_object( $blog ) ) { 
    614613                wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); // redirect and count to 5, "just in case" 
     
    619618           If the user is a member of only 1 blog and the user's primary_blog isn't set to that blog, 
    620619           then update the primary_blog record to match the user's blog 
    621620         */ 
    622         $blogs = get_blogs_of_user( $current_user->ID ); 
     621        $blogs = get_blogs_of_user( get_current_user_id() ); 
    623622 
    624623        if ( !empty( $blogs ) ) { 
    625624                foreach( $blogs as $blogid => $blog ) { 
    626                         if ( $blogid != $dashboard_blog->blog_id && get_user_meta( $current_user->ID , 'primary_blog', true ) == $dashboard_blog->blog_id ) { 
    627                                 update_user_meta( $current_user->ID, 'primary_blog', $blogid ); 
     625                        if ( $blogid != $dashboard_blog->blog_id && get_user_meta( get_current_user_id() , 'primary_blog', true ) == $dashboard_blog->blog_id ) { 
     626                                update_user_meta( get_current_user_id(), 'primary_blog', $blogid ); 
    628627                                continue; 
    629628                        } 
    630629                } 
    631                 $blog = get_blog_details( get_user_meta( $current_user->ID, 'primary_blog', true ) ); 
     630                $blog = get_blog_details( get_user_meta( get_current_user_id(), 'primary_blog', true ) ); 
    632631                        wp_redirect( get_admin_url( $blog->blog_id, '?c=' . $c ) ); 
    633632                exit; 
    634633        } 
     
    697696add_action( 'admin_notices', 'secret_salt_warning' ); 
    698697 
    699698function admin_notice_feed() { 
    700         global $current_user, $current_screen; 
     699        global $current_screen; 
    701700        if ( $current_screen->id != 'dashboard' ) 
    702701                return; 
    703702 
    704703        if ( !empty( $_GET['feed_dismiss'] ) ) { 
    705                 update_user_option( $current_user->id, 'admin_feed_dismiss', $_GET['feed_dismiss'], true ); 
     704                update_user_option( get_current_user_id(), 'admin_feed_dismiss', $_GET['feed_dismiss'], true ); 
    706705                return; 
    707706        } 
    708707 
     
    728727add_action( 'admin_notices', 'admin_notice_feed' ); 
    729728 
    730729function site_admin_notice() { 
    731         global $current_user, $wp_db_version; 
     730        global $wp_db_version; 
    732731        if ( !is_super_admin() ) 
    733732                return false; 
    734733        if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) 
     
    760759add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 ); 
    761760 
    762761function choose_primary_blog() { 
    763         global $current_user; 
    764762        ?> 
    765763        <table class="form-table"> 
    766764        <tr> 
     
    768766                <th scope="row"><?php _e( 'Primary Site' ); ?></th> 
    769767                <td> 
    770768                <?php 
    771                 $all_blogs = get_blogs_of_user( $current_user->ID ); 
    772                 $primary_blog = get_user_meta( $current_user->ID, 'primary_blog', true ); 
     769                $all_blogs = get_blogs_of_user( get_current_user_id() ); 
     770                $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true ); 
    773771                if ( count( $all_blogs ) > 1 ) { 
    774772                        $found = false; 
    775773                        ?> 
     
    783781                        <?php 
    784782                        if ( !$found ) { 
    785783                                $blog = array_shift( $all_blogs ); 
    786                                 update_user_meta( $current_user->ID, 'primary_blog', $blog->userblog_id ); 
     784                                update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); 
    787785                        } 
    788786                } elseif ( count( $all_blogs ) == 1 ) { 
    789787                        $blog = array_shift( $all_blogs ); 
    790788                        echo $blog->domain; 
    791789                        if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list. 
    792                                 update_user_meta( $current_user->ID, 'primary_blog', $blog->userblog_id ); 
     790                                update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id ); 
    793791                } else { 
    794792                        echo "N/A"; 
    795793                } 
  • wp-admin/includes/class-wp-importer.php

     
    215215         * @return bool 
    216216         */ 
    217217        function is_user_over_quota() { 
    218                 global $current_user, $current_blog; 
     218                global $current_blog; 
    219219 
    220220                if ( function_exists( 'upload_is_user_over_quota' ) ) { 
    221221                        if ( upload_is_user_over_quota( 1 ) ) { 
  • wp-admin/edit-attachment-rows.php

     
    3939        continue; 
    4040 
    4141$alt = ( 'alternate' == $alt ) ? '' : 'alternate'; 
    42 global $current_user; 
    43 $post_owner = ( $current_user->ID == $post->post_author ? 'self' : 'other' ); 
     42 
     43$post_owner = ( get_current_user_id() == $post->post_author ? 'self' : 'other' ); 
    4444$att_title = _draft_or_post_title(); 
    4545?> 
    4646        <tr id='post-<?php echo $id; ?>' class='<?php echo trim( $alt . ' author-' . $post_owner . ' status-' . $post->post_status ); ?>' valign="top">