Filter and improve chapter icon output

This commit is contained in:
Tetrakern 2024-05-23 20:16:39 +02:00
parent afa1270d72
commit d952c7011e
3 changed files with 36 additions and 10 deletions

View File

@ -170,6 +170,16 @@ Filters the default chapter formatting settings. The passed array is empty becau
---
### `apply_filters( 'fictioneer_filter_chapter_icon', $icon_html, $chapter_id, $story_id )`
Filters the HTML of the chapter icon before it is rendered.
**Parameters:**
* $icon_html (string) HTML for the chapter icon.
* $chapter_id (int) Post ID of the chapter.
* $story_id (int|null) Post ID of the story (if any). Unsafe.
---
### `apply_filters( 'fictioneer_filter_chapter_identity', $output, $args )`
Filters the intermediate output array in the `_chapter-header.php` partial before it is imploded and rendered. Contains the HTML for the story link, chapter title (safe), and author meta nodes (see `fictioneer_get_chapter_author_nodes()`). Any of these items may be missing depending on the chapters configuration.

View File

@ -1080,11 +1080,19 @@ function fictioneer_shortcode_chapter_list( $attr ) {
// Start HTML ---> ?>
<li class="chapter-group__list-item <?php echo $extra_classes; ?>" data-post-id="<?php echo $chapter_id; ?>">
<?php if ( ! empty( $text_icon ) && ! $hide_icons ) : ?>
<span class="chapter-group__list-item-icon _text text-icon"><?php echo $text_icon; ?></span>
<?php elseif ( ! $hide_icons ) : ?>
<i class="<?php echo empty( $icon ) ? 'fa-solid fa-book' : $icon; ?> chapter-group__list-item-icon"></i>
<?php endif; ?>
<?php
if ( ! $hide_icons ) {
// Text icon overrides normal icon
if ( $text_icon ) {
$icon = "<span class='chapter-group__list-item-icon _text text-icon'>{$text_icon}</span>";
} else {
$icon = $icon ?: 'fa-solid fa-book';
$icon = "<i class='{$icon} chapter-group__list-item-icon'></i>";
}
echo apply_filters( 'fictioneer_filter_chapter_icon', $icon, $chapter_id, $story_id );
}
?>
<a
href="<?php the_permalink( $chapter_id ); ?>"

View File

@ -651,11 +651,19 @@ function fictioneer_story_chapters( $args ) {
style="order: <?php echo $reverse_order - $index; ?>"
>
<?php if ( ! empty( $chapter['text_icon'] ) && ! $hide_icons ) : ?>
<span class="chapter-group__list-item-icon _text text-icon"><?php echo $chapter['text_icon']; ?></span>
<?php elseif ( ! $hide_icons ) : ?>
<i class="<?php echo empty( $chapter['icon'] ) ? 'fa-solid fa-book' : $chapter['icon']; ?> chapter-group__list-item-icon"></i>
<?php endif; ?>
<?php
if ( ! $hide_icons ) {
// Text icon overrides normal icon
if ( $chapter['text_icon'] ) {
$icon = "<span class='chapter-group__list-item-icon _text text-icon'>{$chapter['text_icon']}</span>";
} else {
$icon = $chapter['icon'] ?: 'fa-solid fa-book';
$icon = "<i class='{$icon} chapter-group__list-item-icon'></i>";
}
echo apply_filters( 'fictioneer_filter_chapter_icon', $icon, $chapter['id'], $story_id );
}
?>
<a
<?php echo $chapter['link'] ? "href='{$chapter['link']}'" : ''; ?>