diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 484d26ebbc..f703b5a56b 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -3548,19 +3548,27 @@ function _split_shared_term( $term_id, $term_taxonomy_id, $record = true ) { array( 'parent' => $new_term_id ), array( 'term_taxonomy_id' => $child_tt_id ) ); - clean_term_cache( $term_id, $term_taxonomy->taxonomy ); + clean_term_cache( (int) $child_tt_id, '', false ); } } else { // If the term has no children, we must force its taxonomy cache to be rebuilt separately. - clean_term_cache( $new_term_id, $term_taxonomy->taxonomy ); + clean_term_cache( $new_term_id, $term_taxonomy->taxonomy, false ); } + clean_term_cache( $term_id, $term_taxonomy->taxonomy, false ); + + /* + * Taxonomy cache clearing is delayed to avoid race conditions that may occur when + * regenerating the taxonomy's hierarchy tree. + */ + $taxonomies_to_clean = array( $term_taxonomy->taxonomy ); + // Clean the cache for term taxonomies formerly shared with the current term. - $shared_term_taxonomies = $wpdb->get_row( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) ); - if ( $shared_term_taxonomies ) { - foreach ( $shared_term_taxonomies as $shared_term_taxonomy ) { - clean_term_cache( $term_id, $shared_term_taxonomy ); - } + $shared_term_taxonomies = $wpdb->get_col( $wpdb->prepare( "SELECT taxonomy FROM $wpdb->term_taxonomy WHERE term_id = %d", $term_id ) ); + $taxonomies_to_clean = array_merge( $taxonomies_to_clean, $shared_term_taxonomies ); + + foreach ( $taxonomies_to_clean as $taxonomy_to_clean ) { + clean_taxonomy_cache( $taxonomy_to_clean ); } // Keep a record of term_ids that have been split, keyed by old term_id. See wp_get_split_term(). diff --git a/wp-includes/version.php b/wp-includes/version.php index 53969d5b73..c3f8190348 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9-alpha-40919'; +$wp_version = '4.9-alpha-40920'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.