Skip to content

Commit

Permalink
fix: remove newspack_corrections_ids meta
Browse files Browse the repository at this point in the history
  • Loading branch information
chickenn00dle committed Jan 14, 2025
1 parent aaf8234 commit 72bc6fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
1 change: 0 additions & 1 deletion includes/corrections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,3 @@ In addition, some correction data is stored in the associated post as post meta:
| ------------------------------- | ----------------------- | ----------- | ------------------------------------------------------------- |
| `newspack_corrections_active` | `bool` | `post_meta` | Whether the feature is enabled for the post. |
| `newspack_corrections_location` | `string` | `post_meta` | Where the correction should be displayed. (`top` or `bottom`) |
| `newspack_corrections_ids` | `array` | `post_meta` | An array of IDs of the corrections associated with the post. |
27 changes: 4 additions & 23 deletions includes/corrections/class-corrections.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ class Corrections {
*/
const CORRECTIONS_LOCATION_META = 'newspack_corrections_location';

/**
* Meta key for post corrections ids meta.
*/
const CORRECTIONS_IDS_META = 'newspack_corrections_ids';

/**
* Initializes the class.
*/
Expand Down Expand Up @@ -156,10 +151,6 @@ public static function register_post_type() {
* @param array $corrections The corrections.
*/
public static function add_corrections( $post_id, $corrections ) {
$correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true );
if ( ! is_array( $correction_ids ) ) {
$correction_ids = [];
}
foreach ( $corrections as $correction ) {
$id = wp_insert_post(
[
Expand All @@ -177,7 +168,6 @@ public static function add_corrections( $post_id, $corrections ) {
$correction_ids[] = $id;
}
}
update_post_meta( $post_id, self::CORRECTIONS_IDS_META, $correction_ids );
}

/**
Expand All @@ -188,15 +178,14 @@ public static function add_corrections( $post_id, $corrections ) {
* @return array The corrections.
*/
public static function get_corrections( $post_id ) {
$correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true );
if ( ! is_array( $correction_ids ) ) {
return [];
}
return get_posts(
[
'posts_per_page' => -1,
'post_type' => self::POST_TYPE,
'include' => $correction_ids,
'meta_key' => self::CORRECTION_POST_ID_META, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key
'meta_value' => $post_id, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
'orderby' => 'date',
'order' => 'DESC',
]
);
}
Expand Down Expand Up @@ -224,17 +213,9 @@ public static function update_correction( $correction_id, $correction ) {
* @param array $correction_ids correction ids.
*/
public static function delete_corrections( $post_id, $correction_ids ) {
$stored_correction_ids = get_post_meta( $post_id, self::CORRECTIONS_IDS_META, true );
if ( ! is_array( $stored_correction_ids ) ) {
$stored_correction_ids = [];
}
foreach ( $correction_ids as $id ) {
wp_delete_post( $id, true );
if ( isset( $stored_correction_ids[ $id ] ) ) {
unset( $stored_correction_ids[ $id ] );
}
}
update_post_meta( $post_id, self::CORRECTIONS_IDS_META, $stored_correction_ids );
}

/**
Expand Down

0 comments on commit 72bc6fb

Please sign in to comment.