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

Ensure post_publish_timestamp in AMP_Post_Template is UTC for human_time_diff() #5335

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion includes/templates/class-amp-post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private function add_data_by_key( $key, $value ) {
*/
private function build_post_data() {
$post_title = get_the_title( $this->post );
$post_publish_timestamp = get_the_date( 'U', $this->post );
$post_publish_timestamp = $this->build_post_publish_timestamp();
$post_modified_timestamp = get_post_modified_time( 'U', false, $this->post );
$post_author = get_userdata( $this->post->post_author );

Expand All @@ -294,6 +294,28 @@ private function build_post_data() {
$this->build_post_comments_data();
}

/**
* Build post publish timestamp.
*
* We can't use `get_the_date( 'U' )` because it always returns the non-GMT value.
*
* @return int Post publish UTC timestamp.
*/
private function build_post_publish_timestamp() {
$format = 'U';
$timestamp = (int) get_post_time( $format, true, $this->post, true );

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

// Guard against a plugin poorly filtering get_the_date to be something other than a Unix timestamp.
if ( is_int( $filtered_timestamp ) ) {
$timestamp = $filtered_timestamp;
}

return $timestamp;
}

/**
* Build post comments data.
*/
Expand Down