Add FICTIONEER_LIST_SCHEDULED_CHAPTERS

This commit is contained in:
Tetrakern 2024-10-18 02:22:54 +02:00
parent 27f25a18ac
commit 520c748f55
3 changed files with 55 additions and 1 deletions

View File

@ -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.

View File

@ -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
// =============================================================================

View File

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