-
Notifications
You must be signed in to change notification settings - Fork 381
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
Conversation
@@ -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 ) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I meant time()
.
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 ); |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in db11338.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 value0000-00-00 00:00:00
).Fixes #5449
Checklist