Skip to content
This repository was archived by the owner on Sep 5, 2025. It is now read-only.

Commit 72e34ef

Browse files
Merge pull request #1267 from jrfnl/feature/cs-update
Bring code style up to the latest standards - This PR addresses code-style issues identified when testing the code against the WordPress Coding Standards.
2 parents 648d11e + f03dfde commit 72e34ef

21 files changed

+303
-196
lines changed

.github/CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Found a bug you can fix? Fantastic! Patches are always welcome. Here's a few tip
2222
* Include the purpose of your PR. Be explicit about the issue your PR solves.
2323
* Reference any existing issues that relate to your PR. This allows everyone to easily see all related discussions.
2424
* When submitting a change that affects CSS, please make sure that both SCSS sources and output CSS have been updated equally.
25+
* `_s` complies with the [WordPress Coding Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/) and any PR should comply as well.
2526

2627
By contributing code to `_s`, you grant its use under the [GNU General Public License v2 (or later)](LICENSE).
2728

.travis.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ before_script:
5050
- phpenv config-rm xdebug.ini || echo 'No xdebug config.'
5151
# Set up temporary paths.
5252
- export PHPCS_DIR=/tmp/phpcs
53-
- export SNIFFS_DIR=/tmp/sniffs
53+
- export WPCS_DIR=/tmp/wpcs
54+
- export PHPCOMPAT_DIR=/tmp/phpcompatibility
5455
# Install CodeSniffer for WordPress Coding Standards checks.
55-
- if [[ "$SNIFF" == "1" ]]; then git clone -b 2.9.1 --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi
56+
- if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi
5657
# Install WordPress Coding Standards.
57-
- if [[ "$SNIFF" == "1" ]]; then git clone -b 0.11.0 --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $SNIFFS_DIR; fi
58+
- if [[ "$SNIFF" == "1" ]]; then git clone -b 0.14.1 --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $WPCS_DIR; fi
5859
# Install PHP Compatibility sniffs.
59-
- if [[ "$SNIFF" == "1" ]]; then git clone -b 7.1.5 --depth 1 https://github.com/wimg/PHPCompatibility.git $SNIFFS_DIR/PHPCompatibility; fi
60+
- if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/wimg/PHPCompatibility.git $PHPCOMPAT_DIR; fi
6061
# Set install path for PHPCS sniffs.
6162
# @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941
62-
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs --config-set installed_paths $SNIFFS_DIR; fi
63+
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $WPCS_DIR,$PHPCOMPAT_DIR; fi
6364
# After CodeSniffer install you should refresh your path.
6465
- if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi
6566
# Install JSCS: JavaScript Code Style checker.
@@ -86,7 +87,7 @@ script:
8687
# @link https://pear.php.net/package/PHP_CodeSniffer/
8788
# Uses a custom ruleset based on WordPress. This ruleset is automatically
8889
# picked up by PHPCS as it's named `phpcs.xml(.dist)`.
89-
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/scripts/phpcs; fi
90+
- if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --runtime-set ignore_warnings_on_exit 1; fi
9091

9192
# Receive notifications for build results.
9293
# @link https://docs.travis-ci.com/user/notifications/#Email-notifications

404.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
* @package _s
88
*/
99

10-
get_header(); ?>
10+
get_header();
11+
?>
1112

1213
<div id="primary" class="content-area">
1314
<main id="main" class="site-main">
@@ -21,33 +22,32 @@
2122
<p><?php esc_html_e( 'It looks like nothing was found at this location. Maybe try one of the links below or a search?', '_s' ); ?></p>
2223

2324
<?php
24-
get_search_form();
25+
get_search_form();
2526

26-
the_widget( 'WP_Widget_Recent_Posts' );
27+
the_widget( 'WP_Widget_Recent_Posts' );
2728
?>
2829

2930
<div class="widget widget_categories">
3031
<h2 class="widget-title"><?php esc_html_e( 'Most Used Categories', '_s' ); ?></h2>
3132
<ul>
32-
<?php
33+
<?php
3334
wp_list_categories( array(
3435
'orderby' => 'count',
3536
'order' => 'DESC',
3637
'show_count' => 1,
3738
'title_li' => '',
3839
'number' => 10,
3940
) );
40-
?>
41+
?>
4142
</ul>
4243
</div><!-- .widget -->
4344

4445
<?php
46+
/* translators: %1$s: smiley */
47+
$_s_archive_content = '<p>' . sprintf( esc_html__( 'Try looking in the monthly archives. %1$s', '_s' ), convert_smilies( ':)' ) ) . '</p>';
48+
the_widget( 'WP_Widget_Archives', 'dropdown=1', "after_title=</h2>$_s_archive_content" );
4549

