[wp-trac] [WordPress Trac] #52187: Create function to resolve a post date from post_date and post_date_gmt strings

WordPress Trac noreply at wordpress.org
Tue Dec 29 22:26:30 UTC 2020


#52187: Create function to resolve a post date from post_date and post_date_gmt
strings
----------------------------------------+------------------------------
 Reporter:  jmdodd                      |       Owner:  (none)
     Type:  enhancement                 |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Posts, Post Types           |     Version:  trunk
 Severity:  normal                      |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+------------------------------

Comment (by jmdodd):

 While testing this, I found an interesting behavior in wp_insert_post --
 an empty post_date and an invalid post_date_gmt (ex. "2020-12-41
 10:11:41") will result in an inserted post with a post_date of "1970-01-01
 00:00:00" rather than a failure because get_date_from_gmt will always
 return a date.

 resolve_post_date (soon to be wp_resolve_post_date) doesn't change this
 behavior, but unit tests surfaced it as one that was already present in
 5.6.


 {{{

 $ wp shell
 wp> wp_insert_post( array( 'post_date' => '', 'post_date_gmt' =>
 '2020-12-41 10:10:10', 'post_title' => 'Test', 'post_content' => 'Test
 content.', 'post_status' => 'publish' ) );
 => int(11)
 wp>
 $ wp post get 11
 +-----------------------+--------------------------------------+
 | Field                 | Value                                |
 +-----------------------+--------------------------------------+
 | ID                    | 11                                   |
 | post_author           | 0                                    |
 | post_date             | 1970-01-01 00:00:00                  |
 | post_date_gmt         | 0000-00-00 00:00:00                  |
 | post_content          | Test content.                        |
 | post_title            | Test                                 |
 | post_excerpt          |                                      |
 | post_status           | publish                              |
 | comment_status        | open                                 |
 | ping_status           | open                                 |
 | post_password         |                                      |
 | post_name             | test                                 |
 | to_ping               |                                      |
 | pinged                |                                      |
 | post_modified         | 1970-01-01 00:00:00                  |
 | post_modified_gmt     | 0000-00-00 00:00:00                  |
 | post_content_filtered |                                      |
 | post_parent           | 0                                    |
 | guid                  | http://wp.localhost/1970/01/01/test/ |
 | menu_order            | 0                                    |
 | post_type             | post                                 |
 | post_mime_type        |                                      |
 | comment_count         | 0                                    |
 +-----------------------+--------------------------------------+
 $ wp core version
 5.6
 }}}

 Fixing this behavior would be a breaking change, as posts that would
 previously have been inserted with post_date "1970-01-01 00:00:00" would
 instead fail because of the invalid passed post_date_gmt.

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


More information about the wp-trac mailing list