From ac604af5d4d363006a9a365b05b31a383972d9dd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 9 Aug 2018 04:08:09 +0200 Subject: [PATCH 1/4] QA: Break stylesheets out of browser cache on each new release of a theme The `wp_enqueue_style()` function allows for passing a `$version` parameter which is used to force browsers to load a fresh copy of a stylesheet when it has been changed. If this parameter is not passed, the version number will be set to the version of the WP install which doesn't make sense at all for a theme which is not shipped with WP itself. This commit adds a `_S_VERSION` constant which should be changed to the current version number of the actual finished theme on each new release. This constant is subsequently used in all `wp_enqueue_style()` function calls to ensure that on each new release of the theme, the browser cache is cleared for these stylesheets. Ref: https://developer.wordpress.org/reference/functions/wp_enqueue_style/ --- functions.php | 11 ++++++++--- inc/woocommerce.php | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/functions.php b/functions.php index b7134e760e..3402750dd9 100644 --- a/functions.php +++ b/functions.php @@ -7,6 +7,11 @@ * @package _s */ +if ( ! defined( '_S_VERSION' ) ) { + // Replace #.# with the version number of the theme on each release. + define( '_S_VERSION', '#.#' ); +} + if ( ! function_exists( '_s_setup' ) ) : /** * Sets up theme defaults and registers support for various WordPress features. @@ -120,11 +125,11 @@ function _s_widgets_init() { * Enqueue scripts and styles. */ function _s_scripts() { - wp_enqueue_style( '_s-style', get_stylesheet_uri() ); + wp_enqueue_style( '_s-style', get_stylesheet_uri(), array(), _S_VERSION ); - wp_enqueue_script( '_s-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true ); + wp_enqueue_script( '_s-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true ); - wp_enqueue_script( '_s-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true ); + wp_enqueue_script( '_s-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), _S_VERSION, true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); diff --git a/inc/woocommerce.php b/inc/woocommerce.php index 6d6000ed02..c08f9c9e81 100644 --- a/inc/woocommerce.php +++ b/inc/woocommerce.php @@ -29,7 +29,7 @@ function _s_woocommerce_setup() { * @return void */ function _s_woocommerce_scripts() { - wp_enqueue_style( '_s-woocommerce-style', get_template_directory_uri() . '/woocommerce.css' ); + wp_enqueue_style( '_s-woocommerce-style', get_template_directory_uri() . '/woocommerce.css', array(), _S_VERSION ); $font_path = WC()->plugin_url() . '/assets/fonts/'; $inline_font = '@font-face { From 9f9cb4a0785cece3cf1988e4d4396f9d1ca489e0 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 9 Aug 2018 04:09:28 +0200 Subject: [PATCH 2/4] CS: Minor fixes to comply with WPCS 1.0.0 / PHPCS 3.3.1 --- inc/custom-header.php | 6 +++--- inc/woocommerce.php | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/inc/custom-header.php b/inc/custom-header.php index a4c2a6cc42..243a1eb0a8 100644 --- a/inc/custom-header.php +++ b/inc/custom-header.php @@ -4,7 +4,7 @@ * * You can add an optional custom header image to header.php like so ... * - + * * * @link https://developer.wordpress.org/themes/functionality/custom-headers/ * @@ -57,9 +57,9 @@ function _s_header_style() { position: absolute; clip: rect(1px, 1px, 1px, 1px); } - .site-title a, .site-description { diff --git a/inc/woocommerce.php b/inc/woocommerce.php index c08f9c9e81..97e14cb4e2 100644 --- a/inc/woocommerce.php +++ b/inc/woocommerce.php @@ -103,8 +103,8 @@ function _s_woocommerce_loop_columns() { /** * Related Products Args. * - * @param array $args related products args. - * @return array $args related products args. + * @param array $args Related products args. + * @return array $args Related products args. */ function _s_woocommerce_related_products_args( $args ) { $defaults = array( @@ -175,7 +175,7 @@ function _s_woocommerce_wrapper_before() { * @return void */ function _s_woocommerce_wrapper_after() { - ?> + ?> + * */ if ( ! function_exists( '_s_woocommerce_cart_link_fragment' ) ) { From e8be9d135e7dffae7b1a0547e8e52021102dc82b Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 9 Aug 2018 04:18:07 +0200 Subject: [PATCH 3/4] :rocket: Build: use PHPCompatibilityWP Since mid July, the PHPCompatibility project offers dedicated CMS rulesets which already account for all back-fills/poly-fills. This commit removes the `_s` native version of that ruleset in favour of using this dedicated WP-based ruleset. Additionally, the PHPCompatibility repo has moved to a dedicated GitHub organisation, so that change is included here as well. Refs: * https://github.com/PHPCompatibility/PHPCompatibility/releases/tag/8.2.0 * https://github.com/phpcompatibility/phpcompatibilitywp Note: I would strongly recommend installing these dependencies via Composer instead. grappler has created a good setup for this in PR 1291 which I would recommend for merging, though it will need to be updated to be in line with the changes made in this PR. --- .travis.yml | 7 +++++-- phpcs.xml.dist | 33 ++------------------------------- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4840c9fed2..df1f5be708 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,15 +52,18 @@ before_script: - export PHPCS_DIR=/tmp/phpcs - export WPCS_DIR=/tmp/wpcs - export PHPCOMPAT_DIR=/tmp/phpcompatibility + - export PHPCOMPATWP_DIR=/tmp/phpcompatibilitywp # Install CodeSniffer for WordPress Coding Standards checks. - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi # Install WordPress Coding Standards. - 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 # Install PHP Compatibility sniffs. - - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/wimg/PHPCompatibility.git $PHPCOMPAT_DIR; fi + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/PHPCompatibility/PHPCompatibility.git $PHPCOMPAT_DIR; fi + # Install WP PHP Compatibility ruleset. + - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/PHPCompatibility/PHPCompatibilityWP.git $PHPCOMPATWP_DIR; fi # Set install path for PHPCS sniffs. # @link https://github.com/squizlabs/PHP_CodeSniffer/blob/4237c2fc98cc838730b76ee9cee316f99286a2a7/CodeSniffer.php#L1941 - - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $WPCS_DIR,$PHPCOMPAT_DIR; fi + - if [[ "$SNIFF" == "1" ]]; then $PHPCS_DIR/bin/phpcs --config-set installed_paths $WPCS_DIR,$PHPCOMPAT_DIR,$PHPCOMPATWP_DIR; fi # After CodeSniffer install you should refresh your path. - if [[ "$SNIFF" == "1" ]]; then phpenv rehash; fi # Install JSCS: JavaScript Code Style checker. diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 578ce0255a..f74b0bfcb2 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -97,36 +97,7 @@ ############################################################################# --> - - - - - - - - - - - - - - - - - - - - - - - - - + + From 30447f166d10f057d569ed2d35d0d21d0d76abe9 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 9 Aug 2018 04:20:40 +0200 Subject: [PATCH 4/4] :rocket: Build: use WPCS 1.0.0 ... and sniff against a high PHP version for the fastest and most reliable results. No ruleset changes are needed. Refs: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases/tag/1.0.0 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index df1f5be708..c0e47cee45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,11 +26,11 @@ matrix: dist: precise # aliased to a recent 5.6.x version - php: '5.6' - env: SNIFF=1 # aliased to a recent 7.0.x version - php: '7.0' # aliased to a recent 7.2.x version - php: '7.2' + env: SNIFF=1 # bleeding edge PHP - php: 'nightly' @@ -56,7 +56,7 @@ before_script: # Install CodeSniffer for WordPress Coding Standards checks. - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/squizlabs/PHP_CodeSniffer.git $PHPCS_DIR; fi # Install WordPress Coding Standards. - - 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 + - if [[ "$SNIFF" == "1" ]]; then git clone -b 1.0.0 --depth 1 https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.git $WPCS_DIR; fi # Install PHP Compatibility sniffs. - if [[ "$SNIFF" == "1" ]]; then git clone -b master --depth 1 https://github.com/PHPCompatibility/PHPCompatibility.git $PHPCOMPAT_DIR; fi # Install WP PHP Compatibility ruleset.