Comments are closed to inc/custom-comments.php

Uses the comment_form_comments_closed hook to display the comments close note.
This commit is contained in:
IanDelMar 2020-04-19 00:24:25 +02:00
parent e4cf59e251
commit 59ed94cb34
2 changed files with 34 additions and 24 deletions

View File

@ -38,16 +38,18 @@ if ( post_password_required() ) {
'<span>' . get_the_title() . '</span>'
);
} else {
printf( // WPCS: XSS OK.
/* translators: 1: number of comments, 2: post title */
esc_html( _nx(
'%1$s thought on &ldquo;%2$s&rdquo;',
'%1$s thoughts on &ldquo;%2$s&rdquo;',
$comments_number,
'comments title',
'understrap'
) ),
number_format_i18n( $comments_number ),
printf(
esc_html(
/* translators: 1: number of comments, 2: post title */
_nx(
'%1$s thought on &ldquo;%2$s&rdquo;',
'%1$s thoughts on &ldquo;%2$s&rdquo;',
$comments_number,
'comments title',
'understrap'
)
),
number_format_i18n( '$comments_number' ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'<span>' . get_the_title() . '</span>'
);
}
@ -55,7 +57,7 @@ if ( post_password_required() ) {
</h2><!-- .comments-title -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through. ?>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through. ?>
<nav class="comment-navigation" id="comment-nav-above">
@ -75,7 +77,7 @@ if ( post_password_required() ) {
</nav><!-- #comment-nav-above -->
<?php endif; // check for comment navigation. ?>
<?php endif; // Check for comment navigation. ?>
<ol class="comment-list">
@ -90,7 +92,7 @@ if ( post_password_required() ) {
</ol><!-- .comment-list -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // are there comments to navigate through. ?>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through. ?>
<nav class="comment-navigation" id="comment-nav-below">
@ -110,18 +112,9 @@ if ( post_password_required() ) {
</nav><!-- #comment-nav-below -->
<?php endif; // check for comment navigation. ?>
<?php endif; // Check for comment navigation. ?>
<?php endif; // endif have_comments(). ?>
<?php
// If comments are closed and there are comments, let's leave a little note, shall we?
if ( ! comments_open() && '0' != get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'understrap' ); ?></p>
<?php endif; ?>
<?php endif; // End of if have_comments(). ?>
<?php comment_form(); // Render comments form. ?>

View File

@ -87,3 +87,20 @@ if ( ! function_exists( 'understrap_bootstrap_comment_form' ) ) {
return $args;
}
} // End of if function_exists( 'understrap_bootstrap_comment_form' ).
// Add note if comments are closed.
add_action( 'comment_form_comments_closed', 'understrap_comment_form_comments_closed' );
if ( ! function_exists( 'understrap_comment_form_comments_closed' ) ) {
/**
* Displays a note that comments are closed if comments are closed and there are comments.
*/
function understrap_comment_form_comments_closed() {
if ( get_comments_number() && post_type_supports( get_post_type(), 'comments' ) ) {
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'understrap' ); ?></p>
<?php
}
}
} // End of if function_exists( 'understrap_comment_form_comments_closed' ).