Replaced _story-comments.php partial with function

This commit is contained in:
Tetrakern 2024-04-15 23:03:33 +02:00
parent 1062d90fd2
commit 097de157be
3 changed files with 46 additions and 84 deletions

View File

@ -1029,7 +1029,7 @@ Fires right after the `<article>` container in the `single-fcn_story.php` templa
* $story_id (int) Current story (post) ID.
**Hooked actions:**
* `fictioneer_story_comment( $args )` AJAX-loaded list of all comments for story chapters. Priority 10.
* `fictioneer_story_comments( $args )` AJAX-loaded list of all comments for story chapters. Priority 10.
---
@ -1064,7 +1064,7 @@ Fires right after the article header (cover, title, fandom, genres, and characte
---
### `do_action( 'fictioneer_story_before_comments_list', $args )`
Fires right between the comments list and heading in the `_story-comments.php` partial.
Fires right between the comments list and heading in the `fictioneer_story_comments()` function.
**$args:**
* $story_data (array) Collection of story data.

View File

@ -796,20 +796,59 @@ add_action( 'fictioneer_story_after_content', 'fictioneer_story_blog', 44 );
* Outputs the HTML for the story page comments
*
* @since 5.0.0
* @since 5.14.0 - Merged partial into function.
*
* @param array $args['story_data'] Collection of story data.
* @param int $args['story_id'] The story post ID.
*/
function fictioneer_story_comment( $args ) {
function fictioneer_story_comments( $args ) {
// Setup
$story = $args['story_data'];
// Abort conditions...
if ( post_password_required() ) {
if ( post_password_required() || $story['comment_count'] < 1 ) {
return;
}
// Render partial
get_template_part( 'partials/_story-comments', null, $args );
// Start HTML ---> ?>
<section class="comment-section fictioneer-comments padding-left padding-right padding-bottom">
<h2 class="fictioneer-comments__title"><?php
printf(
_n(
'<span>%s</span> <span>Comment</span>',
'<span>%s</span> <span>Comments</span>',
$story['comment_count'],
'fictioneer'
),
$story['comment_count']
);
?></h2>
<?php do_action( 'fictioneer_story_before_comments_list', $args ); ?>
<div class="fictioneer-comments__list">
<ul>
<li class="load-more-list-item">
<button class="load-more-comments-button"><?php
$load_n = $story['comment_count'] < get_option( 'comments_per_page' ) ?
$story['comment_count'] : get_option( 'comments_per_page' );
printf(
_n(
'Load latest comment (may contain spoilers)',
'Load latest %s comments (may contain spoilers)',
$load_n,
'fictioneer'
),
$load_n
);
?></button>
</li>
<div class="comments-loading-placeholder hidden"><i class="fa-solid fa-spinner spinner"></i></div>
</ul>
</div>
</section>
<?php // <--- End HTML
}
add_action( 'fictioneer_story_after_article', 'fictioneer_story_comment', 10 );
add_action( 'fictioneer_story_after_article', 'fictioneer_story_comments', 10 );
?>

View File

@ -1,77 +0,0 @@
<?php
/**
* Partial: Story Comments
*
* Rendered just below the article block of the story, displaying the AJAX
* button to call a collection of all comments of all chapters. You cannot
* comment here though.
*
* @package WordPress
* @subpackage Fictioneer
* @since 4.7.0
* @see single-fcn_story.php
*
* @internal $args['story_data'] Story data from fictioneer_get_story_data().
* @internal $args['story_id'] Current story and post ID.
*/
?>
<?php
// No direct access!
defined( 'ABSPATH' ) OR exit;
// Setup
$story_id = $args['story_id'];
$story = $args['story_data'];
// Arguments for hooks and templates/etc.
$hook_args = array(
'story_data' => $story,
'story_id' => $story_id,
);
?>
<?php if ( $story['comment_count'] > 0 ) : ?>
<section class="comment-section fictioneer-comments padding-left padding-right padding-bottom">
<h2 class="fictioneer-comments__title"><?php
printf(
_n(
'<span>%s</span> <span>Comment</span>',
'<span>%s</span> <span>Comments</span>',
$story['comment_count'],
'fictioneer'
),
$story['comment_count']
);
?></h2>
<?php do_action( 'fictioneer_story_before_comments_list', $hook_args ); ?>
<div class="fictioneer-comments__list">
<ul>
<li class="load-more-list-item">
<button class="load-more-comments-button"><?php
$load_n = $story['comment_count'] < get_option( 'comments_per_page' ) ? $story['comment_count'] : get_option( 'comments_per_page' );
printf(
_n(
'Load latest comment (may contain spoilers)',
'Load latest %s comments (may contain spoilers)',
$load_n,
'fictioneer'
),
$load_n
);
?></button>
</li>
<div class="comments-loading-placeholder hidden"><i class="fa-solid fa-spinner spinner"></i></div>
</ul>
</div>
</section>
<?php endif; ?>