Make WordPress Core

Ticket #37699: 37699-get_current_blog_id.diff

File 37699-get_current_blog_id.diff, 9.6 KB (added by wonderboymusic, 8 years ago)
  • src/wp-admin/includes/class-wp-themes-list-table.php

     
    9191                        return;
    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;
    103104                        }
  • src/wp-includes/cache.php

     
    729729         * Sets up object properties; PHP 5 style constructor.
    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
    742738                /**
  • src/wp-includes/class-wp-user-query.php

     
    104104         */
    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(),
    110110                        'role__not_in' => array(),
  • src/wp-includes/deprecated.php

     
    23572357 * @see get_users()
    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.
    23632362 * @return array List of users that are part of that site ID
     
    23652364function get_users_of_blog( $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" );
    23732373        return $users;
  • src/wp-includes/load.php

     
    470470 *
    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
    487484                $first_init = true;
     
    495492                wp_using_ext_object_cache( true );
    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        /*
    502500         * If cache supports reset, reset instead of init if already
     
    503501         * initialized. Reset signals to the cache that global IDs
    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' ) ) {
    512511                wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'site-details', 'rss', 'global-posts', 'blog-id-cache', 'networks', 'sites' ) );
  • src/wp-includes/ms-blogs.php

     
    766766function switch_to_blog( $new_blog, $deprecated = null ) {
    767767        global $wpdb;
    768768
    769         if ( empty( $new_blog ) )
    770                 $new_blog = $GLOBALS['blog_id'];
     769        $blog_id = get_current_blog_id();
     770        if ( empty( $new_blog ) ) {
     771                $new_blog = $blog_id;
     772        }
    771773
    772         $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
     774        $GLOBALS['_wp_switched_stack'][] = $blog_id;
    773775
    774776        /*
    775777         * If we're switching to the same blog id that we're on,
     
    776778         * set the right vars, do the associated actions, but skip
    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.
    782784                 *
     
    792794
    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
    798800        if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
     
    800802        } else {
    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
    810812                if ( function_exists( 'wp_cache_add_global_groups' ) ) {
     
    848850function restore_current_blog() {
    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'] );
     858        $blog_id = get_current_blog_id();
    855859
    856         if ( $GLOBALS['blog_id'] == $blog ) {
     860        if ( $blog_id == $blog ) {
    857861                /** This filter is documented in wp-includes/ms-blogs.php */
    858862                do_action( 'switch_blog', $blog, $blog );
    859863                // If we still have items in the switched stack, consider ourselves still 'switched'
     
    862866        }
    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();
    868872
     
    871875        } else {
    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();
    880885
  • src/wp-includes/ms-functions.php

     
    19661966 *
    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                /**
    19801977                 * Fires immediately after an existing user is added to a site.
  • src/wp-includes/user.php

     
    965965 * @since 2.3.0
    966966 * @since 4.5.0 Added the 'display_name_with_login' value for 'show'.
    967967 *
    968  * @global int  $blog_id
    969  *
    970968 * @param array|string $args {
    971969 *     Optional. Array or string of arguments to generate a drop-down of users.
    972970 *     See WP_User_Query::prepare_query() for additional available arguments.
     
    10161014                'include' => '', 'exclude' => '', 'multi' => 0,
    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        );
    10221020