From 8c72912432bd0871450c573c3f0414b3463f08f9 Mon Sep 17 00:00:00 2001 From: Konstantin Obenland Date: Wed, 23 Dec 2015 23:44:26 +0000 Subject: [PATCH] Taxonomy: Pass object ids to delete_* actions. Allows for more targeted updates to affected posts in callbacks. Disambiguates `$objects` variable and amends unit tests. Fixes #35213. Built from https://develop.svn.wordpress.org/trunk@36080 git-svn-id: http://core.svn.wordpress.org/trunk@36045 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/taxonomy.php | 18 +++++++++++------- wp-includes/version.php | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wp-includes/taxonomy.php b/wp-includes/taxonomy.php index aea48ca297..8cbef3c718 100644 --- a/wp-includes/taxonomy.php +++ b/wp-includes/taxonomy.php @@ -2158,10 +2158,10 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { // Get the term before deleting it or its term relationships so we can pass to actions below. $deleted_term = get_term( $term, $taxonomy ); - $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) ); + $object_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) ); - foreach ( (array) $objects as $object ) { - $terms = wp_get_object_terms($object, $taxonomy, array('fields' => 'ids', 'orderby' => 'none')); + foreach ( $object_ids as $object_id ) { + $terms = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids', 'orderby' => 'none' ) ); if ( 1 == count($terms) && isset($default) ) { $terms = array($default); } else { @@ -2170,13 +2170,13 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { $terms = array_merge($terms, array($default)); } $terms = array_map('intval', $terms); - wp_set_object_terms($object, $terms, $taxonomy); + wp_set_object_terms( $object_id, $terms, $taxonomy ); } // Clean the relationship caches for all object types using this term. $tax_object = get_taxonomy( $taxonomy ); foreach ( $tax_object->object_type as $object_type ) - clean_object_term_cache( $objects, $object_type ); + clean_object_term_cache( $object_ids, $object_type ); $term_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE term_id = %d ", $term ) ); foreach ( $term_meta_ids as $mid ) { @@ -2212,14 +2212,16 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { * Fires after a term is deleted from the database and the cache is cleaned. * * @since 2.5.0 + * @since 4.5.0 Introduced `$object_ids` argument. * * @param int $term Term ID. * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. * @param mixed $deleted_term Copy of the already-deleted term, in the form specified * by the parent function. WP_Error otherwise. + * @param array $object_ids List of term object IDs. */ - do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); + do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term, $object_ids ); /** * Fires after a term in a specific taxonomy is deleted. @@ -2228,13 +2230,15 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) { * taxonomy the term belonged to. * * @since 2.3.0 + * @since 4.5.0 Introduced `$object_ids` argument. * * @param int $term Term ID. * @param int $tt_id Term taxonomy ID. * @param mixed $deleted_term Copy of the already-deleted term, in the form specified * by the parent function. WP_Error otherwise. + * @param array $object_ids List of term object IDs. */ - do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term ); + do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term, $object_ids ); return true; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 4561e005ee..650b25e74d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36079'; +$wp_version = '4.5-alpha-36080'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.