Add status prefix to non-published chapter

This is only relevant if you show non-published chapters via filter on story pages.
This commit is contained in:
Tetrakern 2024-04-08 12:37:27 +02:00
parent 0988fd9eaf
commit 9eb4097a84
2 changed files with 46 additions and 1 deletions

View File

@ -244,3 +244,42 @@ function child_update_chapter_formatting_defaults( $formatting ) {
} }
add_filter( 'fictioneer_filter_chapter_default_formatting', 'child_update_chapter_formatting_defaults' ); add_filter( 'fictioneer_filter_chapter_default_formatting', 'child_update_chapter_formatting_defaults' );
``` ```
## Show scheduled chapters on story pages
If the "Next Chapter" note above the chapter list is not enough and you want to show scheduled (future) chapters in the list as well, you can alter the query via filter. You can also include other post statuses, although the sense of that is dubious. Note that this will not alter the [API responses](https://github.com/Tetrakern/fictioneer/blob/main/API.md), because they needs to be uniform across all sites.
**References**
* Filter: [fictioneer_filter_story_chapter_posts_query](FILTERS.md#apply_filters-fictioneer_filter_story_chapter_posts_query-query_args-story_id-chapter_ids-)
```php
/**
* Show scheduled (future) chapter in story chapter list
*
* @since x.x.x
*
* @param array $query_args Chapter list query arguments.
*
* @return array The updated chapter list query arguments.
*/
function child_show_scheduled_chapters( $query_args ) {
$query_args['post_status'] = ['publish', 'future'];
return $query_args;
}
add_filter( 'fictioneer_filter_story_chapter_posts_query', 'child_show_scheduled_chapters' );
// If you want to remove the "Next Chapter" note above the list:
/**
* Remove "Next Chapter" note above list
*
* @since x.x.x
*/
function child_remove_scheduled_chapter() {
remove_action( 'fictioneer_story_after_content', 'fictioneer_story_scheduled_chapter', 41 );
}
add_action( 'wp', 'child_remove_scheduled_chapter', 11 ); // The action is added late, so you need to be even later
```

View File

@ -558,6 +558,7 @@ function fictioneer_story_chapters( $args ) {
$chapter_groups[ $group_key ]['data'][] = array( $chapter_groups[ $group_key ]['data'][] = array(
'id' => $chapter_id, 'id' => $chapter_id,
'status' => $post->post_status,
'link' => get_permalink(), 'link' => get_permalink(),
'timestamp' => get_the_time( 'c' ), 'timestamp' => get_the_time( 'c' ),
'password' => ! empty( $post->post_password ), 'password' => ! empty( $post->post_password ),
@ -614,7 +615,7 @@ function fictioneer_story_chapters( $args ) {
<?php foreach ( $group['data'] as $chapter ) : ?> <?php foreach ( $group['data'] as $chapter ) : ?>
<?php <?php
$index++; $index++;
$extra_classes = ''; $extra_classes = "_{$chapter['status']} ";
// Must account for extra toggle row and start at 1 // Must account for extra toggle row and start at 1
$is_folded = $chapter_folding && $index > FICTIONEER_CHAPTER_FOLDING_THRESHOLD && $is_folded = $chapter_folding && $index > FICTIONEER_CHAPTER_FOLDING_THRESHOLD &&
@ -659,6 +660,11 @@ function fictioneer_story_chapters( $args ) {
class="chapter-group__list-item-link truncate _1-1 <?php echo $chapter['password'] ? '_password' : ''; ?>" class="chapter-group__list-item-link truncate _1-1 <?php echo $chapter['password'] ? '_password' : ''; ?>"
><?php ><?php
// Non-published chapter prefixes
if ( in_array( $chapter['status'], ['future', 'trash', 'private'] ) ) {
echo '<span class="chapter-group__list-item-status">' . fcntr( "{$chapter['status']}_prefix" ) . '</span> ';
}
if ( ! empty( $chapter['prefix'] ) ) { if ( ! empty( $chapter['prefix'] ) ) {
// Mind space between prefix and title // Mind space between prefix and title
echo apply_filters( 'fictioneer_filter_list_chapter_prefix', $chapter['prefix'] ) . ' '; echo apply_filters( 'fictioneer_filter_list_chapter_prefix', $chapter['prefix'] ) . ' ';