#55441 closed task (blessed) (fixed)
In wp_insert_term, pass $args as an additional parameter to after-insert actions (create_term, created_term, et al)
Reported by: | mboynes | Owned by: | johnbillion |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Taxonomy | Keywords: | has-patch add-to-field-guide |
Focuses: | Cc: |
Description
@johnbillion reported an issue to Fieldmanager where it would save term meta to additional terms if any were added or updated as a side effect of adding/updating a term in the WordPress admin. Guarding against this when editing a term is simple since there's a term ID to check against, but I've had to jump through a few hoops to guard against this when creating new terms. Through this process I've come to realize that there's an opportunity for improvement to core. As it currently stands, when all of the actions fire in wp_insert_term() after the term is inserted, there's no way to guarantee that the action firing relates to a specific call of wp_insert_term()
. If the actions included the $args
array passed to that function, then a developer could use that information to target a specific call to wp_insert_term()
, especially when core calls it to insert a term from the canonical form in the WordPress admin (since it passes $_POST
wholesale as the $args
argument).
This would entail adding the argument to the following actions:
create_term
create_{$taxonomy}
created_term
created_{$taxonomy}
saved_term
saved_{$taxonomy}
If there's appetite for this update, I'm happy to submit a patch.
Attachments (1)
Change History (11)
#1
@
2 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#3
@
2 years ago
- Milestone changed from Future Release to 6.1
- Owner set to johnbillion
- Status changed from new to reviewing
#5
@
2 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
Minor nitpick: why is the $args
description different for actions in wp_insert_term()
vs. wp_update_term()
?
wp_insert_term()
: "Term arguments passed to the function."wp_update_term()
: "Arguments passed to wp_update_term()."
Could we use the same pattern for both?
#6
@
2 years ago
@SergeyBiryukov good question, I appreciate your observation. $args
was already documented in some filters (see here in wp_update_term() and here in wp_insert_term()), so I opted for consistency within each function over consistency within the patch. Having said that, I didn't notice at the time that there was also this param doc in wp_insert_term(), so my rationale just went out the window. Ultimately I agree with your vote for consistency, and would also support updating the docblock for wp_insert_term_duplicate_term_check
to match the other pattern.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
2 years ago
#8
@
2 years ago
- Type changed from enhancement to task (blessed)
As discussed ahead of today's scheduled 6.1 Beta 1 release party (see the Slack link above), it was deemed that this ticket was now a docs-only update and that @johnbillion would handle this so I'll convert to a task for it to get resolved here in the 6.1 cycle.
Hi there, thanks for the ticket! I think passing
$args
to these filters makes sense.