2023-01-21 01:31:34 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Template Part: Comments
|
|
|
|
*
|
|
|
|
* Renders the comment form and threads.
|
|
|
|
*
|
|
|
|
* @package WordPress
|
|
|
|
* @subpackage Fictioneer
|
2024-01-26 17:45:59 +01:00
|
|
|
* @since 4.7.0
|
2023-01-21 01:31:34 +01:00
|
|
|
*/
|
|
|
|
?>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
// Don't show the comments if the password has not been entered
|
2023-08-22 01:00:45 +02:00
|
|
|
if ( post_password_required() ) {
|
|
|
|
return;
|
|
|
|
}
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Setup
|
2023-12-02 00:00:13 +01:00
|
|
|
$post_id = get_the_ID();
|
2023-01-21 01:31:34 +01:00
|
|
|
$user = wp_get_current_user();
|
|
|
|
$comments_count = get_comments_number();
|
2024-04-24 12:17:08 +02:00
|
|
|
$order = fictioneer_sanitize_query_var( $_GET['corder'] ?? 0, ['desc', 'asc'], get_option( 'comment_order' ) );
|
2023-01-21 01:31:34 +01:00
|
|
|
$logout_url = fictioneer_get_logout_url( get_permalink() );
|
2024-03-09 19:18:36 +01:00
|
|
|
$is_ajax_comments = get_option( 'fictioneer_enable_ajax_comments' );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
?>
|
|
|
|
|
2024-04-24 00:58:48 +02:00
|
|
|
<div id="comments" class="fictioneer-comments scroll-margin-top" data-post-id="<?php echo $post_id; ?>" data-order="<?php echo $order; ?>" data-logout-url="<?php echo esc_url( $logout_url ); ?>" <?php echo $is_ajax_comments ? 'data-ajax-comments' : ''; ?>>
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( get_option( 'fictioneer_enable_ajax_comments' ) ) {
|
|
|
|
fictioneer_comments_ajax_skeleton( $comments_count ); // AJAX loading skeleton
|
|
|
|
} else {
|
|
|
|
// Query arguments
|
2024-04-24 00:58:48 +02:00
|
|
|
$query_args = array(
|
|
|
|
'post_id' => $post_id,
|
|
|
|
'order' => $order
|
|
|
|
);
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
if ( ! get_option( 'fictioneer_disable_comment_query' ) ) {
|
|
|
|
$query_args['type'] = ['comment', 'private'];
|
|
|
|
} else {
|
2023-02-14 03:41:34 +01:00
|
|
|
$query_args['type'] = ['comment'];
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Filter query arguments
|
2023-12-02 00:00:13 +01:00
|
|
|
$query_args = apply_filters( 'fictioneer_filter_comments_query', $query_args, $post_id );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Query comments
|
|
|
|
$comments_query = new WP_Comment_Query( $query_args );
|
|
|
|
$comments = $comments_query->comments;
|
|
|
|
|
|
|
|
// Filter comments
|
2023-12-02 00:00:13 +01:00
|
|
|
$comments = apply_filters( 'fictioneer_filter_comments', $comments, $post_id );
|
2023-01-21 01:31:34 +01:00
|
|
|
|
|
|
|
// Comments header
|
|
|
|
fictioneer_comment_header( $comments_count );
|
|
|
|
|
|
|
|
// Comment form
|
2024-01-09 18:44:37 +01:00
|
|
|
if ( ! fictioneer_is_commenting_disabled( $post_id ) ) {
|
2023-01-21 01:31:34 +01:00
|
|
|
if ( get_option( 'fictioneer_enable_ajax_comment_form' ) ) {
|
|
|
|
fictioneer_comments_ajax_form_skeleton();
|
|
|
|
} else {
|
|
|
|
comment_form();
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-29 21:46:28 +01:00
|
|
|
echo '<div class="fictioneer-comments__disabled">' . __( 'Commenting is disabled.', 'fictioneer' ) . '</div>';
|
2023-01-21 01:31:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Count all comments regardless of status
|
|
|
|
$count = count( $comments );
|
|
|
|
|
|
|
|
// Comment list
|
|
|
|
if (
|
|
|
|
have_comments() ||
|
|
|
|
( $count > 0 && user_can( $user, 'moderate_comments' ) ) ||
|
2023-12-15 17:51:09 +01:00
|
|
|
( $count > 0 && ! empty( $_GET['commentcode'] ?? 0 ) )
|
2023-01-21 01:31:34 +01:00
|
|
|
) {
|
|
|
|
// Start HTML ---> ?>
|
|
|
|
<ol class="fictioneer-comments__list commentlist">
|
|
|
|
<?php wp_list_comments( [], $comments ); ?>
|
|
|
|
</ol>
|
|
|
|
<?php // <--- End HTML
|
|
|
|
|
|
|
|
// Pagination
|
|
|
|
$pag_args = [];
|
|
|
|
|
|
|
|
if ( ! get_option( 'fictioneer_disable_comment_pagination' ) ) {
|
|
|
|
$pag_args['prev_text'] = fcntr( 'previous' );
|
|
|
|
$pag_args['next_text'] = fcntr( 'next' );
|
|
|
|
}
|
|
|
|
|
|
|
|
the_comments_pagination( $pag_args );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-22 01:00:45 +02:00
|
|
|
// Edit template
|
|
|
|
if (
|
|
|
|
get_option( 'fictioneer_enable_user_comment_editing' ) &&
|
|
|
|
! fictioneer_is_commenting_disabled()
|
|
|
|
) {
|
|
|
|
get_template_part( 'partials/_template_comment_edit' );
|
|
|
|
}
|
|
|
|
|
2023-01-21 01:31:34 +01:00
|
|
|
?>
|
|
|
|
</div>
|