From 520c748f55a78ab2f2b62e8a99ac577c09023d85 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Fri, 18 Oct 2024 02:22:54 +0200 Subject: [PATCH] Add FICTIONEER_LIST_SCHEDULED_CHAPTERS --- INSTALLATION.md | 1 + functions.php | 5 +++ includes/functions/_helpers-templates.php | 50 ++++++++++++++++++++++- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/INSTALLATION.md b/INSTALLATION.md index 27b601f6..b47d24cf 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -1609,4 +1609,5 @@ define( 'CONSTANT_NAME', value ); | FICTIONEER_DEFER_SCRIPTS | boolean | Whether to defer scripts or load them in the footer. Default `true`. | FICTIONEER_ENABLE_ASYNC_ONLOAD_PATTERN | boolean | Whether the [onload pattern](https://www.filamentgroup.com/lab/load-css-simpler/) for asynchronous CSS loading is used. Default `true`. | FICTIONEER_SHOW_LATEST_CHAPTERS_ON_STORY_CARDS | boolean | Whether to show the latest instead of the first chapters on story cards. Default `false`. +| FICTIONEER_LIST_SCHEDULED_CHAPTERS | boolean | Whether to show scheduled chapters in lists. Default `false`. | FICTIONEER_EXAMPLE_CHAPTER_ICONS | array | Collection of example Font Awesome icon class strings. diff --git a/functions.php b/functions.php index fc08339e..5b46f12c 100644 --- a/functions.php +++ b/functions.php @@ -439,6 +439,11 @@ if ( ! defined( 'FICTIONEER_ENABLE_MENU_TRANSIENTS' ) ) { ); } +// Boolean: Whether to show scheduled chapters in lists +if ( ! defined( 'FICTIONEER_LIST_SCHEDULED_CHAPTERS' ) ) { + define( 'FICTIONEER_LIST_SCHEDULED_CHAPTERS', false ); +} + // ============================================================================= // GLOBAL // ============================================================================= diff --git a/includes/functions/_helpers-templates.php b/includes/functions/_helpers-templates.php index 3d6fc853..9f366aca 100644 --- a/includes/functions/_helpers-templates.php +++ b/includes/functions/_helpers-templates.php @@ -1294,7 +1294,6 @@ function fictioneer_get_chapter_index_array( $story_id ) { $allowed_statuses = apply_filters( 'fictioneer_filter_chapter_index_list_statuses', $allowed_statuses, $story_id ); $hide_icons = get_post_meta( $story_id, 'fictioneer_story_hide_chapter_icons', true ) || get_option( 'fictioneer_hide_chapter_icons' ); - $html = ''; $position = 0; // Loop chapters... @@ -2649,3 +2648,52 @@ function fictioneer_get_splide_placeholders( $uid = null, $ttb = false ) { return apply_filters( 'fictioneer_filter_splide_placeholders', '', $uid, $ttb ); } + +// ============================================================================= +// LIST SCHEDULED CHAPTERS +// ============================================================================= + +/** + * Shows scheduled (future) chapter in story chapter list + * + * @since 5.25.0 + * + * @param array $query_args Chapter list query arguments. + * + * @return array The updated chapter list query arguments. + */ + +function fictioneer_show_scheduled_chapters( $query_args ) { + $query_args['post_status'] = ['publish', 'future']; + + return $query_args; +} + +if ( FICTIONEER_LIST_SCHEDULED_CHAPTERS ) { + add_filter( 'fictioneer_filter_story_chapter_posts_query', 'fictioneer_show_scheduled_chapters' ); +} + +/** + * Adds the 'future' post status to an allowed statuses array + * + * @since 5.25.0 + * + * @param string[] $statuses Statuses that are queried. Default ['publish]. + * + * @return array The updated array of statuses. + */ + +function fictioneer_treat_scheduled_chapters_as_published( $statuses ) { + $statuses[] = 'future'; + + return $statuses; +} + +if ( FICTIONEER_LIST_SCHEDULED_CHAPTERS ) { + add_filter( 'fictioneer_filter_chapter_index_list_statuses', 'fictioneer_treat_scheduled_chapters_as_published' ); + add_filter( 'fictioneer_filter_chapter_nav_buttons_allowed_statuses', 'fictioneer_treat_scheduled_chapters_as_published' ); + add_filter( 'fictioneer_filter_get_story_data_queried_chapter_statuses', 'fictioneer_treat_scheduled_chapters_as_published' ); + add_filter( 'fictioneer_filter_get_story_data_indexed_chapter_statuses', 'fictioneer_treat_scheduled_chapters_as_published' ); + add_filter( 'fictioneer_filter_allowed_chapter_permalinks', 'fictioneer_treat_scheduled_chapters_as_published' ); + add_action( 'fictioneer_filter_chapters_added_statuses', 'fictioneer_treat_scheduled_chapters_as_published' ); +}