Make WordPress Core


Ignore:
Timestamp:
12/23/2015 11:43:03 PM (9 years ago)
Author:
obenland
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/taxonomy.php

    r36076 r36080  
    21592159    $deleted_term = get_term( $term, $taxonomy );
    21602160
    2161     $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
    2162 
    2163     foreach ( (array) $objects as $object ) {
    2164         $terms = wp_get_object_terms($object, $taxonomy, array('fields' => 'ids', 'orderby' => 'none'));
     2161    $object_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) );
     2162
     2163    foreach ( $object_ids as $object_id ) {
     2164        $terms = wp_get_object_terms( $object_id, $taxonomy, array( 'fields' => 'ids', 'orderby' => 'none' ) );
    21652165        if ( 1 == count($terms) && isset($default) ) {
    21662166            $terms = array($default);
     
    21712171        }
    21722172        $terms = array_map('intval', $terms);
    2173         wp_set_object_terms($object, $terms, $taxonomy);
     2173        wp_set_object_terms( $object_id, $terms, $taxonomy );
    21742174    }
    21752175
     
    21772177    $tax_object = get_taxonomy( $taxonomy );
    21782178    foreach ( $tax_object->object_type as $object_type )
    2179         clean_object_term_cache( $objects, $object_type );
     2179        clean_object_term_cache( $object_ids, $object_type );
    21802180
    21812181    $term_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->termmeta WHERE term_id = %d ", $term ) );
     
    22132213     *
    22142214     * @since 2.5.0
     2215     * @since 4.5.0 Introduced `$object_ids` argument.
    22152216     *
    22162217     * @param int     $term         Term ID.
     
    22192220     * @param mixed   $deleted_term Copy of the already-deleted term, in the form specified
    22202221     *                              by the parent function. WP_Error otherwise.
     2222     * @param array   $object_ids   List of term object IDs.
    22212223     */
    2222     do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term );
     2224    do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term, $object_ids );
    22232225
    22242226    /**
     
    22292231     *
    22302232     * @since 2.3.0
     2233     * @since 4.5.0 Introduced `$object_ids` argument.
    22312234     *
    22322235     * @param int     $term         Term ID.
     
    22342237     * @param mixed   $deleted_term Copy of the already-deleted term, in the form specified
    22352238     *                              by the parent function. WP_Error otherwise.
     2239     * @param array   $object_ids   List of term object IDs.
    22362240     */
    2237     do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term );
     2241    do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term, $object_ids );
    22382242
    22392243    return true;
Note: See TracChangeset for help on using the changeset viewer.