From a7051df9f1963a34337d8c6f2489b531fc9961ba Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:46:43 +0200 Subject: [PATCH] Add fictioneer_set_chapter_story_parent() --- includes/functions/_development.php | 11 +---------- includes/functions/_helpers-query.php | 23 ++++++++++++++++++++++- includes/functions/_setup-meta-fields.php | 11 +---------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/includes/functions/_development.php b/includes/functions/_development.php index dfc4dd9e..2473d6b5 100644 --- a/includes/functions/_development.php +++ b/includes/functions/_development.php @@ -62,8 +62,6 @@ function fictioneer_generate_test_comments( $post_id, $number = 3 ) { */ function fictioneer_generate_test_content() { - global $wpdb; - if ( ! current_user_can( 'manage_options' ) || get_current_user_id() !== 1 || ! WP_DEBUG ) { return; } @@ -160,14 +158,7 @@ function fictioneer_generate_test_content() { fictioneer_generate_test_comments( $chapter_id, $comment_count ); update_post_meta( $chapter_id, 'fictioneer_chapter_story', $story_id ); - - $wpdb->query( - $wpdb->prepare( - "UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", - $story_id ?: 0, - $chapter_id - ) - ); + fictioneer_set_chapter_story_parent( $chapter_id, $story_id ); } } diff --git a/includes/functions/_helpers-query.php b/includes/functions/_helpers-query.php index ae5ce2c6..a7f78d40 100644 --- a/includes/functions/_helpers-query.php +++ b/includes/functions/_helpers-query.php @@ -335,7 +335,7 @@ if ( get_option( 'fictioneer_disable_extended_story_list_meta_queries' ) ) { } // ============================================================================= -// GET CHAPTER STORY ID +// CHAPTER STORY ID // ============================================================================= /** @@ -351,3 +351,24 @@ if ( get_option( 'fictioneer_disable_extended_story_list_meta_queries' ) ) { function fictioneer_get_chapter_story_id( $chapter_id ) { return get_post_meta( $chapter_id, 'fictioneer_chapter_story', true ); } + +/** + * Sets the chapter parent ID to the story ID + * + * @since 5.26.0 + * + * @param int $chapter_id Chapter ID. + * @param int $story_id Story ID. + */ + +function fictioneer_set_chapter_story_parent( $chapter_id, $story_id ) { + global $wpdb; + + $wpdb->query( + $wpdb->prepare( + "UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", + $story_id ?: 0, + $chapter_id + ) + ); +} diff --git a/includes/functions/_setup-meta-fields.php b/includes/functions/_setup-meta-fields.php index 22a4c375..08f94044 100644 --- a/includes/functions/_setup-meta-fields.php +++ b/includes/functions/_setup-meta-fields.php @@ -3051,19 +3051,10 @@ function fictioneer_save_chapter_metaboxes( $post_id ) { if ( get_option( 'fictioneer_enable_chapter_appending' ) ) { fictioneer_append_chapter_to_story( $post_id, $story_id ); } - - global $wpdb; - - $wpdb->query( - $wpdb->prepare( - "UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", - $story_id ?: 0, - $post_id - ) - ); } } + fictioneer_set_chapter_story_parent( $post_id, $story_id ?: 0 ); $fields['fictioneer_chapter_story'] = strval( $story_id ?: 0 ); }