From 05eb45d88b999b658ee3e38e3997deffcc1f5fe4 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Tue, 8 Oct 2024 12:54:12 +0200 Subject: [PATCH] Add fictioneer_get_simple_chapter_list_items() --- FILTERS.md | 17 ++++++++++++++-- includes/functions/_helpers-templates.php | 24 +++++++++++++++++++++++ single-fcn_chapter.php | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/FILTERS.md b/FILTERS.md index 947bfe75..6cdb0c57 100644 --- a/FILTERS.md +++ b/FILTERS.md @@ -265,17 +265,30 @@ Filters the intermediate output array in the `_chapter-header.php` partial befor --- +### `apply_filters( 'fictioneer_filter_simple_chapter_list_items_statuses', $statuses, $story_id )` ### `apply_filters( 'fictioneer_filter_chapter_list_statuses', $statuses, $story_id )` -Filters the list of allowed chapter statuses during building chapter lists in the `function fictioneer_get_chapter_list_items()` function. By default, only `['publish']` chapters are shown. +Filters the array of allowed chapter statuses when building the simple chapter list items in the `function fictioneer_get_simple_chapter_list_items()` function. By default, only `['publish']` chapters are shown. + +**Note:** `fictioneer_filter_chapter_list_statuses` is deprecated as of 5.25.0. **Parameters:** * $statuses (array) – Array of chapter statuses. * $story_id (int) – Post ID of the story. +**Example:** +```php +function child_add_scheduled_chapters_to_simple_list_items( $statuses ) { + $statuses[] = 'future'; + + return $statuses; +} +add_filter( 'fictioneer_filter_simple_chapter_list_items_statuses', 'child_add_scheduled_chapters_to_simple_list_items' ); +``` + --- ### `apply_filters( 'fictioneer_filter_chapter_list_item', $item, $post, $args )` -Filters each list item HTML string used in the chapter index popup and mobile menu section (only visible on chapter pages), build inside the `fictioneer_get_chapter_list_items()` function. Not to be confused with the chapter list shown on story pages. You can either modify the string or build a new one from the given parameters. +Filters each list item HTML string used in the chapter index popup and mobile menu section (only visible on chapter pages), build inside the `fictioneer_get_simple_chapter_list_items()` function. Not to be confused with the chapter list shown on story pages. You can either modify the string or build a new one from the given parameters. **Parameters:** * $item (string) – HTML for the list item with icon, ID, link, and title. diff --git a/includes/functions/_helpers-templates.php b/includes/functions/_helpers-templates.php index 675dbc05..d800f72c 100644 --- a/includes/functions/_helpers-templates.php +++ b/includes/functions/_helpers-templates.php @@ -1246,6 +1246,8 @@ if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) { /** * Returns the HTML for chapter list items with icon and link * + * @deprecated 5.25.0 + * * @since 5.0.0 * @since 5.9.3 - Added meta field caching. * @since 5.9.4 - Removed output buffer. @@ -1260,6 +1262,27 @@ if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) { */ function fictioneer_get_chapter_list_items( $story_id, $data, $current_index ) { + return fictioneer_get_simple_chapter_list_items( $story_id, $data, $current_index ); + } +} + +if ( ! function_exists( 'fictioneer_get_simple_chapter_list_items' ) ) { + /** + * Returns the HTML for chapter list items with icon and link + * + * Alias: For legacy purposes, the fictioneer_get_chapter_list_items() + * is kept as alias for now but should no longer be used. + * + * @since 5.25.0 - Replaces fictioneer_get_chapter_list_items() + * + * @param int $story_id ID of the story. + * @param array $data Prepared data of the story. + * @param int $current_index Index in chapter ID array. + * + * @return string HTML list of chapters. + */ + + function fictioneer_get_simple_chapter_list_items( $story_id, $data, $current_index ) { // Meta cache? $cache_plugin_active = fictioneer_caching_active( 'chapter_list_items' ); @@ -1283,6 +1306,7 @@ if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) { $hide_icons = get_post_meta( $story_id, 'fictioneer_story_hide_chapter_icons', true ) || get_option( 'fictioneer_hide_chapter_icons' ); $html = ''; $allowed_statuses = apply_filters( 'fictioneer_filter_chapter_list_statuses', ['publish'], $story_id ); + $allowed_statuses = apply_filters( 'fictioneer_filter_simple_chapter_list_items_statuses', $allowed_statuses, $story_id ); // Loop chapters... foreach ( $chapters as $chapter ) { diff --git a/single-fcn_chapter.php b/single-fcn_chapter.php index d7916ea1..e7ca0b97 100644 --- a/single-fcn_chapter.php +++ b/single-fcn_chapter.php @@ -93,7 +93,7 @@ get_header(