Fixed includes/class-wc-order-item-meta.php PHPCS violations
This commit is contained in:
parent
e70f278123
commit
ddac79152a
|
@ -1,43 +1,59 @@
|
||||||
<?php
|
<?php
|
||||||
if ( ! defined( 'ABSPATH' ) ) {
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order Item Meta
|
* Order Item Meta
|
||||||
*
|
*
|
||||||
* A Simple class for managing order item meta so plugins add it in the correct format.
|
* A Simple class for managing order item meta so plugins add it in the correct format.
|
||||||
*
|
*
|
||||||
|
* @package WooCommerce/Classes
|
||||||
* @deprecated 3.0.0 wc_display_item_meta function is used instead.
|
* @deprecated 3.0.0 wc_display_item_meta function is used instead.
|
||||||
* @class order_item_meta
|
* @version 2.4
|
||||||
* @version 2.4
|
*/
|
||||||
* @package WooCommerce/Classes
|
|
||||||
* @author WooThemes
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Order item meta class.
|
||||||
*/
|
*/
|
||||||
class WC_Order_Item_Meta {
|
class WC_Order_Item_Meta {
|
||||||
|
|
||||||
/** @var bool For handling backwards comp */
|
/**
|
||||||
|
* For handling backwards compatibility.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
private $legacy = false;
|
private $legacy = false;
|
||||||
|
|
||||||
/** @var Array Order item */
|
/**
|
||||||
private $item = null;
|
* Order item
|
||||||
|
*
|
||||||
|
* @var array|null
|
||||||
|
*/
|
||||||
|
private $item = null;
|
||||||
|
|
||||||
/** @var Array Post meta data */
|
/**
|
||||||
public $meta = null;
|
* Post meta data
|
||||||
|
*
|
||||||
|
* @var array|null
|
||||||
|
*/
|
||||||
|
public $meta = null;
|
||||||
|
|
||||||
/** @var Product object */
|
/**
|
||||||
|
* Product object.
|
||||||
|
*
|
||||||
|
* @var WC_Product|null
|
||||||
|
*/
|
||||||
public $product = null;
|
public $product = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param array $item defaults to array()
|
* @param array $item defaults to array().
|
||||||
* @param \WC_Product $product defaults to null
|
* @param \WC_Product $product defaults to null.
|
||||||
*/
|
*/
|
||||||
public function __construct( $item = array(), $product = null ) {
|
public function __construct( $item = array(), $product = null ) {
|
||||||
wc_deprecated_function( 'WC_Order_Item_Meta::__construct', '3.1', 'WC_Order_Item_Product' );
|
wc_deprecated_function( 'WC_Order_Item_Meta::__construct', '3.1', 'WC_Order_Item_Product' );
|
||||||
|
|
||||||
// Backwards (pre 2.4) compatibility
|
// Backwards (pre 2.4) compatibility.
|
||||||
if ( ! isset( $item['item_meta'] ) ) {
|
if ( ! isset( $item['item_meta'] ) ) {
|
||||||
$this->legacy = true;
|
$this->legacy = true;
|
||||||
$this->meta = array_filter( (array) $item );
|
$this->meta = array_filter( (array) $item );
|
||||||
|
@ -51,10 +67,10 @@ class WC_Order_Item_Meta {
|
||||||
/**
|
/**
|
||||||
* Display meta in a formatted list.
|
* Display meta in a formatted list.
|
||||||
*
|
*
|
||||||
* @param bool $flat (default: false)
|
* @param bool $flat Flat (default: false).
|
||||||
* @param bool $return (default: false)
|
* @param bool $return Return (default: false).
|
||||||
* @param string $hideprefix (default: _)
|
* @param string $hideprefix Hide prefix (default: _).
|
||||||
* @param string $delimiter Delimiter used to separate items when $flat is true
|
* @param string $delimiter Delimiter used to separate items when $flat is true.
|
||||||
* @return string|void
|
* @return string|void
|
||||||
*/
|
*/
|
||||||
public function display( $flat = false, $return = false, $hideprefix = '_', $delimiter = ", \n" ) {
|
public function display( $flat = false, $return = false, $hideprefix = '_', $delimiter = ", \n" ) {
|
||||||
|
@ -89,14 +105,14 @@ class WC_Order_Item_Meta {
|
||||||
if ( $return ) {
|
if ( $return ) {
|
||||||
return $output;
|
return $output;
|
||||||
} else {
|
} else {
|
||||||
echo $output;
|
echo $output; // WPCS: XSS ok.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array of formatted item meta in format e.g.
|
* Return an array of formatted item meta in format e.g.
|
||||||
*
|
*
|
||||||
* array(
|
* Returns: array(
|
||||||
* 'pa_size' => array(
|
* 'pa_size' => array(
|
||||||
* 'label' => 'Size',
|
* 'label' => 'Size',
|
||||||
* 'value' => 'Medium',
|
* 'value' => 'Medium',
|
||||||
|
@ -104,7 +120,7 @@ class WC_Order_Item_Meta {
|
||||||
* )
|
* )
|
||||||
*
|
*
|
||||||
* @since 2.4
|
* @since 2.4
|
||||||
* @param string $hideprefix exclude meta when key is prefixed with this, defaults to `_`
|
* @param string $hideprefix exclude meta when key is prefixed with this, defaults to '_'.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_formatted( $hideprefix = '_' ) {
|
public function get_formatted( $hideprefix = '_' ) {
|
||||||
|
@ -116,14 +132,14 @@ class WC_Order_Item_Meta {
|
||||||
|
|
||||||
if ( ! empty( $this->item['item_meta_array'] ) ) {
|
if ( ! empty( $this->item['item_meta_array'] ) ) {
|
||||||
foreach ( $this->item['item_meta_array'] as $meta_id => $meta ) {
|
foreach ( $this->item['item_meta_array'] as $meta_id => $meta ) {
|
||||||
if ( "" === $meta->value || is_serialized( $meta->value ) || ( ! empty( $hideprefix ) && substr( $meta->key, 0, 1 ) === $hideprefix ) ) {
|
if ( '' === $meta->value || is_serialized( $meta->value ) || ( ! empty( $hideprefix ) && substr( $meta->key, 0, 1 ) === $hideprefix ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attribute_key = urldecode( str_replace( 'attribute_', '', $meta->key ) );
|
$attribute_key = urldecode( str_replace( 'attribute_', '', $meta->key ) );
|
||||||
$meta_value = $meta->value;
|
$meta_value = $meta->value;
|
||||||
|
|
||||||
// If this is a term slug, get the term's nice name
|
// If this is a term slug, get the term's nice name.
|
||||||
if ( taxonomy_exists( $attribute_key ) ) {
|
if ( taxonomy_exists( $attribute_key ) ) {
|
||||||
$term = get_term_by( 'slug', $meta_value, $attribute_key );
|
$term = get_term_by( 'slug', $meta_value, $attribute_key );
|
||||||
|
|
||||||
|
@ -147,7 +163,7 @@ class WC_Order_Item_Meta {
|
||||||
* Return an array of formatted item meta in format e.g.
|
* Return an array of formatted item meta in format e.g.
|
||||||
* Handles @deprecated args.
|
* Handles @deprecated args.
|
||||||
*
|
*
|
||||||
* @param string $hideprefix
|
* @param string $hideprefix Hide prefix.
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
@ -159,18 +175,18 @@ class WC_Order_Item_Meta {
|
||||||
$formatted_meta = array();
|
$formatted_meta = array();
|
||||||
|
|
||||||
foreach ( $this->meta as $meta_key => $meta_values ) {
|
foreach ( $this->meta as $meta_key => $meta_values ) {
|
||||||
if ( empty( $meta_values ) || ( ! empty( $hideprefix ) && substr( $meta_key, 0, 1 ) == $hideprefix ) ) {
|
if ( empty( $meta_values ) || ( ! empty( $hideprefix ) && substr( $meta_key, 0, 1 ) === $hideprefix ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach ( (array) $meta_values as $meta_value ) {
|
foreach ( (array) $meta_values as $meta_value ) {
|
||||||
// Skip serialised meta
|
// Skip serialised meta.
|
||||||
if ( is_serialized( $meta_value ) ) {
|
if ( is_serialized( $meta_value ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attribute_key = urldecode( str_replace( 'attribute_', '', $meta_key ) );
|
$attribute_key = urldecode( str_replace( 'attribute_', '', $meta_key ) );
|
||||||
|
|
||||||
// If this is a term slug, get the term's nice name
|
// If this is a term slug, get the term's nice name.
|
||||||
if ( taxonomy_exists( $attribute_key ) ) {
|
if ( taxonomy_exists( $attribute_key ) ) {
|
||||||
$term = get_term_by( 'slug', $meta_value, $attribute_key );
|
$term = get_term_by( 'slug', $meta_value, $attribute_key );
|
||||||
if ( ! is_wp_error( $term ) && is_object( $term ) && $term->name ) {
|
if ( ! is_wp_error( $term ) && is_object( $term ) && $term->name ) {
|
||||||
|
@ -178,7 +194,7 @@ class WC_Order_Item_Meta {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unique key required
|
// Unique key required.
|
||||||
$formatted_meta_key = $meta_key;
|
$formatted_meta_key = $meta_key;
|
||||||
$loop = 0;
|
$loop = 0;
|
||||||
while ( isset( $formatted_meta[ $formatted_meta_key ] ) ) {
|
while ( isset( $formatted_meta[ $formatted_meta_key ] ) ) {
|
||||||
|
|
Loading…
Reference in New Issue