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.

git-svn-id: https://develop.svn.wordpress.org/trunk@47932 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2020-06-09 12:39:09 +00:00
parent eb1c55a7ac
commit 65f22692bb
2 changed files with 30 additions and 2 deletions
+26
View File
@@ -1386,6 +1386,32 @@ if ( is_multisite() ) :
);
}
/**
* @ticket 50324
*/
public function test_wp_insert_site_with_clean_site_cache() {
remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 );
add_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
$site_id = wp_insert_site(
array(
'domain' => 'valid-domain.com',
'path' => '/valid-path/',
'network_id' => 1,
)
);
remove_action( 'clean_site_cache', array( $this, 'action_database_insert_on_clean_site_cache' ) );
$this->assertInternalType( 'integer', $site_id );
}
public function action_database_insert_on_clean_site_cache() {
update_site_option( 'database_write_test.' . time(), true );
}
/**
* @ticket 40364
*/