Improve chapter list item helper and added filter

This commit is contained in:
Tetrakern 2024-05-09 14:51:50 +02:00
parent 88c0ac10cf
commit 60ed448e77
2 changed files with 30 additions and 12 deletions

View File

@ -183,6 +183,21 @@ Filters the intermediate output array in the `_chapter-header.php` partial befor
---
### `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.
**Parameters:**
* $item (string) HTML for the list item with icon, ID, link, and title.
* $post (WP_Post) - The chapter post object.
**$args:**
* $title (string) HTML for the regular title.
* $list_title (string) HTML for the list title or empty.
* $icon (string) HTML for the (text) icon or empty.
* $classes (array) Array of CSS classes or empty.
---
### `apply_filters( 'fictioneer_filter_chapter_micro_menu', $micro_menu, $args )`
Filters the intermediate output array of the chapter micro menu in the `fictioneer_get_chapter_micro_menu( $args )` function before it is imploded and rendered.

View File

@ -1267,21 +1267,12 @@ if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) {
// Prepare
$classes = [];
$title = trim( $chapter->post_title );
$title = fictioneer_get_safe_title( $chapter->ID, 'get_chapter_list_items' );
$list_title = get_post_meta( $chapter->ID, 'fictioneer_chapter_list_title', true );
$list_title = trim( wp_strip_all_tags( $list_title ) );
$text_icon = get_post_meta( $chapter->ID, 'fictioneer_chapter_text_icon', true );
$icon = '';
// Check for empty title
if ( empty( $title ) && empty( $list_title ) ) {
$title = sprintf(
_x( '%1$s — %2$s', '[Date] — [Time] if chapter title is missing.', 'fictioneer' ),
get_the_date( '', $chapter->ID ),
get_the_time( '', $chapter->ID )
);
}
// Mark for password
if ( ! empty( $chapter->post_password ) ) {
$classes[] = 'has-password';
@ -1295,14 +1286,26 @@ if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) {
}
// HTML
$html .= sprintf(
'<li class="%s" data-id="%d"><a href="%s">%s<span>%s</span></a></li>',
$item = sprintf(
'<li class="%1$s" data-id="%2$s"><a href="%3$s">%4$s<span>%5$s</span></a></li>',
implode( ' ', $classes ),
$chapter->ID,
get_the_permalink( $chapter->ID ),
$icon,
$list_title ?: $title
);
$html .= apply_filters(
'fictioneer_filter_chapter_list_item',
$item,
$chapter,
array(
'title' => $title,
'list_title' => $list_title,
'icon' => $icon,
'classes' => $classes
)
);
}
// Update meta cache