Make WordPress Core

Changeset 38457


Ignore:
Timestamp:
08/31/2016 04:55:01 AM (10 years ago)
Author:
wonderboymusic
Message:

Multisite: use get_current_blog_id() where applicable, in lieu of plucking the $blog_id global from outer space.

See #37699.

Location:
trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-themes-list-table.php

    r38028 r38457  
    9292                }
    9393
     94                $blog_id = get_current_blog_id();
    9495                if ( is_multisite() ) {
    9596                        if ( current_user_can( 'install_themes' ) && current_user_can( 'manage_network_themes' ) ) {
    96                                 printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ), network_admin_url( 'theme-install.php' ) );
     97                                printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> or <a href="%2$s">install</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ), network_admin_url( 'theme-install.php' ) );
    9798
    9899                                return;
    99100                        } elseif ( current_user_can( 'manage_network_themes' ) ) {
    100                                 printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $GLOBALS['blog_id'] ) );
     101                                printf( __( 'You only have one theme enabled for this site right now. Visit the Network Admin to <a href="%1$s">enable</a> more themes.' ), network_admin_url( 'site-themes.php?id=' . $blog_id ) );
    101102
    102103                                return;
  • trunk/src/wp-includes/cache.php

    r38335 r38457  
    730730         *
    731731         * @since 2.0.8
    732          *
    733      * @global int $blog_id Global blog ID.
    734732         */
    735733        public function __construct() {
    736                 global $blog_id;
    737 
    738734                $this->multisite = is_multisite();
    739                 $this->blog_prefix =  $this->multisite ? $blog_id . ':' : '';
     735                $this->blog_prefix =  $this->multisite ? get_current_blog_id() . ':' : '';
    740736
    741737
  • trunk/src/wp-includes/class-wp-user-query.php

    r38275 r38457  
    105105        public static function fill_query_vars( $args ) {
    106106                $defaults = array(
    107                         'blog_id' => $GLOBALS['blog_id'],
     107                        'blog_id' => get_current_blog_id(),
    108108                        'role' => '',
    109109                        'role__in' => array(),
  • trunk/src/wp-includes/deprecated.php

    r38343 r38457  
    23582358 *
    23592359 * @global wpdb $wpdb    WordPress database abstraction object.
    2360  * @global int  $blog_id The site ID of the site for those that use more than one site.
    23612360 *
    23622361 * @param int $id Site ID.
    … …  
    23662365        _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );
    23672366
    2368         global $wpdb, $blog_id;
    2369         if ( empty($id) )
    2370                 $id = (int) $blog_id;
     2367        global $wpdb;
     2368        if ( empty( $id ) ) {
     2369                $id = get_current_blog_id();
     2370        }
    23712371        $blog_prefix = $wpdb->get_blog_prefix($id);
    23722372        $users = $wpdb->get_results( "SELECT user_id, user_id AS ID, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE {$wpdb->users}.ID = {$wpdb->usermeta}.user_id AND meta_key = '{$blog_prefix}capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
  • trunk/src/wp-includes/load.php

    r38431 r38457  
    471471 * @since 3.0.0
    472472 * @access private
    473  *
    474  * @global int $blog_id Blog ID.
    475473 */
    476474function wp_start_object_cache() {
    477         global $blog_id;
    478 
    479475        $first_init = false;
    480476        if ( ! function_exists( 'wp_cache_init' ) ) {
    481477                if ( file_exists( WP_CONTENT_DIR . '/object-cache.php' ) ) {
    482478                        require_once ( WP_CONTENT_DIR . '/object-cache.php' );
    483                         if ( function_exists( 'wp_cache_init' ) )
     479                        if ( function_exists( 'wp_cache_init' ) ) {
    484480                                wp_using_ext_object_cache( true );
     481                        }
    485482                }
    486483
    … …  
    496493        }
    497494
    498         if ( ! wp_using_ext_object_cache() )
     495        if ( ! wp_using_ext_object_cache() ) {
    499496                require_once ( ABSPATH . WPINC . '/cache.php' );
     497        }
    500498
    501499        /*
    … …  
    504502         * have changed and it may need to update keys and cleanup caches.
    505503         */
    506         if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) )
    507                 wp_cache_switch_to_blog( $blog_id );
    508         elseif ( function_exists( 'wp_cache_init' ) )
     504        if ( ! $first_init && function_exists( 'wp_cache_switch_to_blog' ) ) {
     505                wp_cache_switch_to_blog( get_current_blog_id() );
     506        } elseif ( function_exists( 'wp_cache_init' ) ) {
    509507                wp_cache_init();
     508        }
    510509
    511510        if ( function_exists( 'wp_cache_add_global_groups' ) ) {
  • trunk/src/wp-includes/ms-blogs.php

    r38388 r38457  
    767767        global $wpdb;
    768768
    769         if ( empty( $new_blog ) )
    770                 $new_blog = $GLOBALS['blog_id'];
    771 
    772         $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
     769        $blog_id = get_current_blog_id();
     770        if ( empty( $new_blog ) ) {
     771                $new_blog = $blog_id;
     772        }
     773
     774        $GLOBALS['_wp_switched_stack'][] = $blog_id;
    773775
    774776        /*
    … …  
    777779         * the extra unnecessary work
    778780         */
    779         if ( $new_blog == $GLOBALS['blog_id'] ) {
     781        if ( $new_blog == $blog_id ) {
    780782                /**
    781783                 * Fires when the blog is switched.
    … …  
    793795        $wpdb->set_blog_id( $new_blog );
    794796        $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    795         $prev_blog_id = $GLOBALS['blog_id'];
     797        $prev_blog_id = $blog_id;
    796798        $GLOBALS['blog_id'] = $new_blog;
    797799
    … …  
    801803                global $wp_object_cache;
    802804
    803                 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
     805                if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) {
    804806                        $global_groups = $wp_object_cache->global_groups;
    805                 else
     807                } else {
    806808                        $global_groups = false;
    807 
     809                }
    808810                wp_cache_init();
    809811
    … …  
    849851        global $wpdb;
    850852
    851         if ( empty( $GLOBALS['_wp_switched_stack'] ) )
     853        if ( empty( $GLOBALS['_wp_switched_stack'] ) ) {
    852854                return false;
     855        }
    853856
    854857        $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
    855 
    856         if ( $GLOBALS['blog_id'] == $blog ) {
     858        $blog_id = get_current_blog_id();
     859
     860        if ( $blog_id == $blog ) {
    857861                /** This filter is documented in wp-includes/ms-blogs.php */
    858862                do_action( 'switch_blog', $blog, $blog );
    … …  
    863867
    864868        $wpdb->set_blog_id( $blog );
    865         $prev_blog_id = $GLOBALS['blog_id'];
     869        $prev_blog_id = $blog_id;
    866870        $GLOBALS['blog_id'] = $blog;
    867871        $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
    … …  
    872876                global $wp_object_cache;
    873877
    874                 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
     878                if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) {
    875879                        $global_groups = $wp_object_cache->global_groups;
    876                 else
     880                } else {
    877881                        $global_groups = false;
     882                }
    878883
    879884                wp_cache_init();
  • trunk/src/wp-includes/ms-functions.php

    r38388 r38457  
    19671967 * @since MU
    19681968 *
    1969  * @global int $blog_id
    1970  *
    19711969 * @param array $details
    19721970 * @return true|WP_Error|void
    19731971 */
    19741972function add_existing_user_to_blog( $details = false ) {
    1975         global $blog_id;
    1976 
    19771973        if ( is_array( $details ) ) {
     1974                $blog_id = get_current_blog_id();
    19781975                $result = add_user_to_blog( $blog_id, $details[ 'user_id' ], $details[ 'role' ] );
    19791976                /**
  • trunk/src/wp-includes/user.php

    r38406 r38457  
    965965 * @since 2.3.0
    966966 * @since 4.5.0 Added the 'display_name_with_login' value for 'show'.
    967  *
    968  * @global int  $blog_id
    969967 *
    970968 * @param array|string $args {
    … …  
    10171015                'show' => 'display_name', 'echo' => 1,
    10181016                'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
    1019                 'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false,
     1017                'blog_id' => get_current_blog_id(), 'who' => '', 'include_selected' => false,
    10201018                'option_none_value' => -1
    10211019        );
Note: See TracChangeset for help on using the changeset viewer.