46-
/* translators: %1$s: smiley */
47-
$archive_content = '<p>' . sprintf( esc_html__( 'Try looking in the monthly archives. %1$s', '_s' ), convert_smilies( ':)' ) ) . '</p>';
48-
the_widget( 'WP_Widget_Archives', 'dropdown=1', "after_title=</h2>$archive_content" );
49-
50-
the_widget( 'WP_Widget_Tag_Cloud' );
50+
the_widget( 'WP_Widget_Tag_Cloud' );
5151
?>
5252

5353
</div><!-- .page-content -->

archive.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
* @package _s
88
*/
99

10-
get_header(); ?>
10+
get_header();
11+
?>
1112

1213
<div id="primary" class="content-area">
1314
<main id="main" class="site-main">
1415

15-
<?php
16-
if ( have_posts() ) : ?>
16+
<?php if ( have_posts() ) : ?>
1717

1818
<header class="page-header">
1919
<?php
20-
the_archive_title( '<h1 class="page-title">', '</h1>' );
21-
the_archive_description( '<div class="archive-description">', '</div>' );
20+
the_archive_title( '<h1 class="page-title">', '</h1>' );
21+
the_archive_description( '<div class="archive-description">', '</div>' );
2222
?>
2323
</header><!-- .page-header -->
2424

2525
<?php
2626
/* Start the Loop */
27-
while ( have_posts() ) : the_post();
27+
while ( have_posts() ) :
28+
the_post();
2829

2930
/*
3031
* Include the Post-Type-specific template for the content.
@@ -41,7 +42,8 @@
4142

4243
get_template_part( 'template-parts/content', 'none' );
4344

44-
endif; ?>
45+
endif;
46+
?>
4547

4648
</main><!-- #main -->
4749
</div><!-- #primary -->

comments.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424

2525
<?php
2626
// You can start editing here -- including this comment!
27-
if ( have_comments() ) : ?>
27+
if ( have_comments() ) :
28+
?>
2829
<h2 class="comments-title">
2930
<?php
30-
$comment_count = get_comments_number();
31-
if ( '1' === $comment_count ) {
31+
$_s_comment_count = get_comments_number();
32+
if ( '1' === $_s_comment_count ) {
3233
printf(
3334
/* translators: 1: title. */
3435
esc_html__( 'One thought on &ldquo;%1$s&rdquo;', '_s' ),
@@ -37,8 +38,8 @@
3738
} else {
3839
printf( // WPCS: XSS OK.
3940
/* translators: 1: comment count number, 2: title. */
40-
esc_html( _nx( '%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', $comment_count, 'comments title', '_s' ) ),
41-
number_format_i18n( $comment_count ),
41+
esc_html( _nx( '%1$s thought on &ldquo;%2$s&rdquo;', '%1$s thoughts on &ldquo;%2$s&rdquo;', $_s_comment_count, 'comments title', '_s' ) ),
42+
number_format_i18n( $_s_comment_count ),
4243
'<span>' . get_the_title() . '</span>'
4344
);
4445
}
@@ -49,19 +50,21 @@
4950

5051
<ol class="comment-list">
5152
<?php
52-
wp_list_comments( array(
53-
'style' => 'ol',
54-
'short_ping' => true,
55-
) );
53+
wp_list_comments( array(
54+
'style' => 'ol',
55+
'short_ping' => true,
56+
) );
5657
?>
5758
</ol><!-- .comment-list -->
5859

59-
<?php the_comments_navigation();
60+
<?php
61+
the_comments_navigation();
6062

6163
// If comments are closed and there are comments, let's leave a little note, shall we?
62-
if ( ! comments_open() ) : ?>
64+
if ( ! comments_open() ) :
65+
?>
6366
<p class="no-comments"><?php esc_html_e( 'Comments are closed.', '_s' ); ?></p>
64-
<?php
67+
<?php
6568
endif;
6669

6770
endif; // Check for have_comments().

footer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515

1616
<footer id="colophon" class="site-footer">
1717
<div class="site-info">
18-
<a href="<?php echo esc_url( __( 'https://wordpress.org/', '_s' ) ); ?>"><?php
18+
<a href="<?php echo esc_url( __( 'https://wordpress.org/', '_s' ) ); ?>">
19+
<?php
1920
/* translators: %s: CMS name, i.e. WordPress. */
2021
printf( esc_html__( 'Proudly powered by %s', '_s' ), 'WordPress' );
21-
?></a>
22+
?>
23+
</a>
2224
<span class="sep"> | </span>
23-
<?php
25+
<?php
2426
/* translators: 1: Theme name, 2: Theme author. */
2527
printf( esc_html__( 'Theme: %1$s by %2$s.', '_s' ), '_s', '<a href="https://automattic.com/">Automattic</a>' );
26-
?>
28+
?>
2729
</div><!-- .site-info -->
2830
</footer><!-- #colophon -->
2931
</div><!-- #page -->

