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
+4 -2
View File
@@ -69,9 +69,11 @@ function wp_insert_site( array $data ) {
return new WP_Error( 'db_insert_error', __( 'Could not insert site into the database.' ), $wpdb->last_error );
}
clean_blog_cache( $wpdb->insert_id );
$site_id = (int) $wpdb->insert_id;
$new_site = get_site( $wpdb->insert_id );
clean_blog_cache( $site_id );
$new_site = get_site( $site_id );
if ( ! $new_site ) {
return new WP_Error( 'get_site_error', __( 'Could not retrieve site data.' ) );