diff --git a/includes/api/legacy/v1/class-wc-api-products.php b/includes/api/legacy/v1/class-wc-api-products.php index 7026333127d..47427dd6154 100644 --- a/includes/api/legacy/v1/class-wc-api-products.php +++ b/includes/api/legacy/v1/class-wc-api-products.php @@ -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'], diff --git a/includes/api/legacy/v2/class-wc-api-orders.php b/includes/api/legacy/v2/class-wc-api-orders.php index 2c3f74160e8..c3f6416afcd 100644 --- a/includes/api/legacy/v2/class-wc-api-orders.php +++ b/includes/api/legacy/v2/class-wc-api-orders.php @@ -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 diff --git a/includes/api/legacy/v2/class-wc-api-products.php b/includes/api/legacy/v2/class-wc-api-products.php index 41ea5b9c302..01cf9db9898 100644 --- a/includes/api/legacy/v2/class-wc-api-products.php +++ b/includes/api/legacy/v2/class-wc-api-products.php @@ -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'], diff --git a/includes/api/legacy/v3/class-wc-api-orders.php b/includes/api/legacy/v3/class-wc-api-orders.php index b9c3ff0e812..be6576c66c9 100644 --- a/includes/api/legacy/v3/class-wc-api-orders.php +++ b/includes/api/legacy/v3/class-wc-api-orders.php @@ -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 diff --git a/includes/api/legacy/v3/class-wc-api-products.php b/includes/api/legacy/v3/class-wc-api-products.php index c2d4423aab4..73d9869f079 100644 --- a/includes/api/legacy/v3/class-wc-api-products.php +++ b/includes/api/legacy/v3/class-wc-api-products.php @@ -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'], diff --git a/includes/api/v1/class-wc-rest-products-controller.php b/includes/api/v1/class-wc-rest-products-controller.php index 92d755da896..6a9bd6d458d 100644 --- a/includes/api/v1/class-wc-rest-products-controller.php +++ b/includes/api/v1/class-wc-rest-products-controller.php @@ -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, ); } diff --git a/includes/widgets/class-wc-widget-layered-nav-filters.php b/includes/widgets/class-wc-widget-layered-nav-filters.php index 1f9d1df071d..7469cda8d50 100644 --- a/includes/widgets/class-wc-widget-layered-nav-filters.php +++ b/includes/widgets/class-wc-widget-layered-nav-filters.php @@ -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 ) ); diff --git a/includes/widgets/class-wc-widget-layered-nav.php b/includes/widgets/class-wc-widget-layered-nav.php index 31b73654b2e..16d67d6ae3a 100644 --- a/includes/widgets/class-wc-widget-layered-nav.php +++ b/includes/widgets/class-wc-widget-layered-nav.php @@ -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 ); }