| 1 |
<?php |
| 2 |
|
| 3 |
$post_ID = isset( $post_ID ) && ! empty( $post_ID ) ? intval( $post_ID ) : 0; |
| 4 |
$attributes = isset( $attributes ) && ! empty( $attributes ) ? (array) $attributes : array(); |
| 5 |
$ajax = isset( $ajax ) && ! empty( $ajax ); |
| 6 |
|
| 7 |
if ( ! empty( $post_ID ) ) { |
| 8 |
global $wp_rewrite; |
| 9 |
|
| 10 |
if ( ! comments_open( $post_ID ) && get_comments_number( $post_ID ) && post_type_supports( get_post_type( $post_ID ), 'comments' ) ) { |
| 11 |
esc_html_e( 'Comments for this post are not enabled.', 'qi-blocks' ); |
| 12 |
} elseif ( comments_open( $post_ID ) || get_comments_number( $post_ID ) ) { |
| 13 |
|
| 14 |
$comment_query = new WP_Comment_Query( |
| 15 |
qi_blocks_get_comments_list_args( $post_ID, $ajax ) |
| 16 |
); |
| 17 |
|
| 18 |
// Get an array of comments for the current post. |
| 19 |
$comments = ! empty( $comment_query ) ? $comment_query->get_comments() : 0; |
| 20 |
|
| 21 |
// Check visibility |
| 22 |
$comments_enabled = isset( $attributes['showCommentsList'] ) && ! empty( $attributes['showCommentsList'] ); |
| 23 |
$form_enabled = isset( $attributes['showCommentsForm'] ) && ! empty( $attributes['showCommentsForm'] ); |
| 24 |
|
| 25 |
// Set default title tag for sections title |
| 26 |
$title_tag = isset( $attributes['titleTag'] ) && ! empty( $attributes['titleTag'] ) ? $attributes['titleTag'] : 'h3'; |
| 27 |
|
| 28 |
// Include comments form template |
| 29 |
if ( $comments_enabled && count( $comments ) > 0 ) { |
| 30 |
$comments_number = get_comments_number( $post_ID ); |
| 31 |
$pagination_comments = $comments; |
| 32 |
|
| 33 |
if ( $ajax ) { |
| 34 |
$pagination_comments = ( new WP_Comment_Query( qi_blocks_get_comments_list_args( $post_ID ) ) )->get_comments(); |
| 35 |
} |
| 36 |
?> |
| 37 |
<div id="qodef-comments-list"> |
| 38 |
<<?php echo esc_attr( $title_tag ); ?> class="qodef-m-title"><?php |
| 39 |
echo esc_html( _n( 'Comment', 'Comments', $comments_number, 'qi-blocks' ) ); |
| 40 |
?></<?php echo esc_attr( $title_tag ); ?>> |
| 41 |
<ul class="qodef-m-comments"> |
| 42 |
<?php |
| 43 |
wp_list_comments( |
| 44 |
array( |
| 45 |
'callback' => 'qi_blocks_get_comments_list_template', |
| 46 |
), |
| 47 |
$comments |
| 48 |
); |
| 49 |
?> |
| 50 |
</ul> |
| 51 |
<?php |
| 52 |
// Include pagination comments template |
| 53 |
if ( get_comment_pages_count( $pagination_comments ) > 1 ) { ?> |
| 54 |
<div class="qodef-m-pagination qodef--wp"> |
| 55 |
<?php |
| 56 |
$pagination_args = array( |
| 57 |
'base' => add_query_arg( 'cpage', '%#%' ), |
| 58 |
'format' => '', |
| 59 |
'total' => get_comment_pages_count( $pagination_comments ), |
| 60 |
'current' => ! get_query_var( 'cpage' ) ? 1 : get_query_var( 'cpage' ), |
| 61 |
'add_fragment' => '#comments', |
| 62 |
'prev_text' => qi_blocks_get_svg_icon( 'icon-arrow-left' ), |
| 63 |
'next_text' => qi_blocks_get_svg_icon( 'icon-arrow-right' ), |
| 64 |
); |
| 65 |
|
| 66 |
if ( $wp_rewrite->using_permalinks() ) { |
| 67 |
$pagination_args['base'] = user_trailingslashit( trailingslashit( get_permalink() ) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged' ); |
| 68 |
} |
| 69 |
|
| 70 |
echo _navigation_markup( |
| 71 |
paginate_links( $pagination_args ), |
| 72 |
'comments-pagination', |
| 73 |
esc_html__( 'Comments navigation', 'qi-blocks' ), |
| 74 |
esc_html__( 'Comments', 'qi-blocks' ) |
| 75 |
); |
| 76 |
?> |
| 77 |
</div> |
| 78 |
<?php } ?> |
| 79 |
</div> |
| 80 |
<?php |
| 81 |
} |
| 82 |
|
| 83 |
// Include comments form template |
| 84 |
if ( $form_enabled ) { |
| 85 |
?> |
| 86 |
<div id="qodef-comments-form"> |
| 87 |
<?php |
| 88 |
comment_form( |
| 89 |
qi_blocks_get_comment_form_args( $attributes ), |
| 90 |
$post_ID |
| 91 |
); |
| 92 |
?> |
| 93 |
</div> |
| 94 |
<?php |
| 95 |
} |
| 96 |
} else { |
| 97 |
esc_html_e( 'Comments on this post are not allowed.', 'qi-blocks' ); |
| 98 |
} |
| 99 |
} |
| 100 |
|