Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#33485 closed defect (bug) (fixed)

$deleted_term in wp_delete_term() has incorrect `count` value

Reported by: danielbachhuber's profile danielbachhuber Owned by: nicholas_io's profile nicholas_io
Milestone: 4.4 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords: good-first-bug has-patch
Focuses: Cc:

Description

It's assigned after all of the term relationships are removed. When accessing it through the delete_term action, I'd expect it to persist the original count.

Attachments (1)

33485-with-tests.patch (2.6 KB) - added by nicholas_io 10 years ago.
A Patch to fix the expected behavior

Download all attachments as: .zip

Change History (12)

#1 @boonebgorges
10 years ago

  • Keywords good-first-bug added; dev-feedback removed

Yeah, it hardly seems worth passing count if it's always 0. At the very least, I'd expect 'delete_term_taxonomy' to get the pre-delete count.

#2 follow-up: @nicholas_io
10 years ago

@boonebgorges, Do you mean to pass a count parameter to the delete_term_taxonomy action? I checked the source code and I saw that delete_term_taxonomy only receives the term_id.

#3 in reply to: ↑ 2 ; follow-up: @boonebgorges
10 years ago

Replying to nicholas_io:

@boonebgorges, Do you mean to pass a count parameter to the delete_term_taxonomy action? I checked the source code and I saw that delete_term_taxonomy only receives the term_id.

No, I mean that the $deleted_term variable should be initialized before its term relationships are deleted. That way, $deleted_term->count will reflect the pre-delete state of the term. I assume that you can just switch the blocks of code around, but this needs testing (and possibly a unit test).

#4 in reply to: ↑ 3 @nicholas_io
10 years ago

Replying to boonebgorges:

Replying to nicholas_io:

@boonebgorges, Do you mean to pass a count parameter to the delete_term_taxonomy action? I checked the source code and I saw that delete_term_taxonomy only receives the term_id.

No, I mean that the $deleted_term variable should be initialized before its term relationships are deleted. That way, $deleted_term->count will reflect the pre-delete state of the term. I assume that you can just switch the blocks of code around, but this needs testing (and possibly a unit test).

Ok, I got it, I'll try to make patch.

#5 @netweb
10 years ago

  • Owner set to nicholas_io
  • Status changed from new to assigned

@nicholas_io
10 years ago

A Patch to fix the expected behavior

#6 @nicholas_io
10 years ago

  • Keywords has-patch added; needs-patch removed

#7 follow-up: @boonebgorges
10 years ago

  • Milestone changed from Future Release to 4.4

Thanks, nicholas_io! Patch looks good. I'm going to reconfigure the unit test a little bit to (a) make it compatible with PHP 5.2, and (b) keep the assertions in the scope of the main test method rather than the 'wp_delete_term' callback (which is how we do it elsewhere in the test suite).

#8 @boonebgorges
10 years ago

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

In 33711:

In wp_delete_term(), the $deleted_term object passed to filters should be generated before term relationships are deleted.

This allows the count property to reflect the pre-delete state of affairs,
rather than always being 0.

Props nicholas_io.
Fixes #33485.

#9 in reply to: ↑ 7 ; follow-up: @nicholas_io
10 years ago

Replying to boonebgorges:

Thanks, nicholas_io! Patch looks good. I'm going to reconfigure the unit test a little bit to (a) make it compatible with PHP 5.2, and (b) keep the assertions in the scope of the main test method rather than the 'wp_delete_term' callback (which is how we do it elsewhere in the test suite).

Great, I was in doubt about how do test inside callbacks, now I understood how is done.

#10 in reply to: ↑ 9 ; follow-up: @boonebgorges
10 years ago

Replying to nicholas_io:

Replying to boonebgorges:

Thanks, nicholas_io! Patch looks good. I'm going to reconfigure the unit test a little bit to (a) make it compatible with PHP 5.2, and (b) keep the assertions in the scope of the main test method rather than the 'wp_delete_term' callback (which is how we do it elsewhere in the test suite).

Great, I was in doubt about how do test inside callbacks, now I understood how is done.

Your technique was good too, I'm just trying to be consistent :) Thanks again for the patch!

#11 in reply to: ↑ 10 @nicholas_io
10 years ago

Replying to boonebgorges:

Replying to nicholas_io:

Replying to boonebgorges:

Thanks, nicholas_io! Patch looks good. I'm going to reconfigure the unit test a little bit to (a) make it compatible with PHP 5.2, and (b) keep the assertions in the scope of the main test method rather than the 'wp_delete_term' callback (which is how we do it elsewhere in the test suite).

Great, I was in doubt about how do test inside callbacks, now I understood how is done.

Your technique was good too, I'm just trying to be consistent :) Thanks again for the patch!

All good! No problem :)

Note: See TracTickets for help on using tickets.