WordPress.org

Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#20645 closed defect (bug) (fixed)

'delete_term' action doesn't pass the deleted term object

Reported by: bigdawggi Owned by: ryan
Milestone: 3.5 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

The 'delete_term' action passes 3 params ($term, $tt_id, $taxonomy), just like the 'create_term' action. The issue is that the $term passed to 'delete_term' is not a term object, but instead the term ID; and the issue with that, is there's no longer a way to have anything that hooks on this 'delete_term' action reference information about the term while it was still around.

My use case:

I hooked on 'create_term' to perform actions based on the properties of the $term object. On 'delete_term' I needed to access those properties to perform respective actions counting on $term to be an object (as mentioned in the DocBlock)

 * @uses do_action() Calls both 'delete_term' and 'delete_$taxonomy' action
 *	hooks, passing term object, term id. 'delete_term' gets an additional
 *	parameter with the $taxonomy parameter.

The $term passed to 'delete_term' action was not an object, but instead the ID for the term (which doesn't help b/c the term's deleted and I can't look it up anymore at the point of the action).

The attached patch stores the deleted $term object prior to the actual deletion of the term, and passes it through to the following actions so they can utilize the old properties of the term. (e.g., slug, name, etc.).

Attachments (2)

delete_term-action.diff (970 bytes) - added by bigdawggi 7 years ago.
delete_term-action-as-extra-parameter.diff (984 bytes) - added by bigdawggi 7 years ago.
passing term as extra parameter

Download all attachments as: .zip

Change History (10)

#1 @bigdawggi
7 years ago

Correction, the 'created_term' action passes the term ID as the first parameter -- not the object.

I still think that we should pass the term object to the 'delete_term' action, since the actions hooking on that cannot look up the term any more and we may as well pass the object that has more information about the term around.

Open to suggestions...

#2 follow-up: @SergeyBiryukov
7 years ago

In order to keep backwards compatibility, $deleted_term should be added as a new parameter rather than replace an existing one.

@bigdawggi
7 years ago

passing term as extra parameter

#3 in reply to: ↑ 2 @bigdawggi
7 years ago

Replying to SergeyBiryukov:

In order to keep backwards compatibility, $deleted_term should be added as a new parameter rather than replace an existing one.

Added new patch for that. Thanks!

#4 @SergeyBiryukov
7 years ago

  • Component changed from General to Taxonomy
  • Keywords has-patch 3.5-early added
  • Milestone changed from Awaiting Review to Future Release

#5 follow-up: @bigdawggi
7 years ago

Can this be reviewed to put into the next minor release instead of 3.5?

#6 in reply to: ↑ 5 @SergeyBiryukov
7 years ago

  • Keywords 3.5-early removed
  • Milestone changed from Future Release to 3.5

Replying to bigdawggi:

Can this be reviewed to put into the next minor release instead of 3.5?

No, minor releases are for security and regression fixes only.

#7 @ryan
7 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [21939]:

Pass a term object to the delete_term actions. Props bigdawggi. fixes #20645

Note: See TracTickets for help on using tickets.