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