mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-15 15:16:29 +01:00
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
This commit is contained in:
parent
9e0f434726
commit
8c72912432
@ -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.
|
// Get the term before deleting it or its term relationships so we can pass to actions below.
|
||||||
$deleted_term = get_term( $term, $taxonomy );
|
$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 ) {
|
foreach ( $object_ids as $object_id ) {
|
||||||
$terms = wp_get_object_terms($object, $taxonomy, array('fields' => 'ids', 'orderby' => 'none'));
|
$terms = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids', 'orderby' => 'none' ) );
|
||||||
if ( 1 == count($terms) && isset($default) ) {
|
if ( 1 == count($terms) && isset($default) ) {
|
||||||
$terms = array($default);
|
$terms = array($default);
|
||||||
} else {
|
} else {
|
||||||
@ -2170,13 +2170,13 @@ function wp_delete_term( $term, $taxonomy, $args = array() ) {
|
|||||||
$terms = array_merge($terms, array($default));
|
$terms = array_merge($terms, array($default));
|
||||||
}
|
}
|
||||||
$terms = array_map('intval', $terms);
|
$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.
|
// Clean the relationship caches for all object types using this term.
|
||||||
$tax_object = get_taxonomy( $taxonomy );
|
$tax_object = get_taxonomy( $taxonomy );
|
||||||
foreach ( $tax_object->object_type as $object_type )
|
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 ) );
|
$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 ) {
|
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.
|
* Fires after a term is deleted from the database and the cache is cleaned.
|
||||||
*
|
*
|
||||||
* @since 2.5.0
|
* @since 2.5.0
|
||||||
|
* @since 4.5.0 Introduced `$object_ids` argument.
|
||||||
*
|
*
|
||||||
* @param int $term Term ID.
|
* @param int $term Term ID.
|
||||||
* @param int $tt_id Term taxonomy ID.
|
* @param int $tt_id Term taxonomy ID.
|
||||||
* @param string $taxonomy Taxonomy slug.
|
* @param string $taxonomy Taxonomy slug.
|
||||||
* @param mixed $deleted_term Copy of the already-deleted term, in the form specified
|
* @param mixed $deleted_term Copy of the already-deleted term, in the form specified
|
||||||
* by the parent function. WP_Error otherwise.
|
* 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.
|
* 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.
|
* taxonomy the term belonged to.
|
||||||
*
|
*
|
||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
|
* @since 4.5.0 Introduced `$object_ids` argument.
|
||||||
*
|
*
|
||||||
* @param int $term Term ID.
|
* @param int $term Term ID.
|
||||||
* @param int $tt_id Term taxonomy ID.
|
* @param int $tt_id Term taxonomy ID.
|
||||||
* @param mixed $deleted_term Copy of the already-deleted term, in the form specified
|
* @param mixed $deleted_term Copy of the already-deleted term, in the form specified
|
||||||
* by the parent function. WP_Error otherwise.
|
* 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user