Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use current timestamp if post does not have a date #5450

Merged
merged 2 commits into from
Oct 1, 2020

Conversation

pierlon
Copy link
Contributor

@pierlon pierlon commented Sep 30, 2020

Summary

Uses the current Unix timestamp for the post date if the post does not have one (i.e. post does not have the post_date_gmt property set or has the value 0000-00-00 00:00:00).

Fixes #5449

Checklist

  • My pull request is addressing an open issue (please create one otherwise).
  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@pierlon pierlon added the WS:Core Work stream for Plugin core label Sep 30, 2020
@pierlon pierlon added this to the v2.0.5 milestone Sep 30, 2020
@google-cla google-cla bot added the cla: yes Signed the Google CLA label Sep 30, 2020
@@ -302,15 +302,19 @@ private function build_post_data() {
* @return int Post publish UTC timestamp.
*/
private function build_post_publish_timestamp() {
$format = 'U';
$timestamp = (int) get_post_time( $format, true, $this->post, true );
if ( empty( $this->post->post_date_gmt ) || '0000-00-00 00:00:00' === $this->post->post_date_gmt ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter Do you think a check should be added to only use time() when the post status is either draft, pending or auto-draft?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is necessary, as that special value would only ever happen for a non-published post anyway.

Apparently this post statuses that include that special value are called date_floating, which means “whether the post has a floating creation date.” If it has no creation date, then now() should be assumed no?

https://github.com/WordPress/wordpress-develop/blob/19513ff6a0fc27b2ff7e9debeb6e94b7e1b4d658/src/wp-includes/post.php#L3775-L3810

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh interesting. So yes, if no creation date, use time() (assuming that you mistakenly used now() for time()).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I meant time().

@github-actions
Copy link
Contributor

github-actions bot commented Sep 30, 2020

Plugin builds for db11338 are ready 🛎️!


/** This filter is documented in wp-includes/general-template.php. */
$filtered_timestamp = apply_filters( 'get_the_date', $timestamp, $format, $this->post );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the $timestamp not still get filtered when it is time()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in db11338.

Copy link
Member

@westonruter westonruter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before After
image image

@westonruter westonruter merged commit 5f42cde into develop Oct 1, 2020
@westonruter westonruter deleted the fix/5449-invalid-timestamp-preview-post branch October 1, 2020 19:03
@westonruter westonruter added the Changelogged Whether the issue/PR has been added to release notes. label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelogged Whether the issue/PR has been added to release notes. cla: yes Signed the Google CLA WS:Core Work stream for Plugin core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Previews: date is incorrect
2 participants