From 60ed448e778c47657dd1b435d28c458ac5d6d686 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Thu, 9 May 2024 14:51:50 +0200 Subject: [PATCH] Improve chapter list item helper and added filter --- FILTERS.md | 15 +++++++++++++ includes/functions/_helpers-templates.php | 27 +++++++++++++---------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/FILTERS.md b/FILTERS.md index d0f949ef..31dda92b 100644 --- a/FILTERS.md +++ b/FILTERS.md @@ -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. diff --git a/includes/functions/_helpers-templates.php b/includes/functions/_helpers-templates.php index de3256f7..2ed4d194 100644 --- a/includes/functions/_helpers-templates.php +++ b/includes/functions/_helpers-templates.php @@ -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( - '