diff --git a/includes/functions/_helpers-templates.php b/includes/functions/_helpers-templates.php index 3b33dd3b..9b7517a8 100644 --- a/includes/functions/_helpers-templates.php +++ b/includes/functions/_helpers-templates.php @@ -1123,12 +1123,14 @@ if ( ! function_exists( 'fictioneer_get_chapter_micro_menu' ) ) { * * @since 5.0.0 * @since 5.9.4 - Removed output buffer. + * @since 5.14.0 - Added indexed chapter IDs. * - * @param WP_Post|null $args['story_post'] Optional. Post object of the story. - * @param int $args['chapter_id'] The chapter ID. - * @param array $args['chapter_ids'] IDs of visible chapters in the same story or empty array. - * @param int|boolean $args['prev_index'] Index of previous chapter or false if outside bounds. - * @param int|boolean $args['next_index'] Index of next chapter or false if outside bounds. + * @param WP_Post|null $args['story_post'] Optional. Post object of the story. + * @param int $args['chapter_id'] The chapter ID. + * @param array $args['chapter_ids'] IDs of visible chapters in the same story or empty array. + * @param array $args['indexed_chapter_ids'] IDs of accessible chapters in the same story or empty array. + * @param int|boolean $args['prev_index'] Index of previous chapter or false if outside bounds. + * @param int|boolean $args['next_index'] Index of next chapter or false if outside bounds. * * @return string The chapter micro menu HTML. */ @@ -1184,8 +1186,8 @@ if ( ! function_exists( 'fictioneer_get_chapter_micro_menu' ) ) { if ($args['prev_index'] !== false) { $micro_menu['previous'] = sprintf( '', - get_permalink( $args['chapter_ids'][ $args['prev_index'] ] ), - esc_attr( get_the_title( $args['chapter_ids'][ $args['prev_index'] ] ) ) + get_permalink( $args['indexed_chapter_ids'][ $args['prev_index'] ] ), + esc_attr( get_the_title( $args['indexed_chapter_ids'][ $args['prev_index'] ] ) ) ); } @@ -1199,8 +1201,8 @@ if ( ! function_exists( 'fictioneer_get_chapter_micro_menu' ) ) { if ($args['next_index']) { $micro_menu['next'] = sprintf( '', - get_permalink( $args['chapter_ids'][ $args['next_index'] ] ), - esc_attr( get_the_title( $args['chapter_ids'][ $args['next_index'] ] ) ) + get_permalink( $args['indexed_chapter_ids'][ $args['next_index'] ] ), + esc_attr( get_the_title( $args['indexed_chapter_ids'][ $args['next_index'] ] ) ) ); } diff --git a/includes/functions/_utility.php b/includes/functions/_utility.php index 322599f2..d6c4b317 100644 --- a/includes/functions/_utility.php +++ b/includes/functions/_utility.php @@ -330,6 +330,7 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { $word_count = 0; $comment_count = 0; $visible_chapter_ids = []; + $indexed_chapter_ids = []; // Assign correct icon if ( $status != 'Ongoing' ) { @@ -362,6 +363,11 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { // ... but they are still listed! $visible_chapter_ids[] = $chapter->ID; + + // Indexed chapters (accounts for custom filers) + if ( $chapter->post_status === 'publish' ) { + $indexed_chapter_ids[] = $chapter->ID; + } } // Count ALL comments @@ -390,6 +396,7 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) { 'rating' => get_post_meta( $story_id, 'fictioneer_story_rating', true ), 'rating_letter' => get_post_meta( $story_id, 'fictioneer_story_rating', true )[0], 'chapter_ids' => $visible_chapter_ids, + 'indexed_chapter_ids' => $indexed_chapter_ids, 'last_modified' => get_the_modified_time( 'U', $story_id ), 'comment_count' => $comment_count, 'comment_count_timestamp' => time(), diff --git a/includes/functions/hooks/_chapter_hooks.php b/includes/functions/hooks/_chapter_hooks.php index 8287e7ff..6c5087b0 100644 --- a/includes/functions/hooks/_chapter_hooks.php +++ b/includes/functions/hooks/_chapter_hooks.php @@ -240,11 +240,13 @@ add_action( 'fictioneer_chapter_actions_top_left', 'fictioneer_chapter_resize_bu * Outputs the HTML for the chapter navigation buttons * * @since 5.0.0 + * @since 5.14.0 - Added indexed chapter IDs. * - * @param array $args['chapter_ids'] IDs of visible chapters in the same story or empty array. - * @param int|boolean $args['prev_index'] Index of previous chapter or false if outside bounds. - * @param int|boolean $args['next_index'] Index of next chapter or false if outside bounds. - * @param string $location Either 'top' or 'bottom'. + * @param array $args['chapter_ids'] IDs of visible chapters in the same story or empty array. + * @param array $args['indexed_chapter_ids'] IDs of accessible chapters in the same story or empty array. + * @param int|boolean $args['prev_index'] Index of previous chapter or false if outside bounds. + * @param int|boolean $args['next_index'] Index of next chapter or false if outside bounds. + * @param string $location Either 'top' or 'bottom'. */ function fictioneer_chapter_nav_buttons( $args, $location ) { @@ -257,7 +259,7 @@ function fictioneer_chapter_nav_buttons( $args, $location ) { // Start HTML ---> ?> - + @@ -265,7 +267,7 @@ function fictioneer_chapter_nav_buttons( $args, $location ) { - + post_password ) ? 'password' : ''; $title = fictioneer_get_safe_title( $post->ID, 'single-chapter' ); $age_rating = get_post_meta( $post->ID, 'fictioneer_chapter_rating', true ); @@ -64,6 +65,7 @@ get_header( null, $header_args ); if ( $story_post ) { $story_data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count! $chapter_ids = $story_data['chapter_ids']; + $indexed_chapters = $story_data['indexed_chapter_ids'] ?? $chapter_ids; if ( empty( $age_rating ) ) { $age_rating = $story_data['rating']; @@ -71,7 +73,7 @@ get_header( null, $header_args ); } // Chapter navigation - $current_index = array_search( $post->ID, $chapter_ids ); + $current_index = array_search( $post->ID, $indexed_chapters ); $prev_index = $current_index - 1; $next_index = $current_index + 1; @@ -84,13 +86,14 @@ get_header( null, $header_args ); 'chapter_title' => $title, 'chapter_password' => $post->post_password, 'chapter_ids' => $chapter_ids, + 'indexed_chapter_ids' => $indexed_chapters, 'current_index' => $current_index, 'prev_index' => $prev_index >= 0 ? $prev_index : false, - 'next_index' => isset( $chapter_ids[ $next_index ] ) ? $next_index : false + 'next_index' => isset( $indexed_chapters[ $next_index ] ) ? $next_index : false ); ?> - +