Add fictioneer_get_simple_chapter_list_items()

This commit is contained in:
Tetrakern 2024-10-08 12:54:12 +02:00
parent c73e64eb5e
commit 05eb45d88b
3 changed files with 40 additions and 3 deletions

View File

@ -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.

View File

@ -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 ) {

View File

@ -93,7 +93,7 @@ get_header(
<?php if ( $story_post && $indexed_chapters ): ?>
<div id="story-chapter-list" class="hidden" data-story-id="<?php echo $story_id; ?>">
<ul data-current-id="<?php echo $post_id; ?>"><?php
echo fictioneer_get_chapter_list_items( $story_id, $story_data, $current_index );
echo fictioneer_get_simple_chapter_list_items( $story_id, $story_data, $current_index );
?></ul>
</div>
<?php endif; ?>