Add and use fictioneer_footer hook

Also clean up a bit.
This commit is contained in:
Tetrakern 2023-08-03 19:56:25 +02:00
parent fefa1d762c
commit 9ea007437c
2 changed files with 26 additions and 11 deletions

View File

@ -14,8 +14,8 @@
* @see partials/_consent-banner.php
* @see wp_footer()
*
* @internal $args['post_type'] Current post type or null.
* @internal $args['post_id'] Current post ID or null.
* @internal $args['post_type'] Current post type or null.
* @internal $args['breadcrumbs'] Array of breadcrumb tuples with label (0) and link (1).
*/
?>
@ -30,16 +30,24 @@
</div> <!-- .site -->
<?php
// Null post ID for generated pages
if ( is_archive() || is_search() || is_404() ) {
$args['post_id'] = null;
}
// Render TTS interface if required
if (
get_post_type() == 'fcn_chapter' &&
! empty( $args['post_id'] ) &&
$args['post_type'] == 'fcn_chapter' &&
! post_password_required()
) {
get_template_part( 'partials/_tts-interface' );
}
// Render cookie banner HTML if required
if ( get_option( 'fictioneer_cookie_banner' ) ) get_template_part( 'partials/_consent-banner' );
if ( get_option( 'fictioneer_cookie_banner' ) ) {
get_template_part( 'partials/_consent-banner' );
}
?>
<?php /* Adding the AJAX nonce this way allows caching plugins to update it dynamically. */ ?>
@ -51,6 +59,9 @@
echo '<div id="fictioneer-lightbox" class="lightbox"><button type="button" class="lightbox__close" aria-label="' . esc_attr__( 'Close lightbox', 'fictioneer' ) . '">' . fictioneer_get_icon( 'fa-xmark' ) . '</button><i class="fa-solid fa-spinner fa-spin loader" style="--fa-animation-duration: .8s;"></i><div class="lightbox__content target"></div></div>';
}
// Fictioneer footer hook
do_action( 'fictioneer_footer', $args );
// WordPress footer hook (includes modals)
wp_footer();
?>

View File

@ -105,17 +105,16 @@ if ( ! function_exists( 'fictioneer_output_modals' ) ) {
/**
* Outputs the HTML for the modals
*
* @since Fictioneer 5.0
* @since Fictioneer 5.0.0
*
* @param int|null $args['post_id'] Current post ID or null.
* @param int|null $args['story_id'] Current story ID (if chapter) or null.
* @param string|boolean $args['header_image_url'] URL of the filtered header image or false.
* @param array $args['header_args'] Arguments passed to the header.php partial.
* @param string|null $args['post_type'] Current post type or null.
* @param array $args['breadcrumbs'] Array of breadcrumb tuples with label (0) and link (1).
*/
function fictioneer_output_modals( $args ) {
// Formatting and suggestions
if ( get_post_type() == 'fcn_chapter' ) {
if ( ! empty( $args['post_id'] ) && $args['post_type'] == 'fcn_chapter' ) {
?><input id="modal-formatting-toggle" data-target="formatting-modal" type="checkbox" tabindex="-1" class="modal-toggle" autocomplete="off" hidden><?php
get_template_part( 'partials/_modal-formatting' );
@ -147,7 +146,12 @@ if ( ! function_exists( 'fictioneer_output_modals' ) ) {
get_template_part( 'partials/_modal-site-settings' );
// BBCodes tutorial
if ( ! post_password_required() && comments_open() && ! fictioneer_is_commenting_disabled() ) {
if (
! empty( $args['post_id'] ) &&
! post_password_required() &&
comments_open() &&
! fictioneer_is_commenting_disabled()
) {
?><input id="modal-bbcodes-toggle" data-target="bbcodes-modal" type="checkbox" tabindex="-1" class="modal-toggle" autocomplete="off" hidden><?php
get_template_part( 'partials/_modal-bbcodes' );
}
@ -156,7 +160,7 @@ if ( ! function_exists( 'fictioneer_output_modals' ) ) {
do_action( 'fictioneer_modals' );
}
}
add_action( 'wp_footer', 'fictioneer_output_modals' );
add_action( 'fictioneer_footer', 'fictioneer_output_modals' );
// =============================================================================
// OUTPUT NAVIGATION BAR