[wp-trac] [WordPress Trac] #63975: wp_delete_auto_drafts passes post ID as string instead of as int
WordPress Trac
noreply at wordpress.org
Mon Oct 6 20:11:37 UTC 2025
#63975: wp_delete_auto_drafts passes post ID as string instead of as int
-------------------------------------------------+-------------------------
Reporter: kkmuffme | Owner:
| westonruter
Type: defect (bug) | Status: closed
Priority: normal | Milestone: 6.9
Component: Posts, Post Types | Version: 3.4
Severity: normal | Resolution: fixed
Keywords: has-test-info has-patch has-unit- | Focuses:
tests |
-------------------------------------------------+-------------------------
Changes (by westonruter):
* status: accepted => closed
* resolution: => fixed
Comment:
In [changeset:"60906" 60906]:
{{{
#!CommitTicketReference repository="" revision="60906"
Posts, Post Types: Short-circuit `wp_post_delete()` when `$post_id` arg is
not above zero after casting to `int`.
The casting to `int` ensures that the action callbacks for post deletion
can safely use the `int` type hint for the `$post_id` argument, as
otherwise a fatal error occurs when an integer string is passed. This
function also originally had casting of the argument to an integer, going
back to at least WP 1.5.0, since it was passed directly into an SQL query.
The casting was removed in [6180] with the introduction of prepared SQL
statements.
The `wp_delete_post()` function had `$post_id = 0` defined as its
argument, also going back at least to WP 1.5.0, perhaps as a way to
indicate the type of the argument as being an integer before there was
PHPDoc. Unlike with functions like `get_post()` which have `$post = null`
as the default argument to fall back to getting the global post, no such
fallback logic was added to `wp_delete_post()`, meaning that passing no
argument would always result in a DB query to locate the post with an `ID`
of `0`, which will never happen. So this introduces a `_doing_it_wrong()`
in case `0` is passed, and yet the default value of `0` is not removed
from the function signature to not introduce a fatal error in case any
existing code is not supplying the `$post_id` parameter (however unlikely
this may be).
Unit tests have been fleshed out for `wp_delete_post()` to add coverage
for what was previously missing.
Props SirLouen, kkmuffme, fakhriaz, sajjad67, siliconforks, peterwilsoncc,
westonruter.
Fixes #63975.
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63975#comment:45>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list