mirror of
https://github.com/WordPress/WordPress.git
synced 2024-10-31 07:49:38 +01:00
1ce5dc7444
`str_contains()` was introduced in PHP 8.0 to perform a case-sensitive check indicating if the string to search in (haystack) contains the given substring (needle). WordPress core includes a polyfill for `str_contains()` on PHP < 8.0 as of WordPress 5.9. This commit replaces `false !== strpos( ... )` with `str_contains()` in core files, making the code more readable and consistent, as well as better aligned with modern development practices. Follow-up to [52039], [52040], [52326], [55703], [55710], [55987]. Props Soean, spacedmonkey, costdev, dingo_d, azaozz, mikeschroder, flixos90, peterwilsoncc, SergeyBiryukov. Fixes #58206. Built from https://develop.svn.wordpress.org/trunk@55988 git-svn-id: http://core.svn.wordpress.org/trunk@55500 1a063a9b-81f0-0310-95a4-ce76da25c4cd
133 lines
3.1 KiB
PHP
133 lines
3.1 KiB
PHP
<?php
|
|
/**
|
|
* The template file for displaying the comments and comment form for the
|
|
* Twenty Twenty theme.
|
|
*
|
|
* @package WordPress
|
|
* @subpackage Twenty_Twenty
|
|
* @since Twenty Twenty 1.0
|
|
*/
|
|
|
|
/*
|
|
* If the current post is protected by a password and
|
|
* the visitor has not yet entered the password we will
|
|
* return early without loading the comments.
|
|
*/
|
|
if ( post_password_required() ) {
|
|
return;
|
|
}
|
|
|
|
if ( $comments ) {
|
|
?>
|
|
|
|
<div class="comments" id="comments">
|
|
|
|
<?php
|
|
$comments_number = get_comments_number();
|
|
?>
|
|
|
|
<div class="comments-header section-inner small max-percentage">
|
|
|
|
<h2 class="comment-reply-title">
|
|
<?php
|
|
if ( ! have_comments() ) {
|
|
_e( 'Leave a comment', 'twentytwenty' );
|
|
} elseif ( '1' === $comments_number ) {
|
|
/* translators: %s: Post title. */
|
|
printf( _x( 'One reply on “%s”', 'comments title', 'twentytwenty' ), get_the_title() );
|
|
} else {
|
|
printf(
|
|
/* translators: 1: Number of comments, 2: Post title. */
|
|
_nx(
|
|
'%1$s reply on “%2$s”',
|
|
'%1$s replies on “%2$s”',
|
|
$comments_number,
|
|
'comments title',
|
|
'twentytwenty'
|
|
),
|
|
number_format_i18n( $comments_number ),
|
|
get_the_title()
|
|
);
|
|
}
|
|
|
|
?>
|
|
</h2><!-- .comments-title -->
|
|
|
|
</div><!-- .comments-header -->
|
|
|
|
<div class="comments-inner section-inner thin max-percentage">
|
|
|
|
<?php
|
|
wp_list_comments(
|
|
array(
|
|
'walker' => new TwentyTwenty_Walker_Comment(),
|
|
'avatar_size' => 120,
|
|
'style' => 'div',
|
|
)
|
|
);
|
|
|
|
$comment_pagination = paginate_comments_links(
|
|
array(
|
|
'echo' => false,
|
|
'end_size' => 0,
|
|
'mid_size' => 0,
|
|
'next_text' => __( 'Newer Comments', 'twentytwenty' ) . ' <span aria-hidden="true">→</span>',
|
|
'prev_text' => '<span aria-hidden="true">←</span> ' . __( 'Older Comments', 'twentytwenty' ),
|
|
)
|
|
);
|
|
|
|
if ( $comment_pagination ) {
|
|
$pagination_classes = '';
|
|
|
|
// If we're only showing the "Next" link, add a class indicating so.
|
|
if ( ! str_contains( $comment_pagination, 'prev page-numbers' ) ) {
|
|
$pagination_classes = ' only-next';
|
|
}
|
|
?>
|
|
|
|
<nav class="comments-pagination pagination<?php echo $pagination_classes; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static output ?>" aria-label="<?php esc_attr_e( 'Comments', 'twentytwenty' ); ?>">
|
|
<?php echo wp_kses_post( $comment_pagination ); ?>
|
|
</nav>
|
|
|
|
<?php
|
|
}
|
|
?>
|
|
|
|
</div><!-- .comments-inner -->
|
|
|
|
</div><!-- comments -->
|
|
|
|
<?php
|
|
}
|
|
|
|
if ( comments_open() || pings_open() ) {
|
|
|
|
if ( $comments ) {
|
|
echo '<hr class="styled-separator is-style-wide" aria-hidden="true" />';
|
|
}
|
|
|
|
comment_form(
|
|
array(
|
|
'class_form' => 'section-inner thin max-percentage',
|
|
'title_reply_before' => '<h2 id="reply-title" class="comment-reply-title">',
|
|
'title_reply_after' => '</h2>',
|
|
)
|
|
);
|
|
|
|
} elseif ( is_single() ) {
|
|
|
|
if ( $comments ) {
|
|
echo '<hr class="styled-separator is-style-wide" aria-hidden="true" />';
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="comment-respond" id="respond">
|
|
|
|
<p class="comments-closed"><?php _e( 'Comments are closed.', 'twentytwenty' ); ?></p>
|
|
|
|
</div><!-- #respond -->
|
|
|
|
<?php
|
|
}
|