Skip to content

Commit

Permalink
fix: human-readable timestamp of sent newsletters
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Aug 1, 2024
1 parent 25ecc21 commit bf3e268
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions includes/class-newspack-newsletters.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,6 @@ public static function display_post_states( $post_states, $post ) {

$post_status = get_post_status_object( $post->post_status );
$sent = self::is_newsletter_sent( $post->ID );
$is_public = get_post_meta( $post->ID, 'is_public', true );

if ( $sent ) {
$time_diff = time() - $sent;

Expand Down Expand Up @@ -1176,17 +1174,17 @@ public static function is_newsletter_sent( $post_id ) {
}

/** Detect meta that determines the sent state */
$sent = get_post_meta( $post_id, 'newsletter_sent', true );
if ( 0 < $sent ) {
$sent = get_post_meta( $post_id, 'newsletter_sent', true );
$is_published = 'publish' === get_post_status( $post_id );
$publish_date = $is_published ? get_post_datetime( $post_id, 'date', 'gmt' )->getTimestamp() : 0;
if ( 0 < $sent && $sent === $publish_date ) {
return $sent;
}

/** Legacy check for sent/publish newsletters without meta. */
if ( 'publish' === get_post_status( $post_id ) ) {
$post = get_post( $post_id );
$sent = strtotime( $post->post_date );
self::set_newsletter_sent( $post_id, $sent );
return $sent;
if ( $publish_date ) {
self::set_newsletter_sent( $post_id, $publish_date );
return $publish_date;
}

return false;
Expand Down

0 comments on commit bf3e268

Please sign in to comment.