replace all remaining str_replace( 'pa_', ... with wc_attribute_taxonomy_name_raw(...)

This commit is contained in:
Ron Rennick 2018-12-03 10:57:27 -04:00
parent dc0aeb0553
commit c1ad273a03
8 changed files with 15 additions and 15 deletions

View File

@ -500,7 +500,7 @@ class WC_API_Products extends WC_API_Resource {
// taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
$attributes[] = array(
'name' => ucwords( str_replace( 'attribute_', '', str_replace( 'pa_', '', $attribute_name ) ) ),
'name' => ucwords( str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $attribute_name ) ) ),
'option' => $attribute,
);
}
@ -508,7 +508,7 @@ class WC_API_Products extends WC_API_Resource {
foreach ( $product->get_attributes() as $attribute ) {
$attributes[] = array(
'name' => ucwords( str_replace( 'pa_', '', $attribute['name'] ) ),
'name' => ucwords( wc_attribute_taxonomy_name_raw( $attribute['name'] ) ),
'position' => $attribute['position'],
'visible' => (bool) $attribute['is_visible'],
'variation' => (bool) $attribute['is_variation'],

View File

@ -973,7 +973,7 @@ class WC_API_Orders extends WC_API_Resource {
if ( isset( $variations ) && is_array( $variations ) ) {
// start by normalizing the passed variations
foreach ( $variations as $key => $value ) {
$key = str_replace( 'attribute_', '', str_replace( 'pa_', '', $key ) ); // from get_attributes in class-wc-api-products.php
$key = str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $key ) ); // from get_attributes in class-wc-api-products.php
$variations_normalized[ $key ] = strtolower( $value );
}
// now search through each product child and see if our passed variations match anything
@ -981,7 +981,7 @@ class WC_API_Orders extends WC_API_Resource {
$meta = array();
foreach ( get_post_meta( $variation ) as $key => $value ) {
$value = $value[0];
$key = str_replace( 'attribute_', '', str_replace( 'pa_', '', $key ) );
$key = str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $key ) );
$meta[ $key ] = strtolower( $value );
}
// if the variation array is a part of the $meta array, we found our match

View File

@ -1835,7 +1835,7 @@ class WC_API_Products extends WC_API_Resource {
// taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
$attributes[] = array(
'name' => wc_attribute_label( str_replace( 'attribute_', '', $attribute_name ) ),
'slug' => str_replace( 'attribute_', '', str_replace( 'pa_', '', $attribute_name ) ),
'slug' => str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $attribute_name ) ),
'option' => $attribute,
);
}
@ -1844,7 +1844,7 @@ class WC_API_Products extends WC_API_Resource {
foreach ( $product->get_attributes() as $attribute ) {
$attributes[] = array(
'name' => wc_attribute_label( $attribute['name'] ),
'slug' => str_replace( 'pa_', '', $attribute['name'] ),
'slug' => wc_attribute_taxonomy_name_raw( $attribute['name'] ),
'position' => (int) $attribute['position'],
'visible' => (bool) $attribute['is_visible'],
'variation' => (bool) $attribute['is_variation'],

View File

@ -1018,7 +1018,7 @@ class WC_API_Orders extends WC_API_Resource {
if ( isset( $variations ) && is_array( $variations ) ) {
// start by normalizing the passed variations
foreach ( $variations as $key => $value ) {
$key = str_replace( 'attribute_', '', str_replace( 'pa_', '', $key ) ); // from get_attributes in class-wc-api-products.php
$key = str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $key ) ); // from get_attributes in class-wc-api-products.php
$variations_normalized[ $key ] = strtolower( $value );
}
// now search through each product child and see if our passed variations match anything
@ -1026,7 +1026,7 @@ class WC_API_Orders extends WC_API_Resource {
$meta = array();
foreach ( get_post_meta( $variation ) as $key => $value ) {
$value = $value[0];
$key = str_replace( 'attribute_', '', str_replace( 'pa_', '', $key ) );
$key = str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $key ) );
$meta[ $key ] = strtolower( $value );
}
// if the variation array is a part of the $meta array, we found our match

View File

@ -2393,7 +2393,7 @@ class WC_API_Products extends WC_API_Resource {
// taxonomy-based attributes are prefixed with `pa_`, otherwise simply `attribute_`
$attributes[] = array(
'name' => wc_attribute_label( str_replace( 'attribute_', '', $attribute_name ), $product ),
'slug' => str_replace( 'attribute_', '', str_replace( 'pa_', '', $attribute_name ) ),
'slug' => str_replace( 'attribute_', '', wc_attribute_taxonomy_name_raw( $attribute_name ) ),
'option' => $attribute,
);
}
@ -2402,7 +2402,7 @@ class WC_API_Products extends WC_API_Resource {
foreach ( $product->get_attributes() as $attribute ) {
$attributes[] = array(
'name' => wc_attribute_label( $attribute['name'], $product ),
'slug' => str_replace( 'pa_', '', $attribute['name'] ),
'slug' => wc_attribute_taxonomy_name_raw( $attribute['name'] ),
'position' => (int) $attribute['position'],
'visible' => (bool) $attribute['is_visible'],
'variation' => (bool) $attribute['is_variation'],

View File

@ -352,7 +352,7 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
} else {
$default[] = array(
'id' => 0,
'name' => str_replace( 'pa_', '', $key ),
'name' => wc_attribute_taxonomy_name_raw( $key ),
'option' => $value,
);
}

View File

@ -65,7 +65,7 @@ class WC_Widget_Layered_Nav_Filters extends WC_Widget {
continue;
}
$filter_name = 'filter_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) );
$filter_name = 'filter_' . wc_attribute_taxonomy_name_raw( $taxonomy );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$current_filter = array_map( 'sanitize_title', $current_filter );
$new_filter = array_diff( $current_filter, array( $term_slug ) );

View File

@ -223,7 +223,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
if ( $taxonomy !== $this->get_current_taxonomy() ) {
$term_counts = $this->get_filtered_term_product_counts( wp_list_pluck( $terms, 'term_id' ), $taxonomy, $query_type );
$_chosen_attributes = WC_Query::get_layered_nav_chosen_attributes();
$taxonomy_filter_name = str_replace( 'pa_', '', $taxonomy );
$taxonomy_filter_name = wc_attribute_taxonomy_name_raw( $taxonomy );
$taxonomy_label = wc_attribute_label( $taxonomy );
/* translators: %s: taxonomy name */
@ -423,7 +423,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
continue;
}
$filter_name = 'filter_' . str_replace( 'pa_', '', $taxonomy );
$filter_name = 'filter_' . wc_attribute_taxonomy_name_raw( $taxonomy );
$current_filter = isset( $_GET[ $filter_name ] ) ? explode( ',', wc_clean( wp_unslash( $_GET[ $filter_name ] ) ) ) : array(); // WPCS: input var ok, CSRF ok.
$current_filter = array_map( 'sanitize_title', $current_filter );
@ -452,7 +452,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
// Add Query type Arg to URL.
if ( 'or' === $query_type && ! ( 1 === count( $current_filter ) && $option_is_set ) ) {
$link = add_query_arg( 'query_type_' . sanitize_title( str_replace( 'pa_', '', $taxonomy ) ), 'or', $link );
$link = add_query_arg( 'query_type_' . wc_attribute_taxonomy_name_raw( $taxonomy ), 'or', $link );
}
$link = str_replace( '%2C', ',', $link );
}