diff --git a/includes/functions/_api.php b/includes/functions/_api.php index a79e98a3..1a3c7cbd 100644 --- a/includes/functions/_api.php +++ b/includes/functions/_api.php @@ -18,7 +18,7 @@ if ( ! function_exists( 'fictioneer_api_get_story_node' ) ) { function fictioneer_api_get_story_node( $story_id, $with_chapters = true ) { // Validation - $data = fictioneer_get_story_data( $story_id ); + $data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count! // Abort if... if ( empty( $data ) ) return false; diff --git a/includes/functions/_shortcodes.php b/includes/functions/_shortcodes.php index 2ea330e0..58d30a75 100644 --- a/includes/functions/_shortcodes.php +++ b/includes/functions/_shortcodes.php @@ -871,7 +871,7 @@ function fictioneer_shortcode_chapter_list( $attr ) { if ( $story_id && empty( $chapter_ids ) ) { // ... via story $hide_icons = $hide_icons || fictioneer_get_field( 'fictioneer_story_hide_chapter_icons', $story_id ); - $story_data = fictioneer_get_story_data( $story_id ); + $story_data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count! $chapters = $story_data['chapter_ids']; } elseif ( ! empty( $chapter_ids ) ) { // ... via chapter IDs diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index 472eca1b..08dadb0a 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -200,12 +200,14 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { * * @since Fictioneer 4.3 * - * @param int $story_id ID of the story. + * @param int $story_id ID of the story. + * @param boolean $refresh_comment_count Optional. Whether to refresh comment count. + * Default true. * * @return array|boolean $result Data of the story or false if invalid. */ - function fictioneer_get_story_data( $story_id ) { + function fictioneer_get_story_data( $story_id, $refresh_comment_count = true ) { $story_id = fictioneer_validate_id( $story_id, 'fcn_story' ); if ( ! $story_id ) return false; @@ -215,16 +217,18 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { if ( ! empty( $old_data ) && $old_data['last_modified'] >= get_the_modified_time( 'U', $story_id ) ) { // Refresh comment count - $comment_count = count( $old_data['chapter_ids'] ) < 1 ? 0 : get_comments( - array( - 'status' => 'approve', - 'post_type' => array( 'fcn_chapter' ), - 'post__in' => $old_data['chapter_ids'], - 'count' => true - ) - ); + if ( $refresh_comment_count ) { + $comment_count = count( $old_data['chapter_ids'] ) < 1 ? 0 : get_comments( + array( + 'status' => 'approve', + 'post_type' => array( 'fcn_chapter' ), + 'post__in' => $old_data['chapter_ids'], + 'count' => true + ) + ); - $old_data['comment_count'] = $comment_count; + $old_data['comment_count'] = $comment_count; + } // Return cached data return $old_data; diff --git a/includes/functions/_wordpress_mods.php b/includes/functions/_wordpress_mods.php index cdd47518..f6f847df 100644 --- a/includes/functions/_wordpress_mods.php +++ b/includes/functions/_wordpress_mods.php @@ -172,7 +172,7 @@ if ( ! function_exists( 'fictioneer_get_stories_total_word_count' ) ) { // Sum of all word counts foreach( $stories as $story ) { - $story_data = fictioneer_get_story_data( $story->ID ); + $story_data = fictioneer_get_story_data( $story->ID, false ); // Does not refresh comment count! $word_count += $story_data['word_count']; } diff --git a/includes/functions/comments/_story_comments.php b/includes/functions/comments/_story_comments.php index e01d39d7..217f9801 100644 --- a/includes/functions/comments/_story_comments.php +++ b/includes/functions/comments/_story_comments.php @@ -104,7 +104,7 @@ if ( ! function_exists( 'fictioneer_request_story_comments' ) ) { // Setup $page = isset( $_GET['page'] ) ? absint( $_GET['page'] ) : 1; - $story = fictioneer_get_story_data( $story_id ); + $story = fictioneer_get_story_data( $story_id, true ); $chapter_ids = $story['chapter_ids']; // Only contains publicly visible chapters $comments_per_page = get_option( 'comments_per_page' ); $chapter_data = []; diff --git a/includes/functions/settings/_settings_page_epubs.php b/includes/functions/settings/_settings_page_epubs.php index f1065759..9d247126 100644 --- a/includes/functions/settings/_settings_page_epubs.php +++ b/includes/functions/settings/_settings_page_epubs.php @@ -92,7 +92,7 @@ $current_epubs = array_slice( $epubs, $offset, $epubs_per_page, true ); $story_data = null; if ( $story ) { - $story_data = fictioneer_get_story_data( $story->ID ); + $story_data = fictioneer_get_story_data( $story->ID, false ); // Does not refresh comment count! } $downloads = $story ? get_post_meta( $story->ID, 'fictioneer_epub_downloads', true ) : 0; diff --git a/includes/functions/users/_checkmarks.php b/includes/functions/users/_checkmarks.php index 1c280d88..3bd6eb10 100644 --- a/includes/functions/users/_checkmarks.php +++ b/includes/functions/users/_checkmarks.php @@ -163,7 +163,7 @@ if ( ! function_exists( 'fictioneer_ajax_set_checkmark' ) ) { wp_send_json_error( ['error' => __( 'Invalid story ID.', 'fictioneer' )] ); } - $story_data = fictioneer_get_story_data( $story_id ); + $story_data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count! // Prepare update $update = isset( $_POST['update'] ) ? explode( ' ', sanitize_text_field( $_POST['update'] ) ) : []; diff --git a/partials/_card-chapter.php b/partials/_card-chapter.php index 0ee6595b..e1edaeec 100644 --- a/partials/_card-chapter.php +++ b/partials/_card-chapter.php @@ -19,7 +19,7 @@ // Setup $title = fictioneer_get_safe_title( get_the_ID() ); $story_id = fictioneer_get_field( 'fictioneer_chapter_story' ); -$story_data = $story_id ? fictioneer_get_story_data( $story_id ) : null; +$story_data = $story_id ? fictioneer_get_story_data( $story_id, false ) : null; // Does not refresh comment count! $chapter_rating = fictioneer_get_field( 'fictioneer_chapter_rating' ); $story_thumbnail_url_full = $story_id ? get_the_post_thumbnail_url( $story_id, 'full' ) : null; $text_icon = fictioneer_get_field( 'fictioneer_chapter_text_icon' ); diff --git a/partials/_latest-chapters-compact.php b/partials/_latest-chapters-compact.php index 40d3ea5a..b1518c7e 100644 --- a/partials/_latest-chapters-compact.php +++ b/partials/_latest-chapters-compact.php @@ -75,7 +75,7 @@ $entries = fictioneer_shortcode_query( $query_args ); // Setup $title = fictioneer_get_safe_title( get_the_ID() ); $story_id = fictioneer_get_field( 'fictioneer_chapter_story' ); - $story = $story_id ? fictioneer_get_story_data( $story_id ) : false; + $story = $story_id ? fictioneer_get_story_data( $story_id, false ) : false; // Does not refresh comment count! $text_icon = fictioneer_get_field( 'fictioneer_chapter_text_icon' ); // Chapter images diff --git a/partials/_latest-chapters.php b/partials/_latest-chapters.php index 06236dda..861e344e 100644 --- a/partials/_latest-chapters.php +++ b/partials/_latest-chapters.php @@ -77,7 +77,7 @@ $entries = fictioneer_shortcode_query( $query_args ); $title = fictioneer_get_safe_title( get_the_ID() ); $chapter_rating = fictioneer_get_field( 'fictioneer_chapter_rating' ); $story_id = fictioneer_get_field( 'fictioneer_chapter_story' ); - $story = $story_id ? fictioneer_get_story_data( $story_id ) : false; + $story = $story_id ? fictioneer_get_story_data( $story_id, false ) : false; // Does not refresh comment count! $text_icon = fictioneer_get_field( 'fictioneer_chapter_text_icon' ); // Chapter images diff --git a/partials/_latest-stories-compact.php b/partials/_latest-stories-compact.php index 04352cb0..19e19a99 100644 --- a/partials/_latest-stories-compact.php +++ b/partials/_latest-stories-compact.php @@ -83,7 +83,7 @@ $entries = fictioneer_shortcode_query( $query_args ); ID ); + $story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count! $tags = get_option( 'fictioneer_show_tags_on_story_cards' ) ? get_the_tags( $post ) : false; ?> diff --git a/partials/_latest-stories.php b/partials/_latest-stories.php index 4747e727..e13c5929 100644 --- a/partials/_latest-stories.php +++ b/partials/_latest-stories.php @@ -80,7 +80,7 @@ $entries = fictioneer_shortcode_query( $query_args ); ID ); + $story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count! $tags = get_option( 'fictioneer_show_tags_on_story_cards' ) ? get_the_tags( $post ) : false; ?> diff --git a/partials/_latest-updates-compact.php b/partials/_latest-updates-compact.php index ba1f2219..499a4a00 100644 --- a/partials/_latest-updates-compact.php +++ b/partials/_latest-updates-compact.php @@ -87,7 +87,7 @@ $entries = fictioneer_shortcode_query( $query_args ); ID ); + $story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count! $chapter_list = []; $chapter_excerpt; // Set inside inner loop $chapter_title; // Set inside inner loop diff --git a/partials/_latest-updates.php b/partials/_latest-updates.php index c56abb18..7393e1b9 100644 --- a/partials/_latest-updates.php +++ b/partials/_latest-updates.php @@ -88,7 +88,7 @@ $entries = fictioneer_shortcode_query( $query_args ); ID ); + $story = fictioneer_get_story_data( $post->ID, false ); // Does not refresh comment count! $tags = get_option( 'fictioneer_show_tags_on_story_cards' ) ? get_the_tags( $post ) : false; $chapter_list = []; diff --git a/partials/_story-content.php b/partials/_story-content.php index b6b49ff2..07b1c376 100644 --- a/partials/_story-content.php +++ b/partials/_story-content.php @@ -133,7 +133,7 @@ $disable_folding = fictioneer_get_field( 'fictioneer_story_disable_collapse' );