From 13dbe298c90b8fd99b6766138d43d8a3cb91179d Mon Sep 17 00:00:00 2001 From: Rasmy Nguyen Date: Thu, 9 Jan 2025 12:48:30 -0500 Subject: [PATCH] fix: use post_date to store correction date --- includes/corrections/README.md | 2 +- includes/corrections/class-corrections.php | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/includes/corrections/README.md b/includes/corrections/README.md index b878c37ce8..101094a4df 100644 --- a/includes/corrections/README.md +++ b/includes/corrections/README.md @@ -22,7 +22,7 @@ Corrections are stored as `newspack_correction` custom post type. A correction c | ----------------------------- | -------- | -------------- | --------------------------------------------------------------- | | `title` | `string` | `post_title` | The correction title. Defaults to 'Correction for [post title]' | | `content` | `string` | `post_content` | The correction text. | -| `newspack_correction_date` | `string` | `post_meta` | Correction date. Note this is different from the post date. | +| `date` | `string` | `post_date` | The date assigned to the correction. | | `newspack_correction-post-id` | `int` | `post_meta` | The ID of the post to which the correction is associated. | In addition, some correction data is stored in the associated post as post meta: diff --git a/includes/corrections/class-corrections.php b/includes/corrections/class-corrections.php index 775677487e..e71e4b5bbe 100644 --- a/includes/corrections/class-corrections.php +++ b/includes/corrections/class-corrections.php @@ -16,11 +16,6 @@ class Corrections { */ const POST_TYPE = 'newspack_correction'; - /** - * Meta key for correction date meta. - */ - const CORRECTION_DATE_META = 'newspack_correction_date'; - /** * Meta key for correction post ID meta. */ @@ -170,11 +165,11 @@ public static function add_corrections( $post_id, $corrections ) { [ 'post_title' => 'Correction for ' . get_the_title( $post_id ), 'post_content' => $correction['content'], + 'post_date' => $correction['date'], 'post_type' => self::POST_TYPE, 'post_status' => 'publish', 'meta_input' => [ self::CORRECTION_POST_ID_META => $post_id, - self::CORRECTION_DATE_META => $correction['date'], ], ] ); @@ -217,9 +212,9 @@ public static function update_correction( $correction_id, $correction ) { [ 'ID' => $correction_id, 'post_content' => sanitize_textarea_field( $correction['content'] ), + 'post_date' => sanitize_text_field( $correction['date'] ), ] ); - update_post_meta( $correction_id, self::CORRECTION_DATE_META, sanitize_text_field( $correction['date'] ) ); } /** @@ -285,11 +280,11 @@ public static function handle_corrections_shortcode() { post_content; - $correction_date = get_post_meta( $correction->ID, self::CORRECTION_DATE_META, true ); + $correction_date = \get_the_date( 'M j, Y', $correction->ID ); $correction_heading = sprintf( // translators: %s: correction date. __( 'Correction on %s', 'newspack-plugin' ), - gmdate( 'M j, Y', strtotime( $correction_date ) ) + $correction_date ); ?>

@@ -353,7 +348,7 @@ public static function render_corrections_metabox( $post ) { post_content; - $correction_date = get_post_meta( $correction->ID, self::CORRECTION_DATE_META, true ); + $correction_date = \get_the_date( 'Y-m-d', $correction->ID ); ?>

@@ -478,11 +473,11 @@ public static function output_corrections_on_post( $content ) { post_content; - $correction_date = get_post_meta( $correction->ID, self::CORRECTION_DATE_META, true ); + $correction_date = \get_the_date( 'M j, Y', $correction->ID ); $correction_heading = sprintf( // translators: %s: correction date. __( 'Correction on %s', 'newspack-plugin' ), - gmdate( 'M j, Y', strtotime( $correction_date ) ) + $correction_date ); ?>