Account for unpublished story parent or chapter

This commit is contained in:
Tetrakern 2023-08-17 16:39:31 +02:00
parent 5deeb29991
commit ef00a51301
3 changed files with 57 additions and 12 deletions

View File

@ -198,6 +198,13 @@ add_action( 'fictioneer_chapter_actions_top_left', 'fictioneer_chapter_resize_bu
*/
function fictioneer_chapter_nav_buttons( $args, $location ) {
$post_status = get_post_status( get_the_ID() );
// Do not render on hidden posts
if ( $post_status !== 'publish' ) {
return;
}
// Start HTML ---> ?>
<?php if ( $args['prev_index'] !== false ) : ?>
<a href="<?php echo get_permalink( $args['chapter_ids'][ $args['prev_index'] ] ); ?>" title="<?php echo get_the_title( $args['chapter_ids'][ $args['prev_index'] ] ); ?>" class="button _secondary _navigation _prev"><?php echo fcntr( 'previous' ) ?></a>
@ -251,6 +258,12 @@ add_action( 'fictioneer_chapter_actions_top_center', 'fictioneer_chapter_formatt
function fictioneer_chapter_subscribe_button() {
$subscribe_buttons = fictioneer_get_subscribe_options();
$post_status = get_post_status( get_the_ID() );
// Do not render on hidden posts
if ( $post_status !== 'publish' ) {
return;
}
if ( ! empty( $subscribe_buttons ) ) {
// Start HTML ---> ?>
@ -290,7 +303,7 @@ function fictioneer_chapter_fullscreen_buttons() {
add_action( 'fictioneer_chapter_actions_top_center', 'fictioneer_chapter_fullscreen_buttons', 20 );
// =============================================================================
// CHAPTER BACK TO STORY BUTTON
// CHAPTER INDEX POPUP MENU
// =============================================================================
/**
@ -302,8 +315,17 @@ add_action( 'fictioneer_chapter_actions_top_center', 'fictioneer_chapter_fullscr
*/
function fictioneer_chapter_index_popup_menu( $args ) {
// Abort if...
if ( ! $args['story_post'] ) return;
$post_status = get_post_status( get_the_ID() );
// Do not render on hidden posts
if ( $post_status !== 'publish' ) {
return;
}
// Abort if there is no story assigned
if ( ! $args['story_post'] ) {
return;
}
// Start HTML ---> ?>
<div id="chapter-list-popup-toggle" class="toggle-last-clicked button _secondary popup-menu-toggle tooltipped" tabindex="0" role="button" data-tooltip="<?php esc_attr_e( 'Index', 'fictioneer' ); ?>" aria-label="<?php esc_attr_e( 'Index', 'fictioneer' ); ?>">
@ -356,6 +378,13 @@ add_action( 'fictioneer_chapter_actions_bottom_center', 'fictioneer_chapter_book
*/
function fictioneer_chapter_media_buttons() {
$post_status = get_post_status( get_the_ID() );
// Do not render on hidden posts
if ( $post_status !== 'publish' ) {
return;
}
get_template_part( 'partials/_share-buttons' );
}
add_action( 'fictioneer_chapter_actions_bottom_left', 'fictioneer_chapter_media_buttons', 10 );

View File

@ -10,18 +10,28 @@
* @since 5.0
* @see single-fcn_chapter.php
*
* @internal $args['story_post'] Optional. Post object of the story.
* @internal $args['story_data'] Optional. Story data from fictioneer_get_story_data().
* @internal $args['chapter_id'] The chapter ID.
* @internal $args['chapter_title'] Safe chapter title.
* @internal $args['chapter_password'] Chapter password or empty string.
* @internal $args['story_post'] Optional. Post object of the story.
* @internal $args['story_data'] Optional. Story data from fictioneer_get_story_data().
* @internal $args['chapter_id'] The chapter ID.
* @internal $args['chapter_title'] Safe chapter title.
* @internal $args['chapter_password'] Chapter password or empty string.
*/
?>
<?php
$story_visible = $args['story_post'] &&
! empty( $args['story_data']['title'] ) &&
get_post_status( $args['story_post']->ID ) === 'publish';
?>
<header class="chapter__headline layout-links">
<?php if ( $args['story_post'] && ! empty( $args['story_data']['title'] ) ) : ?>
<a href="<?php echo get_the_permalink( $args['story_post']->ID ); ?>"><?php echo $args['story_data']['title']; ?></a>
<?php if ( $story_visible ) : ?>
<a href="<?php the_permalink( $args['story_post']->ID ); ?>"><?php echo $args['story_data']['title']; ?></a>
<?php endif; ?>
<?php if ( ! fictioneer_get_field( 'fictioneer_chapter_hide_title' ) ) : ?>
<h1 class="chapter__title<?php if ( ! empty( $args['chapter_password'] ) ) echo ' password'; ?>"><?php echo $args['chapter_title']; ?></h1>
<em class="chapter__author"><?php
@ -31,4 +41,5 @@
);
?></em>
<?php endif; ?>
</header>

View File

@ -54,13 +54,18 @@ if (
<?php
// Setup
$story_data = null;
$story_post = null;
$story_id = fictioneer_get_field( 'fictioneer_chapter_story' );
$story_post = empty( $story_id ) ? null : get_post( $story_id );
$chapter_ids = [];
$password_class = ! empty( $post->post_password ) ? 'password' : '';
$title = fictioneer_get_safe_title( get_the_ID() );
$this_breadcrumb = [$title, get_the_permalink()];
// Story published?
if ( ! empty( $story_id ) && get_post_status( $story_id ) === 'publish' ) {
$story_post = empty( $story_id ) ? null : get_post( $story_id );
}
// Story data
if ( $story_post ) {
$story_data = fictioneer_get_story_data( $story_id, false ); // Does not refresh comment count!
@ -83,7 +88,7 @@ if (
'chapter_ids' => $chapter_ids,
'current_index' => $current_index,
'prev_index' => $prev_index >= 0 ? $prev_index : false,
'next_index' => isset( $chapter_ids[$next_index] ) ? $next_index : false
'next_index' => isset( $chapter_ids[ $next_index ] ) ? $next_index : false
);
?>