Skip to content

Commit

Permalink
fix: use post_date to store correction date
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Jan 9, 2025
1 parent fea9890 commit 13dbe29
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion includes/corrections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 7 additions & 12 deletions includes/corrections/class-corrections.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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'],
],
]
);
Expand Down Expand Up @@ -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'] ) );
}

/**
Expand Down Expand Up @@ -285,11 +280,11 @@ public static function handle_corrections_shortcode() {
<?php
foreach ( $corrections as $correction ) :
$correction_content = $correction->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
);
?>
<p>
Expand Down Expand Up @@ -353,7 +348,7 @@ public static function render_corrections_metabox( $post ) {
<?php
foreach ( $corrections as $correction ) :
$correction_content = $correction->post_content;
$correction_date = get_post_meta( $correction->ID, self::CORRECTION_DATE_META, true );
$correction_date = \get_the_date( 'Y-m-d', $correction->ID );
?>
<fieldset name="existing-corrections[<?php echo esc_attr( $correction->ID ); ?>]" class="correction">
<p><?php echo esc_html( __( 'Article Correction', 'newspack-plugin' ) ); ?></p>
Expand Down Expand Up @@ -478,11 +473,11 @@ public static function output_corrections_on_post( $content ) {
<?php
foreach ( $corrections as $correction ) :
$correction_content = $correction->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
);
?>
<!-- wp:paragraph {"fontSize":"small"} -->
Expand Down

0 comments on commit 13dbe29

Please sign in to comment.