Opened 12 months ago
Last modified 3 months ago
#60532 new enhancement
Add a `pre_set_object_terms` action
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 6.5 |
Component: | Taxonomy | Keywords: | good-first-bug has-patch |
Focuses: | Cc: |
Description
Working with some custom terms & taxonomies, and it looks like there's no way to hook in to wp_set_object_terms
_before_ the terms are updated.
In the end, the $old_tt_ids
is passed to the set_object_terms
action(added in r12261). But, these are the term_taxonomy_id
s and a a bit harder to work with than the plain terms. Also, these are provided _after_ the terms are updated. So, there's no way to short-circuit the updating.
However, I think it would be useful to have a pre_
action that can work on the current terms before commiting the changes.
Attachments (1)
Change History (7)
This ticket was mentioned in PR #7660 on WordPress/wordpress-develop by @geekofshire.
3 months ago
#3
This PR introduces a new pre_set_object_terms action that triggers before terms are assigned to an object in wp_set_object_terms. Currently, it is only possible to access term taxonomy IDs ($old_tt_ids) after terms have already been updated, which limits the ability to make adjustments prior to committing changes.
Trac ticket: https://core.trac.wordpress.org/ticket/60532
#5
follow-up:
↓ 6
@
3 months ago
@geekofshire @sagarsavani7979 Imho the position of the filter is broken as it is in the patch and PR. The position is too low, $object_id
is already used before to fill $old_tt_ids
. So under normal conditions $old_tt_ids
will have the wrong content if $append
is false
Also see: https://github.com/WordPress/wordpress-develop/pull/7660#discussion_r1820132363
#6
in reply to:
↑ 5
@
3 months ago
Replying to apermo:
@geekofshire @sagarsavani7979 Imho the position of the filter is broken as it is in the patch and PR. The position is too low,
$object_id
is already used before to fill$old_tt_ids
. So under normal conditions$old_tt_ids
will have the wrong content if$append
isfalse
Also see: https://github.com/WordPress/wordpress-develop/pull/7660#discussion_r1820132363
Thank you for the feedback! I’ve made adjustments based on your comments.
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.