storefront/comments.php
Rua Haszard 7bd2171866
reinstate phpcs php linting (#1463)
* update squizlabs/php_codesniffer and WP coding standards to latest

* revamp phpcs sniffer rulesets:
- update to php-compatibility (wimg is defunct)
- add version for woocommerce-sniffs

* streamline phpcs config (get it working at all):
- update min WP version to 5.3
- remove references to rules we don't have installed
  - WordPress.VIP
  - WordPress.XSS

* fix 2x phpcs errors (automatically via phpcbf)

* update phps ignore unescaped output comment to current format

* add npm scripts for php linter and linter autofixer

* auto-fix PHP linter errors using phpcbf :

Before phpcbf:

[x] PEAR      Functions           Function call signature multiple arguments          127
[x] Generic   White space         Disallow space indent spaces used                   10
[ ] WordPres  WP                  Enqueued resource parameters missing version        6
[ ] PHPCompa  Language construct  New language constructs t_ns_separator found        4
[ ] WordPres  Security            Escape output output not escaped                    4
[ ] PHPCompa  Parameter values    New HTMLEntities encoding default not set           2
[ ] WordPres  Date time           Restricted functions date_date                      2
[x] Generic   Files               End file newline not found                          1
[x] PEAR      Functions           Function call signature close bracket line          1
[x] PEAR      Functions           Function call signature content after open bracket  1
[x] Squiz     White space         Superfluous whitespace end line                     1
[x] WordPres  Arrays              Comma after array item no comma                     1

phpcbf fixed all [x] violations, all whitespace/formatting

After phpcbf:

WordPres  WP                  Enqueued resource parameters missing version      6
PHPCompa  Language construct  New language constructs t_ns_separator found      4
WordPres  Security            Escape output output not escaped                  4
PHPCompa  Parameter values    New HTMLEntities encoding default not set         2
WordPres  Date time           Restricted functions date_date                    2

Note - this commit does not include auto-fixed files with other
violations. These will follow in separate commit (after fixing!)

* fix phpcs violations:
- numerous formatting issues fixed automatically
- manually fix missing version param in calls to wp_enqueue_style

* fix phpcs violations:
- numerous formatting issues fixed automatically
- fix missing deps param in call to wp_enqueue_style

* update phpcs test php version to match min requirement (5.6)

* fix phpcs violations including some missing escaping:
- numerous formatting issues fixed automatically
- prefer gmdate() over potentially ambiguous date()
- escape output (a real issue!) of comment dates

* fix violations (all automated formatting fixes)

* reinstate WordPress rule/standard in phpcs.xml (minimise PR changes)

* exclude build (pre-zip) ./storefront & tighten excludes for dep folders

* bulk-update Security.EscapeOutput.OutputNotEscaped ignore comment:
- the previous comment format is no longer supported
- bulk replacing these to reduce phpcs warning overhead
2020-09-21 15:50:46 +01:00

87 lines
3 KiB
PHP

<?php
/**
* The template for displaying comments.
*
* The area of the page that contains both current comments
* and the comment form.
*
* @package storefront
*/
/*
* 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;
}
?>
<section id="comments" class="comments-area" aria-label="<?php esc_html_e( 'Post Comments', 'storefront' ); ?>">
<?php
if ( have_comments() ) :
?>
<h2 class="comments-title">
<?php
// phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped
printf(
/* 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;', get_comments_number(), 'comments title', 'storefront' ) ),
number_format_i18n( get_comments_number() ),
'<span>' . get_the_title() . '</span>'
);
// phpcs:enable
?>
</h2>
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through. ?>
<nav id="comment-nav-above" class="comment-navigation" role="navigation" aria-label="<?php esc_html_e( 'Comment Navigation Above', 'storefront' ); ?>">
<span class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'storefront' ); ?></span>
<div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'storefront' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'storefront' ) ); ?></div>
</nav><!-- #comment-nav-above -->
<?php endif; // Check for comment navigation. ?>
<ol class="comment-list">
<?php
wp_list_comments(
array(
'style' => 'ol',
'short_ping' => true,
'callback' => 'storefront_comment',
)
);
?>
</ol><!-- .comment-list -->
<?php if ( get_comment_pages_count() > 1 && get_option( 'page_comments' ) ) : // Are there comments to navigate through. ?>
<nav id="comment-nav-below" class="comment-navigation" role="navigation" aria-label="<?php esc_html_e( 'Comment Navigation Below', 'storefront' ); ?>">
<span class="screen-reader-text"><?php esc_html_e( 'Comment navigation', 'storefront' ); ?></span>
<div class="nav-previous"><?php previous_comments_link( __( '&larr; Older Comments', 'storefront' ) ); ?></div>
<div class="nav-next"><?php next_comments_link( __( 'Newer Comments &rarr;', 'storefront' ) ); ?></div>
</nav><!-- #comment-nav-below -->
<?php
endif; // Check for comment navigation.
endif;
if ( ! comments_open() && 0 !== intval( get_comments_number() ) && post_type_supports( get_post_type(), 'comments' ) ) :
?>
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', 'storefront' ); ?></p>
<?php
endif;
$args = apply_filters(
'storefront_comment_form_args',
array(
'title_reply_before' => '<span id="reply-title" class="gamma comment-reply-title">',
'title_reply_after' => '</span>',
)
);
comment_form( $args );
?>
</section><!-- #comments -->