Make WordPress Core

Ticket #60532: 60532.patch

File 60532.patch, 866 bytes (added by sagarsavani7979, 3 months ago)

This commit adds a new action hook, 'pre_set_object_terms', to the wp_set_object_terms function. This hook fires before an object's terms are set, allowing developers to perform operations or modifications on the terms array before the changes are committed.

  • src/wp-includes/taxonomy.php

    diff --git a/src/wp-includes/taxonomy.php b/src/wp-includes/taxonomy.php
    index 85ca5c30da..64fc4fcfb6 100644
    a b function wp_set_object_terms( $object_id, $terms, $taxonomy, $append = false ) { 
    28172817                $old_tt_ids = array();
    28182818        }
    28192819
     2820        /**
     2821         * Fires before an object's terms are set.
     2822         *
     2823         * @since 6.4.1
     2824         *
     2825         * @param int    $object_id  Object ID.
     2826         * @param array  $terms      An array of object term IDs or slugs.
     2827         * @param string $taxonomy   Taxonomy slug.
     2828         * @param bool   $append     Whether to append new terms to the old terms.
     2829         * @param array  $old_tt_ids Old array of term taxonomy IDs.
     2830         */
     2831        do_action( 'pre_set_object_terms', $object_id, $terms, $taxonomy, $append, $old_tt_ids );
     2832
    28202833        $tt_ids     = array();
    28212834        $term_ids   = array();
    28222835        $new_tt_ids = array();