Skip to content

PHP Standards #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/*
1 change: 1 addition & 0 deletions assets/css/style.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require-dev": {
"stevegrunwell/wp-enforcer": "^0.5.0"
}
}
155 changes: 155 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 33 additions & 19 deletions image-flipper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/*
/**
Plugin Name: WooCommerce Product Image Flipper
Plugin URI: http://jameskoster.co.uk/tag/product-image-flipper/
Version: 0.4.2
Expand All @@ -11,21 +11,28 @@

License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
*/

/**
* Check if WooCommerce is active
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {

if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ), true ) ) {

/**
* Image Flipper class
*/
if ( ! class_exists( 'WC_pif' ) ) {
if ( ! class_exists( 'WC_Pif' ) ) {

class WC_pif {
/**
* WC_Pif class.
*/
class WC_Pif {

/**
* Constructor.
*
* @access public
*/
public function __construct() {
add_action( 'init', array( $this, 'pif_init' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'pif_scripts' ) );
Expand All @@ -43,21 +50,26 @@ public function pif_init() {
/**
* Class functions
*/

public function pif_scripts() {
if ( apply_filters( 'woocommerce_product_image_flipper_styles', true ) ) {
wp_enqueue_style( 'pif-styles', plugins_url( '/assets/css/style.css', __FILE__ ) );
wp_enqueue_style( 'pif-styles', plugins_url( '/assets/css/style.min.css', __FILE__ ), array(), null, 'all' );
}
}

/**
* Product Has Gallery.
*
* @access public
* @param mixed $classes Classes.
*/
public function product_has_gallery( $classes ) {
global $product;

$post_type = get_post_type( get_the_ID() );

if ( ! is_admin() ) {

if ( $post_type == 'product' ) {
if ( 'product' === $post_type ) {

$attachment_ids = $this->get_gallery_image_ids( $product );

Expand All @@ -70,9 +82,10 @@ public function product_has_gallery( $classes ) {
return $classes;
}


/**
* Frontend functions
* Woocomerce Template Loop Second Product Thumbnail.
*
* @access public
*/
public function woocommerce_template_loop_second_product_thumbnail() {
global $product, $woocommerce;
Expand All @@ -83,25 +96,27 @@ public function woocommerce_template_loop_second_product_thumbnail() {
$attachment_ids = array_values( $attachment_ids );
$secondary_image_id = $attachment_ids['0'];

$secondary_image_alt = get_post_meta( $secondary_image_id, '_wp_attachment_image_alt', true );
$secondary_image_title = get_the_title($secondary_image_id);
$secondary_image_alt = get_post_meta( $secondary_image_id, '_wp_attachment_image_alt', true );
$secondary_image_title = get_the_title( $secondary_image_id );

echo wp_get_attachment_image(
$secondary_image_id,
'shop_catalog',
'',
array(
'class' => 'secondary-image attachment-shop-catalog wp-post-image wp-post-image--secondary',
'alt' => $secondary_image_alt,
'title' => $secondary_image_title
'alt' => $secondary_image_alt,
'title' => $secondary_image_title,
)
);
}
}


/**
* WooCommerce Compatibility Functions
* Get Gallery Image IDs.
*
* @access public
* @param mixed $product Product.
*/
public function get_gallery_image_ids( $product ) {
if ( ! is_a( $product, 'WC_Product' ) ) {
Expand All @@ -117,7 +132,6 @@ public function get_gallery_image_ids( $product ) {

}


$WC_pif = new WC_pif();
$wc_pif = new WC_Pif();
}
}
24 changes: 24 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<!--
Customize the rules WP Enforcer uses by editing this file according to PHP_CodeSniffer's
ruleset.xml standard: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
-->
<ruleset name="WP-Enforcer">
<description>Coding standards from WP Enforcer.</description>

<!-- FILES -->
<exclude-pattern>phpcs.xml</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>

<!--
Don't get angry about checking files that don't contain code
@link https://github.com/stevegrunwell/wp-enforcer/issues/12
-->
<rule ref="Internal.NoCodeFound">
<severity>0</severity>
</rule>

<rule ref="WordPress-Extra" />
<rule ref="WordPress-Docs" />
</ruleset>