[wp-trac] [WordPress Trac] #36738: No validation for $post_date_gmt parameter
WordPress Trac
noreply at wordpress.org
Tue Sep 2 14:59:26 UTC 2025
#36738: No validation for $post_date_gmt parameter
-------------------------------------------------+-------------------------
Reporter: Latz | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Future
| Release
Component: Posts, Post Types | Version: 3.5
Severity: normal | Resolution:
Keywords: has-test-info good-first-bug needs- | Focuses:
patch |
-------------------------------------------------+-------------------------
Comment (by paulbonneau):
Hello @SirLouen,
First of all, thanks for your answer.
I think I was not clear and in my previous answer because it was too
intricate and complicated.
To simplify : It doesn't seems possible to implement "Just like $post_date
it should throw an error to give a programmer the right hint for his
malfunctioning code." without introducing a breaking change that
contradict the desire for backward compatibility.
I found other tests in `/tests/phpunit/tests/post/wpInsertPost.php` like
`test_insert_empty_post_date` that explicitly wait `1970-01-01 00:00:00`
when an invalid_date is passed in `post_date_gmt`. It has been introduced
in this ticket : https://core.trac.wordpress.org/ticket/52187#comment:4
Nevertheless, I still have produced a patch as I think @Latz is the good
way to go. This patch :
* implements this requirement `Just like $post_date it should throw an
error to give a programmer the right hint for his malfunctioning code.`
* abstract part of the current logic within `wp_resolve_post_date` and use
it to target both scenarios (`$post_date` and `$post_date_gmt`) as best as
I could
* update test so they pass when a WP_Error is thrown if an invalid
post_date_gmt is passed to wp_insert_post
* try to respect as much as possible the original logic of the code
You will find this patch name `36738-02092025.diff` attached to the
ticket.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/36738#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list