Fixed includes/class-wc-breadcrumb.php PHPCS violations

This commit is contained in:
Claudio Sanches 2018-03-15 18:30:08 -03:00
parent 820426a4d0
commit 8d860d7fb3
1 changed files with 45 additions and 33 deletions

View File

@ -1,17 +1,15 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* WC_Breadcrumb class.
*
* @class WC_Breadcrumb
* @version 2.3.0
* @package WooCommerce/Classes
* @category Class
* @author WooThemes
* @package WooCommerce/Classes
* @version 2.3.0
*/
defined( 'ABSPATH' ) || exit;
/**
* Breadcrumb class.
*/
class WC_Breadcrumb {
@ -25,8 +23,8 @@ class WC_Breadcrumb {
/**
* Add a crumb so we don't get lost.
*
* @param string $name
* @param string $link
* @param string $name Name.
* @param string $link Link.
*/
public function add_crumb( $name, $link = '' ) {
$this->crumbs[] = array(
@ -99,14 +97,14 @@ class WC_Breadcrumb {
$shop_page_id = wc_get_page_id( 'shop' );
$shop_page = get_post( $shop_page_id );
// If permalinks contain the shop page in the URI prepend the breadcrumb with shop
if ( $shop_page_id && $shop_page && isset( $permalinks['product_base'] ) && strstr( $permalinks['product_base'], '/' . $shop_page->post_name ) && get_option( 'page_on_front' ) != $shop_page_id ) {
// If permalinks contain the shop page in the URI prepend the breadcrumb with shop.
if ( $shop_page_id && $shop_page && isset( $permalinks['product_base'] ) && strstr( $permalinks['product_base'], '/' . $shop_page->post_name ) && intval( get_option( 'page_on_front' ) ) !== $shop_page_id ) {
$this->add_crumb( get_the_title( $shop_page ), get_permalink( $shop_page ) );
}
}
/**
* is home trail.
* Is home trail..
*/
private function add_crumbs_home() {
$this->add_crumb( single_post_title( '', false ) );
@ -120,7 +118,7 @@ class WC_Breadcrumb {
}
/**
* attachment trail.
* Attachment trail.
*/
private function add_crumbs_attachment() {
global $post;
@ -132,23 +130,27 @@ class WC_Breadcrumb {
/**
* Single post trail.
*
* @param int $post_id
* @param string $permalink
* @param int $post_id Post ID.
* @param string $permalink Post permalink.
*/
private function add_crumbs_single( $post_id = 0, $permalink = '' ) {
if ( ! $post_id ) {
global $post;
} else {
$post = get_post( $post_id );
$post = get_post( $post_id ); // WPCS: override ok.
}
if ( 'product' === get_post_type( $post ) ) {
$this->prepend_shop_page();
$terms = wc_get_product_terms( $post->ID, 'product_cat', apply_filters( 'woocommerce_breadcrumb_product_terms_args', array(
'orderby' => 'parent',
'order' => 'DESC',
) ) );
$terms = wc_get_product_terms(
$post->ID, 'product_cat', apply_filters(
'woocommerce_breadcrumb_product_terms_args', array(
'orderby' => 'parent',
'order' => 'DESC',
)
)
);
if ( $terms ) {
$main_term = apply_filters( 'woocommerce_breadcrumb_main_term', $terms[0], $terms );
@ -183,8 +185,8 @@ class WC_Breadcrumb {
$parent_id = $post->post_parent;
while ( $parent_id ) {
$page = get_post( $parent_id );
$parent_id = $page->post_parent;
$page = get_post( $parent_id );
$parent_id = $page->post_parent;
$parent_crumbs[] = array( get_the_title( $page->ID ), get_permalink( $page->ID ) );
}
@ -217,6 +219,8 @@ class WC_Breadcrumb {
$current_term = $GLOBALS['wp_query']->get_queried_object();
$this->prepend_shop_page();
/* translators: %s: product tag */
$this->add_crumb( sprintf( __( 'Products tagged &ldquo;%s&rdquo;', 'woocommerce' ), $current_term->name ) );
}
@ -224,7 +228,7 @@ class WC_Breadcrumb {
* Shop breadcrumb.
*/
private function add_crumbs_shop() {
if ( get_option( 'page_on_front' ) == wc_get_page_id( 'shop' ) ) {
if ( intval( get_option( 'page_on_front' ) ) === wc_get_page_id( 'shop' ) ) {
return;
}
@ -232,7 +236,7 @@ class WC_Breadcrumb {
if ( ! $_name ) {
$product_post_type = get_post_type_object( 'product' );
$_name = $product_post_type->labels->singular_name;
$_name = $product_post_type->labels->singular_name;
}
$this->add_crumb( $_name, get_post_type_archive_link( 'product' ) );
@ -255,7 +259,7 @@ class WC_Breadcrumb {
private function add_crumbs_category() {
$this_category = get_category( $GLOBALS['wp_query']->get_queried_object() );
if ( 0 != $this_category->parent ) {
if ( 0 !== intval( $this_category->parent ) ) {
$this->term_ancestors( $this_category->term_id, 'category' );
}
@ -267,6 +271,8 @@ class WC_Breadcrumb {
*/
private function add_crumbs_tag() {
$queried_object = $GLOBALS['wp_query']->get_queried_object();
/* translators: %s: tag name */
$this->add_crumb( sprintf( __( 'Posts tagged &ldquo;%s&rdquo;', 'woocommerce' ), single_tag_title( '', false ) ), get_tag_link( $queried_object->term_id ) );
}
@ -294,7 +300,7 @@ class WC_Breadcrumb {
$this->add_crumb( $taxonomy->labels->name );
if ( 0 != $this_term->parent ) {
if ( 0 !== intval( $this_term->parent ) ) {
$this->term_ancestors( $this_term->term_id, $this_term->taxonomy );
}
@ -308,14 +314,16 @@ class WC_Breadcrumb {
global $author;
$userdata = get_userdata( $author );
/* translators: %s: author name */
$this->add_crumb( sprintf( __( 'Author: %s', 'woocommerce' ), $userdata->display_name ) );
}
/**
* Add crumbs for a term.
*
* @param int $term_id
* @param string $taxonomy
* @param int $term_id Term ID.
* @param string $taxonomy Taxonomy.
*/
private function term_ancestors( $term_id, $taxonomy ) {
$ancestors = get_ancestors( $term_id, $taxonomy );
@ -334,8 +342,10 @@ class WC_Breadcrumb {
* Endpoints.
*/
private function endpoint_trail() {
// Is an endpoint showing?
if ( is_wc_endpoint_url() && ( $endpoint = WC()->query->get_current_endpoint() ) && ( $endpoint_title = WC()->query->get_endpoint_title( $endpoint ) ) ) {
$endpoint = is_wc_endpoint_url() ? WC()->query->get_current_endpoint() : '';
$endpoint_title = $endpoint ? WC()->query->get_endpoint_title( $endpoint ) : '';
if ( $endpoint_title ) {
$this->add_crumb( $endpoint_title );
}
}
@ -345,6 +355,7 @@ class WC_Breadcrumb {
*/
private function search_trail() {
if ( is_search() ) {
/* translators: %s: search term */
$this->add_crumb( sprintf( __( 'Search results for &ldquo;%s&rdquo;', 'woocommerce' ), get_search_query() ), remove_query_arg( 'paged' ) );
}
}
@ -354,6 +365,7 @@ class WC_Breadcrumb {
*/
private function paged_trail() {
if ( get_query_var( 'paged' ) ) {
/* translators: %d: page number */
$this->add_crumb( sprintf( __( 'Page %d', 'woocommerce' ), get_query_var( 'paged' ) ) );
}
}