Ticket #21459: 21459.3.diff
File 21459.3.diff, 12.0 KB (added by , 12 years ago) |
---|
-
wp-includes/admin-bar.php
344 344 $blue_wp_logo_url = includes_url('images/wpmini-blue.png'); 345 345 346 346 foreach ( (array) $wp_admin_bar->user->blogs as $blog ) { 347 // @todo Replace with some favicon lookup.348 //$blavatar = '<img src="' . esc_url( blavatar_url( blavatar_domain( $blog->siteurl ), 'img', 16, $blue_wp_logo_url ) ) . '" alt="Blavatar" width="16" height="16" />'; 347 switch_to_blog( $blog->userblog_id ); 348 349 349 $blavatar = '<img src="' . esc_url($blue_wp_logo_url) . '" alt="' . esc_attr__( 'Blavatar' ) . '" width="16" height="16" class="blavatar"/>'; 350 350 351 351 $blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname; … … 355 355 'parent' => 'my-sites-list', 356 356 'id' => $menu_id, 357 357 'title' => $blavatar . $blogname, 358 'href' => get_admin_url( $blog->userblog_id),358 'href' => admin_url(), 359 359 ) ); 360 360 361 361 $wp_admin_bar->add_menu( array( 362 362 'parent' => $menu_id, 363 363 'id' => $menu_id . '-d', 364 364 'title' => __( 'Dashboard' ), 365 'href' => get_admin_url( $blog->userblog_id),365 'href' => admin_url(), 366 366 ) ); 367 367 368 if ( current_user_can _for_blog( $blog->userblog_id,'edit_posts' ) ) {368 if ( current_user_can( 'edit_posts' ) ) { 369 369 $wp_admin_bar->add_menu( array( 370 370 'parent' => $menu_id, 371 371 'id' => $menu_id . '-n', 372 372 'title' => __( 'New Post' ), 373 'href' => get_admin_url( $blog->userblog_id,'post-new.php' ),373 'href' => admin_url( 'post-new.php' ), 374 374 ) ); 375 375 $wp_admin_bar->add_menu( array( 376 376 'parent' => $menu_id, 377 377 'id' => $menu_id . '-c', 378 378 'title' => __( 'Manage Comments' ), 379 'href' => get_admin_url( $blog->userblog_id,'edit-comments.php' ),379 'href' => admin_url( 'edit-comments.php' ), 380 380 ) ); 381 381 } 382 382 … … 384 384 'parent' => $menu_id, 385 385 'id' => $menu_id . '-v', 386 386 'title' => __( 'Visit Site' ), 387 'href' => get_home_url( $blog->userblog_id,'/' ),387 'href' => home_url( '/' ), 388 388 ) ); 389 390 restore_current_blog(); 389 391 } 390 392 } 391 393 -
wp-includes/ms-blogs.php
325 325 * @since MU 326 326 * 327 327 * @param int $new_blog The id of the blog you want to switch to. Default: current blog 328 * @param bool $ validate Whether to check if $new_blog exists before proceeding328 * @param bool $deprecated Depecreated argument 329 329 * @return bool True on success, False if the validation failed 330 330 */ 331 function switch_to_blog( $new_blog, $ validate = false) {332 global $wpdb, $ table_prefix, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;331 function switch_to_blog( $new_blog, $deprecated = null ) { 332 global $wpdb, $wp_roles; 333 333 334 if ( empty( $new_blog) )335 $new_blog = $ blog_id;334 if ( empty( $new_blog ) ) 335 $new_blog = $GLOBALS['blog_id']; 336 336 337 if ( $validate && ! get_blog_details( $new_blog ) ) 338 return false; 337 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id']; 339 338 340 if ( empty($switched_stack) )341 $switched_stack = array();342 343 $switched_stack[] = $blog_id;344 345 339 /* If we're switching to the same blog id that we're on, 346 340 * set the right vars, do the associated actions, but skip 347 341 * the extra unnecessary work */ 348 if ( $ blog_id == $new_blog) {349 do_action( 'switch_blog', $ blog_id, $blog_id);350 $ switched= true;342 if ( $new_blog == $GLOBALS['blog_id'] ) { 343 do_action( 'switch_blog', $new_blog, $new_blog ); 344 $GLOBALS['_wp_switched'] = true; 351 345 return true; 352 346 } 353 347 354 $wpdb->set_blog_id( $new_blog);355 $ table_prefix= $wpdb->prefix;356 $prev_blog_id = $ blog_id;357 $ blog_id= $new_blog;348 $wpdb->set_blog_id( $new_blog ); 349 $GLOBALS['table_prefix'] = $wpdb->prefix; 350 $prev_blog_id = $GLOBALS['blog_id']; 351 $GLOBALS['blog_id'] = $new_blog; 358 352 359 if ( is_object( $wp_roles ) ) { 360 $wpdb->suppress_errors(); 361 if ( method_exists( $wp_roles ,'_init' ) ) 362 $wp_roles->_init(); 363 elseif ( method_exists( $wp_roles, '__construct' ) ) 364 $wp_roles->__construct(); 365 $wpdb->suppress_errors( false ); 366 } 367 368 if ( did_action('init') ) { 353 if ( did_action( 'init' ) ) { 354 $wp_roles->reinit(); 369 355 $current_user = wp_get_current_user(); 370 if ( is_object( $current_user ) ) 371 $current_user->for_blog( $blog_id ); 356 $current_user->for_blog( $new_blog ); 372 357 } 373 358 374 359 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 375 wp_cache_switch_to_blog( $ blog_id);360 wp_cache_switch_to_blog( $new_blog ); 376 361 } else { 362 global $wp_object_cache; 363 377 364 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 378 365 $global_groups = $wp_object_cache->global_groups; 379 366 else 380 367 $global_groups = false; 381 368 382 369 wp_cache_init(); 383 if ( function_exists('wp_cache_add_global_groups') ) { 370 371 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 384 372 if ( is_array( $global_groups ) ) 385 373 wp_cache_add_global_groups( $global_groups ); 386 374 else 387 375 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 388 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ));376 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 389 377 } 390 378 } 391 379 392 do_action('switch_blog', $blog_id, $prev_blog_id); 393 $switched = true; 380 do_action( 'switch_blog', $new_blog, $prev_blog_id ); 381 $GLOBALS['_wp_switched'] = true; 382 394 383 return true; 395 384 } 396 385 … … 403 392 * @return bool True on success, False if we're already on the current blog 404 393 */ 405 394 function restore_current_blog() { 406 global $ table_prefix, $wpdb, $blog_id, $switched, $switched_stack, $wp_roles, $wp_object_cache;395 global $wpdb, $wp_roles; 407 396 408 if ( ! $switched)397 if ( ! $GLOBALS['_wp_switched'] ) 409 398 return false; 410 399 411 if ( !is_array( $switched_stack ) ) 412 return false; 400 $blog = array_pop( $GLOBALS['_wp_switched_stack'] ); 413 401 414 $blog = array_pop( $switched_stack ); 415 if ( $blog_id == $blog ) { 402 if ( $GLOBALS['blog_id'] == $blog ) { 416 403 do_action( 'switch_blog', $blog, $blog ); 417 / * If we still have items in the switched stack, consider ourselves still 'switched' */418 $ switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0);404 // If we still have items in the switched stack, consider ourselves still 'switched' 405 $GLOBALS['_wp_switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 419 406 return true; 420 407 } 421 408 422 $wpdb->set_blog_id( $blog);423 $prev_blog_id = $ blog_id;424 $ blog_id= $blog;425 $ table_prefix= $wpdb->prefix;409 $wpdb->set_blog_id( $blog ); 410 $prev_blog_id = $GLOBALS['blog_id']; 411 $GLOBALS['blog_id'] = $blog; 412 $GLOBALS['table_prefix'] = $wpdb->prefix; 426 413 427 if ( is_object( $wp_roles ) ) { 428 $wpdb->suppress_errors(); 429 if ( method_exists( $wp_roles ,'_init' ) ) 430 $wp_roles->_init(); 431 elseif ( method_exists( $wp_roles, '__construct' ) ) 432 $wp_roles->__construct(); 433 $wpdb->suppress_errors( false ); 434 } 435 436 if ( did_action('init') ) { 414 if ( did_action( 'init' ) ) { 415 $wp_roles->reinit(); 437 416 $current_user = wp_get_current_user(); 438 if ( is_object( $current_user ) ) 439 $current_user->for_blog( $blog_id ); 417 $current_user->for_blog( $blog ); 440 418 } 441 419 442 420 if ( function_exists( 'wp_cache_switch_to_blog' ) ) { 443 wp_cache_switch_to_blog( $blog _id);421 wp_cache_switch_to_blog( $blog ); 444 422 } else { 423 global $wp_object_cache; 424 445 425 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) ) 446 426 $global_groups = $wp_object_cache->global_groups; 447 427 else 448 428 $global_groups = false; 449 429 450 430 wp_cache_init(); 451 if ( function_exists('wp_cache_add_global_groups') ) { 431 432 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 452 433 if ( is_array( $global_groups ) ) 453 434 wp_cache_add_global_groups( $global_groups ); 454 435 else 455 436 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 456 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ));437 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) ); 457 438 } 458 439 } 459 440 460 do_action( 'switch_blog', $blog_id, $prev_blog_id);441 do_action( 'switch_blog', $blog, $prev_blog_id ); 461 442 462 /* If we still have items in the switched stack, consider ourselves still 'switched' */ 463 $switched = ( is_array( $switched_stack ) && count( $switched_stack ) > 0 ); 443 // If we still have items in the switched stack, consider ourselves still 'switched' 444 $GLOBALS['_wp_switched'] = ! empty( $GLOBALS['_wp_switched_stack'] ); 445 464 446 return true; 465 447 } 466 448 -
wp-includes/capabilities.php
108 108 109 109 $this->role_objects = array(); 110 110 $this->role_names = array(); 111 foreach ( (array) $this->roles as $role => $data) {111 foreach ( array_keys( $this->roles ) as $role ) { 112 112 $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); 113 113 $this->role_names[$role] = $this->roles[$role]['name']; 114 114 } 115 115 } 116 116 117 117 /** 118 * Reinitialize the object 119 * 120 * Recreates the role objects. This is typically called only by switch_to_blog() 121 * after switching wpdb to a new blog ID. 122 * 123 * @since 3.5.0 124 * @access public 125 */ 126 function reinit() { 127 // There is no need to reinit if using the wp_user_roles global. 128 if ( ! $this->use_db ) 129 return; 130 131 global $wpdb, $wp_user_roles; 132 133 // Duplicated from _init() to avoid an extra function call. 134 $this->role_key = $wpdb->prefix . 'user_roles'; 135 $this->roles = get_option( $this->role_key ); 136 if ( empty( $this->roles ) ) 137 return; 138 139 $this->role_objects = array(); 140 $this->role_names = array(); 141 foreach ( array_keys( $this->roles ) as $role ) { 142 $this->role_objects[$role] = new WP_Role( $role, $this->roles[$role]['capabilities'] ); 143 $this->role_names[$role] = $this->roles[$role]['name']; 144 } 145 } 146 147 /** 118 148 * Add role name with capabilities to list. 119 149 * 120 150 * Updates the list of roles, if the role doesn't already exist. … … 233 263 * @param string $role Role name to look up. 234 264 * @return bool 235 265 */ 236 function is_role( $role ) 237 { 266 function is_role( $role ) { 238 267 return isset( $this->role_names[$role] ); 239 268 } 240 269 } … … 1231 1260 * @return bool 1232 1261 */ 1233 1262 function current_user_can_for_blog( $blog_id, $capability ) { 1263 switch_to_blog( $blog_id ); 1264 1234 1265 $current_user = wp_get_current_user(); 1235 1266 1236 1267 if ( empty( $current_user ) ) 1237 1268 return false; 1238 1269 1239 // Create new object to avoid stomping the global current_user.1240 $user = new WP_User( $current_user->ID );1241 1242 // Set the blog id. @todo add blog id arg to WP_User constructor?1243 $user->for_blog( $blog_id );1244 1245 1270 $args = array_slice( func_get_args(), 2 ); 1246 1271 $args = array_merge( array( $capability ), $args ); 1247 1272 1248 return call_user_func_array( array( &$user, 'has_cap' ), $args ); 1273 $can = call_user_func_array( array( $current_user, 'has_cap' ), $args ); 1274 1275 restore_current_blog(); 1276 1277 return $can; 1249 1278 } 1250 1279 1251 1280 /** -
wp-includes/ms-settings.php
126 126 $wpdb->set_prefix( $table_prefix, false ); // $table_prefix can be set in sunrise.php 127 127 $wpdb->set_blog_id( $current_blog->blog_id, $current_blog->site_id ); 128 128 $table_prefix = $wpdb->get_blog_prefix(); 129 $_wp_switched_stack = array(); 130 $_wp_switched = false; 129 131 130 132 // need to init cache again after blog_id is set 131 133 wp_start_object_cache(); -
wp-settings.php
252 252 */ 253 253 $GLOBALS['wp_widget_factory'] = new WP_Widget_Factory(); 254 254 255 /** 256 * WordPress User Roles 257 * @global object $wp_roles 258 * @since 2.0.0 259 */ 260 $GLOBALS['wp_roles'] = new WP_Roles(); 261 255 262 do_action( 'setup_theme' ); 256 263 257 264 // Define the template related constants.