From 23948ab3646d6b2901b2d0d959f3676ff1212c6b Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 28 Oct 2010 15:46:11 +0000 Subject: [PATCH] get_current_blog_id(). Props aaroncampbell. fixes #15233 git-svn-id: http://svn.automattic.com/wordpress/trunk@16050 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-app.php | 4 ++-- wp-includes/admin-bar/admin-bar-class.php | 6 ++---- wp-includes/general-template.php | 12 ++++++++++++ wp-includes/post.php | 10 +++++----- wp-includes/user.php | 12 +++++------- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/wp-app.php b/wp-app.php index f21c3c068..2eaf6195e 100644 --- a/wp-app.php +++ b/wp-app.php @@ -387,7 +387,7 @@ EOD; * @since 2.2.0 */ function create_post() { - global $blog_id, $user_ID; + global $user_ID; $this->get_accepted_content_type($this->atom_content_types); $parser = new AtomParser(); @@ -419,7 +419,7 @@ EOD; if ( !current_user_can($cap) ) $this->auth_required(__('Sorry, you do not have the right to edit/publish new posts.')); - $blog_ID = (int ) $blog_id; + $blog_ID = get_current_blog_id(); $post_status = ($publish) ? 'publish' : 'draft'; $post_author = (int) $user_ID; $post_title = $entry->title[1]; diff --git a/wp-includes/admin-bar/admin-bar-class.php b/wp-includes/admin-bar/admin-bar-class.php index c9a03aca1..ed7d764e0 100644 --- a/wp-includes/admin-bar/admin-bar-class.php +++ b/wp-includes/admin-bar/admin-bar-class.php @@ -7,8 +7,6 @@ class WP_Admin_Bar { var $user; function initialize() { - global $blog_id; - /* Only load super admin menu code if the logged in user is a super admin */ if ( is_super_admin() ) { require( ABSPATH . WPINC . '/admin-bar/admin-bar-superadmin.php' ); @@ -28,7 +26,7 @@ class WP_Admin_Bar { $this->user->domain = empty( $this->user->active_blog ) ? user_admin_url() : trailingslashit( get_home_url( $this->user->active_blog->blog_id ) ); $this->user->account_domain = $this->user->domain; } else { - $this->user->active_blog = $this->user->blogs[$blog_id]; + $this->user->active_blog = $this->user->blogs[get_current_blog_id()]; $this->user->domain = trailingslashit( home_url() ); $this->user->account_domain = $this->user->domain; } @@ -85,7 +83,7 @@ class WP_Admin_Bar { function remove_menu( $id ) { return $this->remove_node( $id, $this->menu ); } - + function render() { ?>
diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index d6782e746..62234d4b4 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -491,6 +491,18 @@ function get_bloginfo( $show = '', $filter = 'raw' ) { return $output; } +/** + * Retrieve the current blog id + * + * @since 3.1.0 + * + * @return int Blog id + */ +function get_current_blog_id() { + global $blog_id; + return absint($blog_id); +} + /** * Display or retrieve page title for all areas of blog. * diff --git a/wp-includes/post.php b/wp-includes/post.php index 6cc664260..fb1582b6a 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -1016,7 +1016,7 @@ function register_post_type($post_type, $args = array()) { * behave like edit_posts. * - publish_posts - Controls publishing objects of this post type. * - read_private_posts - Controls whether private objects can be read. - + * These four primitive capabilities are checked in core in various locations. * There are also seven other primitive capabilities which are not referenced * directly in core, except in map_meta_cap(), which takes the three aforementioned @@ -2265,11 +2265,11 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 'suppress_filters' => true ); - + $r = wp_parse_args( $args, $defaults ); $results = get_posts( $r ); - + // Backward compatibility. Prior to 3.1 expected posts to be returned in array if ( ARRAY_A == $output ){ foreach( $results as $key => $result ) { @@ -4141,7 +4141,7 @@ function get_lastpostmodified($timezone = 'server') { * @return string The date. */ function _get_last_post_time( $timezone, $field ) { - global $wpdb, $blog_id; + global $wpdb; if ( !in_array( $field, array( 'date', 'modified' ) ) ) return false; @@ -4152,7 +4152,7 @@ function _get_last_post_time( $timezone, $field ) { $post_types = apply_filters( "get_lastpost{$field}_post_types", (array) $post_types ); - $key = "lastpost{$field}:$blog_id:$timezone:" . md5( serialize( $post_types ) ); + $key = "lastpost{$field}:" . get_current_blog_id() . ":$timezone:" . md5( serialize( $post_types ) ); $date = wp_cache_get( $key, 'timeinfo' ); diff --git a/wp-includes/user.php b/wp-includes/user.php index 0e0ca9ed6..97d42fde3 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -376,7 +376,7 @@ class WP_User_Query extends WP_Object_Query { $this->query_vars = wp_parse_args( $query, array( 'blog_id' => $GLOBALS['blog_id'], 'role' => '', - 'meta_key' => '', + 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'include' => array(), @@ -572,10 +572,8 @@ function get_users( $args = array() ) { * @return array List of users that are part of that Blog ID */ function get_users_of_blog( $id = '' ) { - global $blog_id; - if ( empty( $id ) ) - $id = (int) $blog_id; + $id = get_current_blog_id(); return get_users( array( 'blog_id' => $id ) ); } @@ -593,7 +591,7 @@ function get_blogs_of_user( $id, $all = false ) { global $wpdb; if ( !is_multisite() ) { - global $blog_id; + $blog_id = get_current_blog_id(); $blogs = array(); $blogs[ $blog_id ]->userblog_id = $blog_id; $blogs[ $blog_id ]->blogname = get_option('blogname'); @@ -757,10 +755,10 @@ function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { * @return array Includes a grand total and an array of counts indexed by role strings. */ function count_users($strategy = 'time') { - global $wpdb, $blog_id, $wp_roles; + global $wpdb, $wp_roles; // Initialize - $id = (int) $blog_id; + $id = get_current_blog_id(); $blog_prefix = $wpdb->get_blog_prefix($id); $result = array();