From 866cfdf19b06c4362c7b53dad36990513fe8866a Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 14 Nov 2014 21:53:22 +0000 Subject: [PATCH] Flush cache for newly created term in `_split_shared_term()`. The term itself does not have any cached values yet, but in some cases the new term's taxonomy may need its cached hierarchy to be refreshed as a result of the term splitting. Props jorbin. See #30335. Built from https://develop.svn.wordpress.org/trunk@30347 git-svn-id: http://core.svn.wordpress.org/trunk@30346 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 17 +++++++++++------ wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index 79d04ae81f..fa450e5fea 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -4096,12 +4096,17 @@ function _split_shared_term( $term_id, $term_taxonomy_id ) { $term_taxonomy = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->term_taxonomy WHERE term_taxonomy_id = %d", $term_taxonomy_id ) ); $children_tt_ids = $wpdb->get_col( $wpdb->prepare( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE taxonomy = %s AND parent = %d", $term_taxonomy->taxonomy, $term_id ) ); - foreach ( $children_tt_ids as $child_tt_id ) { - $wpdb->update( $wpdb->term_taxonomy, - array( 'parent' => $new_term_id ), - array( 'term_taxonomy_id' => $child_tt_id ) - ); - clean_term_cache( $term_id, $term_taxonomy->taxonomy ); + if ( ! empty( $children_tt_ids ) ) { + foreach ( $children_tt_ids as $child_tt_id ) { + $wpdb->update( $wpdb->term_taxonomy, + array( 'parent' => $new_term_id ), + array( 'term_taxonomy_id' => $child_tt_id ) + ); + clean_term_cache( $term_id, $term_taxonomy->taxonomy ); + } + } 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 the cache for term taxonomies formerly shared with the current term. diff --git a/wp-includes/version.php b/wp-includes/version.php index 3280838ad4..922ca6f605 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30346'; +$wp_version = '4.1-alpha-30347'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.