Make WordPress Core

Ticket #41684: 41684.2.patch

File 41684.2.patch, 11.3 KB (added by spacedmonkey, 8 years ago)
  • src/wp-admin/includes/upgrade.php

     
    432432                upgrade_network();
    433433        wp_cache_flush();
    434434
     435        $site_id = get_current_blog_id();
     436
    435437        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 ) );
    438440                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() ) );
    440442        }
    441443
    442444        /**
     
    12571259                        }
    12581260                        $start += 20;
    12591261                }
    1260                 refresh_blog_details( $wpdb->blogid );
     1262                refresh_blog_details( get_current_blog_id() );
    12611263        }
    12621264}
    12631265
  • src/wp-admin/ms-delete-site.php

     
    1717
    1818if ( isset( $_GET['h'] ) && $_GET['h'] != '' && get_option( 'delete_blog_hash' ) != false ) {
    1919        if ( hash_equals( get_option( 'delete_blog_hash' ), $_GET['h'] ) ) {
    20                 wpmu_delete_blog( $wpdb->blogid );
     20                wpmu_delete_blog( get_current_blog_id() );
    2121                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 ) );
    2222        } else {
    2323                wp_die( __( "I'm sorry, the link you clicked is stale. Please select another option." ) );
  • src/wp-admin/user-new.php

     
    156156                                add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email
    157157                                add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email
    158158                        }
    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'] ) );
    160160                        if ( isset( $_POST[ 'noconfirmation' ] ) && current_user_can( 'manage_network_users' ) ) {
    161161                                $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 ) );
    162162                                $new_user = wpmu_activate_signup( $key );
  • src/wp-includes/ms-blogs.php

     
    1212 * Update the last_updated field for the current site.
    1313 *
    1414 * @since MU (3.0.0)
    15  *
    16  * @global wpdb $wpdb WordPress database abstraction object.
    1715 */
    1816function wpmu_update_blogs_date() {
    19         global $wpdb;
    2017
    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 ) ) );
    2221        /**
    2322         * Fires after the blog details are updated.
    2423         *
     
    2625         *
    2726         * @param int $blog_id Site ID.
    2827         */
    29         do_action( 'wpmu_blog_updated', $wpdb->blogid );
     28        do_action( 'wpmu_blog_updated', $site_id );
    3029}
    3130
    3231/**
  • src/wp-includes/ms-default-constants.php

     
    1414 * wp-includes/ms-files.php (wp-content/blogs.php in MU).
    1515 *
    1616 * @since 3.0.0
    17  *
    18  * @global wpdb $wpdb WordPress database abstraction object.
    1917 */
    2018function ms_upload_constants() {
    21         global $wpdb;
    2219
    2320        // This filter is attached in ms-default-filters.php but that file is not included during SHORTINIT.
    2421        add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
     
    3027        if ( !defined( 'UPLOADBLOGSDIR' ) )
    3128                define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' );
    3229
     30        $site_id = get_current_blog_id();
    3331        // Note, the main site in a post-MU network uses wp-content/uploads.
    3432        // This is handled in wp_upload_dir() by ignoring UPLOADS for this case.
    3533        if ( ! defined( 'UPLOADS' ) ) {
    36                 define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" );
     34                define( 'UPLOADS', UPLOADBLOGSDIR . '/' . $site_id . '/files/' );
    3735
    3836                // Uploads dir relative to ABSPATH
    3937                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/' );
    4139        }
    4240}
    4341
  • src/wp-includes/ms-functions.php

     
    3434 *
    3535 * @since MU (3.0.0) 1.0
    3636 *
    37  * @global wpdb $wpdb WordPress database abstraction object.
    38  *
    3937 * @param int $user_id The unique ID of the user
    4038 * @return WP_Site|void The blog object
    4139 */
    4240function get_active_blog_for_user( $user_id ) {
    43         global $wpdb;
    4441        $blogs = get_blogs_of_user( $user_id );
    4542        if ( empty( $blogs ) )
    4643                return;
    4744
    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        }
    5049
    5150        $primary_blog = get_user_meta( $user_id, 'primary_blog', true );
    5251        $first_blog = current($blogs);
     
    22152214
    22162215        $current_user = wp_get_current_user();
    22172216        if ( $blog_id == 0 ) {
    2218                 $blog_id = $wpdb->blogid;
     2217                $blog_id = get_current_blog_id();
    22192218        }
    22202219        $local_key = $wpdb->get_blog_prefix( $blog_id ) . $key;
    22212220
  • tests/phpunit/tests/multisite/getMainSiteId.php

     
    1 <?php
    2 
    3 if ( is_multisite() ) :
    4 
    5 /**
    6  * Tests for the get_main_site_id() function.
    7  *
    8  * @group ms-site
    9  * @group multisite
    10  */
    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 29684
    55          */
    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 29684
    62          */
    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 29684
    76          */
    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 29684
    83          */
    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 29684
    90          */
    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 29684
    97          */
    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

     
    363363                wpmu_update_blogs_date();
    364364
    365365                // 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() );
    367367                $current_time = time();
    368368                $time_difference = $current_time - strtotime( $blog->last_updated );
    369369                $this->assertLessThan( 2, $time_difference );
  • tests/phpunit/tests/user/multisite.php

     
    120120                wp_set_current_user( $user1_id );
    121121
    122122                $this->assertTrue( is_blog_user() );
    123                 $this->assertTrue( is_blog_user( $wpdb->blogid ) );
     123                $this->assertTrue( is_blog_user( get_current_blog_id() ) );
    124124
    125125                $blog_ids = array();
    126126
     
    149149                $this->assertFalse( is_user_member_of_blog() );
    150150
    151151                wp_set_current_user( $user1_id );
     152                $site_id = get_current_blog_id();
    152153
    153154                $this->assertTrue( is_user_member_of_blog() );
    154155                $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 ) );
    156157                $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 ) );
    158159
    159160                $blog_ids = self::factory()->blog->create_many( 1 );
    160161                foreach ( $blog_ids as $blog_id ) {