Make WordPress Core

Changeset 47932


Ignore:
Timestamp:
06/09/2020 12:39:09 PM (20 months ago)
Author:
SergeyBiryukov
Message:

Networks and Sites: Ensure the site ID in wp_insert_site() is still correct after calling clean_blog_cache().

By saving $wpdb->insert_id to a variable, we make sure the ID does not change if another database insert is performed on the clean_site_cache action.

Props trepmal.
Fixes #50324.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/ms-site.php

    r47611 r47932  
    7070    }
    7171
    72     clean_blog_cache( $wpdb->insert_id );
    73 
    74     $new_site = get_site( $wpdb->insert_id );
     72    $site_id = (int) $wpdb->insert_id;
     73
     74    clean_blog_cache( $site_id );
     75
     76    $new_site = get_site( $site_id );
    7577
    7678    if ( ! $new_site ) {
  • trunk/tests/phpunit/tests/multisite/site.php

    r47318 r47932  
    13881388
    13891389        /**
     1390         * @ticket 50324
     1391         */
     1392        public function test_wp_insert_site_with_clean_site_cache() {
     1393            remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
     1394
     1395            add_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
     1396
     1397            $site_id = wp_insert_site(
     1398                array(
     1399                    'domain'     => 'valid-domain.com',
     1400                    'path'       => '/valid-path/',
     1401                    'network_id' => 1,
     1402                )
     1403            );
     1404
     1405            remove_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
     1406
     1407            $this->assertInternalType( 'integer', $site_id );
     1408
     1409        }
     1410
     1411        public function action_database_insert_on_clean_site_cache() {
     1412            update_site_option( 'database_write_test.' . time(), true );
     1413        }
     1414
     1415        /**
    13901416         * @ticket 40364
    13911417         */
Note: See TracChangeset for help on using the changeset viewer.