Ticket #41684: 41684.2.patch
File 41684.2.patch, 11.3 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/upgrade.php
432 432 upgrade_network(); 433 433 wp_cache_flush(); 434 434 435 $site_id = get_current_blog_id(); 436 435 437 if ( is_multisite() ) { 436 if ( $wpdb->get_row( "SELECT blog_id FROM {$wpdb->blog_versions} WHERE blog_id = '{$wpdb->blogid}'") )437 $wpdb->query( "UPDATE {$wpdb->blog_versions} SET db_version = '{$wp_db_version}' WHERE blog_id = '{$wpdb->blogid}'");438 if ( $wpdb->get_row( $wpdb->prepare( 'SELECT blog_id FROM %s WHERE blog_id = %d', $wpdb->blog_versions, $site_id ) ) ) 439 $wpdb->query( $wpdb->prepare( 'UPDATE %s SET db_version = %d WHERE blog_id = %d', $wpdb->blog_versions, $wp_db_version, $site_id ) ); 438 440 else 439 $wpdb->query( "INSERT INTO {$wpdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$wpdb->blogid}', '{$wp_db_version}', NOW());");441 $wpdb->query( $wpdb->prepare( 'INSERT INTO %s ( `blog_id` , `db_version` , `last_updated` ) VALUES ( %d, %d, %s);', $site_id, $wpdb->blog_versions, $wp_db_version, NOW() ) ); 440 442 } 441 443 442 444 /** … … 1257 1259 } 1258 1260 $start += 20; 1259 1261 } 1260 refresh_blog_details( $wpdb->blogid);1262 refresh_blog_details( get_current_blog_id() ); 1261 1263 } 1262 1264 } 1263 1265 -
src/wp-admin/ms-delete-site.php
17 17 18 18 if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) { 19 19 if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) { 20 wpmu_delete_blog( $wpdb->blogid);20 wpmu_delete_blog( get_current_blog_id() ); 21 21 wp_die( sprintf( __( 'Thank you for using %s, your site has been deleted. Happy trails to you until we meet again.' ), get_network()->site_name ) ); 22 22 } else { 23 23 wp_die( __( "I'm sorry, the link you clicked is stale. Please select another option." ) ); -
src/wp-admin/user-new.php
156 156 add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email 157 157 add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email 158 158 } 159 wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => $wpdb->blogid, 'new_role' => $_REQUEST['role'] ) );159 wpmu_signup_user( $new_user_login, $new_user_email, array( 'add_to_blog' => get_current_blog_id(), 'new_role' => $_REQUEST['role'] ) ); 160 160 if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) { 161 161 $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) ); 162 162 $new_user = wpmu_activate_signup( $key ); -
src/wp-includes/ms-blogs.php
12 12 * Update the last_updated field for the current site. 13 13 * 14 14 * @since MU (3.0.0) 15 *16 * @global wpdb $wpdb WordPress database abstraction object.17 15 */ 18 16 function wpmu_update_blogs_date() { 19 global $wpdb;20 17 21 update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) ); 18 $site_id = get_current_blog_id(); 19 20 update_blog_details( $site_id, array( 'last_updated' => current_time( 'mysql', true ) ) ); 22 21 /** 23 22 * Fires after the blog details are updated. 24 23 * … … 26 25 * 27 26 * @param int $blog_id Site ID. 28 27 */ 29 do_action( 'wpmu_blog_updated', $ wpdb->blogid );28 do_action( 'wpmu_blog_updated', $site_id ); 30 29 } 31 30 32 31 /** -
src/wp-includes/ms-default-constants.php
14 14 * wp-includes/ms-files.php (wp-content/blogs.php in MU). 15 15 * 16 16 * @since 3.0.0 17 *18 * @global wpdb $wpdb WordPress database abstraction object.19 17 */ 20 18 function ms_upload_constants() { 21 global $wpdb;22 19 23 20 // This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT. 24 21 add_filter( 'default_site_option_ms_files_rewriting', '__return_true' ); … … 30 27 if ( !defined( 'UPLOADBLOGSDIR' ) ) 31 28 define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' ); 32 29 30 $site_id = get_current_blog_id(); 33 31 // Note, the main site in a post-MU network uses wp-content/uploads. 34 32 // This is handled in wp_upload_dir() by ignoring UPLOADS for this case. 35 33 if ( ! defined( 'UPLOADS' ) ) { 36 define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/");34 define( 'UPLOADS', UPLOADBLOGSDIR . '/' . $site_id . '/files/' ); 37 35 38 36 // Uploads dir relative to ABSPATH 39 37 if ( 'wp-content/blogs.dir' == UPLOADBLOGSDIR && ! defined( 'BLOGUPLOADDIR' ) ) 40 define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . "/blogs.dir/{$wpdb->blogid}/files/");38 define( 'BLOGUPLOADDIR', WP_CONTENT_DIR . '/blogs.dir/' . $site_id . '/files/' ); 41 39 } 42 40 } 43 41 -
src/wp-includes/ms-functions.php
34 34 * 35 35 * @since MU (3.0.0) 1.0 36 36 * 37 * @global wpdb $wpdb WordPress database abstraction object.38 *39 37 * @param int $user_id The unique ID of the user 40 38 * @return WP_Site|void The blog object 41 39 */ 42 40 function get_active_blog_for_user( $user_id ) { 43 global $wpdb;44 41 $blogs = get_blogs_of_user( $user_id ); 45 42 if ( empty( $blogs ) ) 46 43 return; 47 44 48 if ( !is_multisite() ) 49 return $blogs[$wpdb->blogid]; 45 if ( ! is_multisite() ) { 46 $site_id = get_current_blog_id(); 47 return $blogs[ $site_id ]; 48 } 50 49 51 50 $primary_blog = get_user_meta( $user_id, 'primary_blog', true ); 52 51 $first_blog = current($blogs); … … 2215 2214 2216 2215 $current_user = wp_get_current_user(); 2217 2216 if ( $blog_id == 0 ) { 2218 $blog_id = $wpdb->blogid;2217 $blog_id = get_current_blog_id(); 2219 2218 } 2220 2219 $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key; 2221 2220 -
tests/phpunit/tests/multisite/getMainSiteId.php
1 <?php2 3 if ( is_multisite() ) :4 5 /**6 * Tests for the get_main_site_id() function.7 *8 * @group ms-site9 * @group multisite10 */11 class Tests_Multisite_Get_Main_Site_ID extends WP_UnitTestCase {12 protected static $network_ids;13 protected static $site_ids;14 15 public static function wpSetUpBeforeClass( $factory ) {16 self::$network_ids = array(17 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/' ),18 'wp.org/' => array( 'domain' => 'wp.org', 'path' => '/' ), // A network with no sites.19 );20 21 foreach ( self::$network_ids as &$id ) {22 $id = $factory->network->create( $id );23 }24 unset( $id );25 26 self::$site_ids = array(27 'www.w.org/' => array( 'domain' => 'www.w.org', 'path' => '/' ),28 'wordpress.org/' => array( 'domain' => 'wordpress.org', 'path' => '/', 'site_id' => self::$network_ids['wordpress.org/'] ),29 'wordpress.org/foo/' => array( 'domain' => 'wordpress.org', 'path' => '/foo/', 'site_id' => self::$network_ids['wordpress.org/'] ),30 );31 32 foreach ( self::$site_ids as &$id ) {33 $id = $factory->blog->create( $id );34 }35 unset( $id );36 }37 38 public static function wpTearDownAfterClass() {39 foreach( self::$site_ids as $id ) {40 wpmu_delete_blog( $id, true );41 }42 43 global $wpdb;44 45 foreach( self::$network_ids as $id ) {46 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id ) );47 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->site} WHERE id= %d", $id ) );48 }49 50 wp_update_network_site_counts();51 }52 53 /**54 * @ticket 2968455 */56 public function test_get_main_site_id_on_main_site_returns_self() {57 $this->assertSame( get_current_blog_id(), get_main_site_id() );58 }59 60 /**61 * @ticket 2968462 */63 public function test_get_main_site_id_returns_main_site_in_switched_context() {64 $main_site_id = get_current_blog_id();65 $other_site_id = self::$site_ids['www.w.org/'];66 67 switch_to_blog( $other_site_id );68 $result = get_main_site_id();69 restore_current_blog();70 71 $this->assertSame( $main_site_id, $result );72 }73 74 /**75 * @ticket 2968476 */77 public function test_get_main_site_id_with_different_network_returns_correct_id() {78 $this->assertSame( self::$site_ids['wordpress.org/'], get_main_site_id( self::$network_ids['wordpress.org/'] ) );79 }80 81 /**82 * @ticket 2968483 */84 public function test_get_main_site_id_on_network_without_site_returns_0() {85 $this->assertSame( 0, get_main_site_id( self::$network_ids['wp.org/'] ) );86 }87 88 /**89 * @ticket 2968490 */91 public function test_get_main_site_id_on_invalid_network_returns_0() {92 $this->assertSame( 0, get_main_site_id( 333 ) );93 }94 95 /**96 * @ticket 2968497 */98 public function test_get_main_site_id_filtered() {99 add_filter( 'pre_get_main_site_id', array( $this, 'filter_get_main_site_id' ) );100 $result = get_main_site_id();101 102 $this->assertSame( 333, $result );103 }104 105 public function filter_get_main_site_id() {106 return 333;107 }108 }109 110 endif; -
tests/phpunit/tests/multisite/site.php
363 363 wpmu_update_blogs_date(); 364 364 365 365 // compare the update time with the current time, allow delta < 2 366 $blog = get_site( $wpdb->blogid);366 $blog = get_site( get_current_blog_id() ); 367 367 $current_time = time(); 368 368 $time_difference = $current_time - strtotime( $blog->last_updated ); 369 369 $this->assertLessThan( 2, $time_difference ); -
tests/phpunit/tests/user/multisite.php
120 120 wp_set_current_user( $user1_id ); 121 121 122 122 $this->assertTrue( is_blog_user() ); 123 $this->assertTrue( is_blog_user( $wpdb->blogid) );123 $this->assertTrue( is_blog_user( get_current_blog_id() ) ); 124 124 125 125 $blog_ids = array(); 126 126 … … 149 149 $this->assertFalse( is_user_member_of_blog() ); 150 150 151 151 wp_set_current_user( $user1_id ); 152 $site_id = get_current_blog_id(); 152 153 153 154 $this->assertTrue( is_user_member_of_blog() ); 154 155 $this->assertTrue( is_user_member_of_blog( 0, 0 ) ); 155 $this->assertTrue( is_user_member_of_blog( 0, $ wpdb->blogid ) );156 $this->assertTrue( is_user_member_of_blog( 0, $site_id ) ); 156 157 $this->assertTrue( is_user_member_of_blog( $user1_id ) ); 157 $this->assertTrue( is_user_member_of_blog( $user1_id, $ wpdb->blogid ) );158 $this->assertTrue( is_user_member_of_blog( $user1_id, $site_id ) ); 158 159 159 160 $blog_ids = self::factory()->blog->create_many( 1 ); 160 161 foreach ( $blog_ids as $blog_id ) {