Make WordPress Core

Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#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's profile mboynes Owned by: johnbillion's profile 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)

55441.diff (7.9 KB) - added by mboynes 2 years ago.
Adds $args to all actions/filters in wp_insert_term and wp_update_term

Download all attachments as: .zip

Change History (11)

#1 @SergeyBiryukov
2 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

Hi there, thanks for the ticket! I think passing $args to these filters makes sense.

@mboynes
2 years ago

Adds $args to all actions/filters in wp_insert_term and wp_update_term

#2 @mboynes
2 years ago

  • Keywords has-patch added; needs-patch removed

#3 @johnbillion
2 years ago

  • Milestone changed from Future Release to 6.1
  • Owner set to johnbillion
  • Status changed from new to reviewing

#4 @johnbillion
2 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 53627:

Taxonomy: Pass the $args parameter to all actions and filters in wp_insert_term() and wp_update_term().

This allows actions and filters to access potentially useful contextual information when terms are inserted and updated.

Props mboynes

Fixes #55441

#5 @SergeyBiryukov
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?

Last edited 2 years ago by SergeyBiryukov (previous) (diff)

#6 @mboynes
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 @JeffPaul
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.

#9 @johnbillion
2 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 54266:

Taxonomy: Standardise the format used to describe arguments passed to actions and filters inside wp_insert_term() and wp_update_term().

Props SergeyBiryukov, mboynes

Fixes #55441

#10 @milana_cap
2 years ago

  • Keywords add-to-field-guide added
Note: See TracTickets for help on using tickets.