Skip to content

Commit

Permalink
Add fictioneer_get_simple_chapter_list_items()
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetrakern committed Oct 8, 2024
1 parent c73e64e commit 05eb45d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
17 changes: 15 additions & 2 deletions FILTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions includes/functions/_helpers-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -1246,6 +1246,8 @@ function fictioneer_get_chapter_micro_menu( $args ) {
/**
* 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.
Expand All @@ -1260,6 +1262,27 @@ function fictioneer_get_chapter_micro_menu( $args ) {
*/

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' );

Expand All @@ -1283,6 +1306,7 @@ function fictioneer_get_chapter_list_items( $story_id, $data, $current_index ) {
$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 ) {
Expand Down
2 changes: 1 addition & 1 deletion single-fcn_chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<?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; ?>
Expand Down

0 comments on commit 05eb45d

Please sign in to comment.