functions.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ function _s_setup() {
9191
* @global int $content_width
9292
*/
9393
function _s_content_width() {
94+
// This variable is intended to be overruled from themes.
95+
// Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
96+
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
9497
$GLOBALS['content_width'] = apply_filters( '_s_content_width', 640 );
9598
}
9699
add_action( 'after_setup_theme', '_s_content_width', 0 );

header.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,29 @@
2828
<div class="site-branding">
2929
<?php
3030
the_custom_logo();
31-
if ( is_front_page() && is_home() ) : ?>
31+
if ( is_front_page() && is_home() ) :
32+
?>
3233
<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
33-
<?php else : ?>
34+
<?php
35+
else :
36+
?>
3437
<p class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></p>
35-
<?php
38+
<?php
3639
endif;
37-
38-
$description = get_bloginfo( 'description', 'display' );
39-
if ( $description || is_customize_preview() ) : ?>
40-
<p class="site-description"><?php echo $description; /* WPCS: xss ok. */ ?></p>
41-
<?php
42-
endif; ?>
40+
$_s_description = get_bloginfo( 'description', 'display' );
41+
if ( $_s_description || is_customize_preview() ) :
42+
?>
43+
<p class="site-description"><?php echo $_s_description; /* WPCS: xss ok. */ ?></p>
44+
<?php endif; ?>
4345
</div><!-- .site-branding -->
4446

4547
<nav id="site-navigation" class="main-navigation">
4648
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e( 'Primary Menu', '_s' ); ?></button>
4749
<?php
48-
wp_nav_menu( array(
49-
'theme_location' => 'menu-1',
50-
'menu_id' => 'primary-menu',
51-
) );
50+
wp_nav_menu( array(
51+
'theme_location' => 'menu-1',
52+
'menu_id' => 'primary-menu',
53+
) );
5254
?>
5355
</nav><!-- #site-navigation -->
5456
</header><!-- #masthead -->

inc/custom-header.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ function _s_header_style() {
5151
<?php
5252
// Has the text been hidden?
5353
if ( ! display_header_text() ) :
54-
?>
54+
?>
5555
.site-title,
5656
.site-description {
5757
position: absolute;
5858
clip: rect(1px, 1px, 1px, 1px);
5959
}
6060
<?php
61-
// If the user has set a custom color for the text use that.
62-
else :
63-
?>
61+
// If the user has set a custom color for the text use that.
62+
else :
63+
?>
6464
.site-title a,
6565
.site-description {
6666
color: #<?php echo esc_attr( $header_text_color ); ?>;

inc/template-tags.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,37 @@ function _s_entry_footer() {
112112
endif;
113113

114114
if ( ! function_exists( '_s_post_thumbnail' ) ) :
115-
/**
116-
* Displays an optional post thumbnail.
117-
*
118-
* Wraps the post thumbnail in an anchor element on index views, or a div
119-
* element when on single views.
120-
*/
121-
function _s_post_thumbnail() {
122-
if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
123-
return;
124-
}
115+
/**
116+
* Displays an optional post thumbnail.
117+
*
118+
* Wraps the post thumbnail in an anchor element on index views, or a div
119+
* element when on single views.
120+
*/
121+
function _s_post_thumbnail() {
122+
if ( post_password_required() || is_attachment() || ! has_post_thumbnail() ) {
123+
return;
124+
}
125125

126-
if ( is_singular() ) :
127-
?>
126+
if ( is_singular() ) :
127+
?>
128128

129-
<div class="post-thumbnail">
130-
<?php the_post_thumbnail(); ?>
131-
</div><!-- .post-thumbnail -->
129+
<div class="post-thumbnail">
130+
<?php the_post_thumbnail(); ?>
131+
</div><!-- .post-thumbnail -->
132132

133-
<?php else : ?>
133+
<?php else : ?>
134134

135-
<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
136-
<?php
135+
<a class="post-thumbnail" href="<?php the_permalink(); ?>" aria-hidden="true">
136+
<?php
137137
the_post_thumbnail( 'post-thumbnail', array(
138138
'alt' => the_title_attribute( array(
139139
'echo' => false,
140140
) ),
141141
) );
142-
?>
143-
</a>
142+
?>
143+
</a>
144144

145-
<?php endif; // End is_singular().
146-
}
145+
<?php
146+
endif; // End is_singular().
147+
}
147148
endif;

0 commit comments

Comments
 (0)