Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 13 years ago

#18044 closed defect (bug) (invalid)

`delete_post` hook has off-by-1 error in `$postid` parameter

Reported by: meitar's profile meitar Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2
Component: Plugins Keywords:
Focuses: Cc:


In WordPress 3.2, the delete_post hook seems to be passed the incorrect post ID. Specifically, if a post's ID is 5, then the functioned called by the delete_post hook is passed an integer value of 6, contradicting $_GET['post'] (of a string value of 5, in this example).

Attached to this ticket is a very crude plugin showing the problem. I have tested the same plugin against WordPress 3.1.4 and the issue is not visible there. To see the issue in action:

  1. Install the plugin & activate the plugin.
  2. Create a new post.
  3. Delete that post.

Is this a regression?

Attachments (1)

wp-3.2-off-by-1-demo.php (668 bytes) - added by meitar 13 years ago.
Crude plugin that shows off-by-1 error in delete_post hook.

Download all attachments as: .zip

Change History (3)

13 years ago

Crude plugin that shows off-by-1 error in delete_post hook.

#1 @kawauso
13 years ago

  • Resolution set to invalid
  • Status changed from new to closed

The ID being passed to the filter is a post revision, the $_GET value is the parent post ID. In my test these were 849 and 838 respectively, so being off by one is coincidence.

'delete_post' is actually invoked for each revision before the parent post, so if you remove the exit from your test code, you should see they match in the final iteration.

#2 @kawauso
13 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.