storefront/inc/jetpack/class-storefront-jetpack.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

118 lines
3.3 KiB
PHP

<?php
/**
* Storefront Jetpack Class
*
* @package storefront
* @since 2.0.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'Storefront_Jetpack' ) ) :
/**
* The Storefront Jetpack integration class
*/
class Storefront_Jetpack {
/**
* Setup class.
*
* @since 1.0
*/
public function __construct() {
add_action( 'init', array( $this, 'jetpack_setup' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'jetpack_scripts' ), 10 );
if ( storefront_is_woocommerce_activated() ) {
add_action( 'init', array( $this, 'jetpack_infinite_scroll_wrapper_columns' ) );
}
}
/**
* Add theme support for Infinite Scroll.
* See: http://jetpack.me/support/infinite-scroll/
*/
public function jetpack_setup() {
add_theme_support(
'infinite-scroll',
apply_filters(
'storefront_jetpack_infinite_scroll_args',
array(
'container' => 'main',
'footer' => 'page',
'render' => array( $this, 'jetpack_infinite_scroll_loop' ),
'footer_widgets' => array(
'footer-1',
'footer-2',
'footer-3',
'footer-4',
),
)
)
);
}
/**
* A loop used to display content appended using Jetpack infinite scroll
*
* @return void
*/
public function jetpack_infinite_scroll_loop() {
do_action( 'storefront_jetpack_infinite_scroll_before' );
if ( function_exists( 'storefront_is_product_archive' ) && storefront_is_product_archive() ) {
do_action( 'storefront_jetpack_product_infinite_scroll_before' );
woocommerce_product_loop_start();
}
while ( have_posts() ) :
the_post();
if ( function_exists( 'storefront_is_product_archive' ) && storefront_is_product_archive() ) {
wc_get_template_part( 'content', 'product' );
} else {
get_template_part( 'content', get_post_format() );
}
endwhile; // end of the loop.
if ( function_exists( 'storefront_is_product_archive' ) && storefront_is_product_archive() ) {
woocommerce_product_loop_end();
do_action( 'storefront_jetpack_product_infinite_scroll_after' );
}
do_action( 'storefront_jetpack_infinite_scroll_after' );
}
/**
* Adds columns wrapper to content appended by Jetpack infinite scroll
*
* @return void
*/
public function jetpack_infinite_scroll_wrapper_columns() {
add_action( 'storefront_jetpack_product_infinite_scroll_before', 'storefront_product_columns_wrapper' );
add_action( 'storefront_jetpack_product_infinite_scroll_after', 'storefront_product_columns_wrapper_close' );
}
/**
* Enqueue jetpack styles.
*
* @since 1.6.1
*/
public function jetpack_scripts() {
global $storefront_version;
if ( wp_style_is( 'the-neverending-homepage', 'enqueued' ) ) {
wp_enqueue_style( 'storefront-jetpack-infinite-scroll', get_template_directory_uri() . '/assets/css/jetpack/infinite-scroll.css', array( 'the-neverending-homepage' ), $storefront_version );
wp_style_add_data( 'storefront-jetpack-infinite-scroll', 'rtl', 'replace' );
}
wp_enqueue_style( 'storefront-jetpack-widgets', get_template_directory_uri() . '/assets/css/jetpack/widgets.css', array(), $storefront_version );
wp_style_add_data( 'storefront-jetpack-widgets', 'rtl', 'replace' );
}
}
endif;
return new Storefront_Jetpack();