[wp-trac] [WordPress Trac] #26798: While inserting a post some values for 'post_date' throw a PHP exception

WordPress Trac noreply at wordpress.org
Thu Nov 6 23:36:08 UTC 2025


#26798: While inserting a post some values for 'post_date' throw a PHP exception
--------------------------------------+----------------------
 Reporter:  mobius5150                |       Owner:  pbearne
     Type:  defect (bug)              |      Status:  closed
 Priority:  normal                    |   Milestone:  6.9
Component:  Date/Time                 |     Version:  3.5
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+----------------------
Changes (by johnjamesjacoby):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"61172" 61172]:
 {{{
 #!CommitTicketReference repository="" revision="61172"
 Date/Time: Prevent a PHP exception when inserting posts with a partially
 malformed `post_date`.

 This commit updates `wp_resolve_post_date()` to use a regular expression
 for parsing the date string into year, month, and day matches. This
 approach handles missing leading zeros more reliably than `substr()` while
 remaining performant (see #57683).

 It also adds checks and type-casting to `wp_checkdate()` variables before
 passing them into PHP's `checkdate()` function to avoid the potential for
 a `TypeError` in PHP 8 and newer (see #54186).

 Lastly, it includes 2 new unit tests (with data providers) to cover an
 array of valid and invalid date formats (YYYY-MM-DD, YYYY-MM-DD HH:MM:SS,
 ISO 8601, RSS, leap years, malformed inputs, etc...)

 Props alordiel, desrosj, johnbillion, johnjamesjacoby, johnregan3,
 modius5150, nacin, pbearne.

 Fixes #26798.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/26798#comment:19>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list