Better workaround for #2975

This commit is contained in:
Mike Jolley 2013-04-16 15:39:07 +01:00
parent 6a96cc5d4c
commit 003dab8525
6 changed files with 11 additions and 20 deletions

View File

@ -352,8 +352,8 @@ function woocommerce_product_data_box() {
continue;
// Get product data values for current taxonomy - this contains ordering and visibility data
if ( isset( $attributes[ $attribute_taxonomy_name ] ) )
$attribute = $attributes[ $attribute_taxonomy_name ];
if ( isset( $attributes[ sanitize_title( $attribute_taxonomy_name ) ] ) )
$attribute = $attributes[ sanitize_title( $attribute_taxonomy_name ) ];
$position = empty( $attribute['position'] ) ? 0 : absint( $attribute['position'] );
@ -772,7 +772,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
if ( $values ) {
// Add attribute to array, but don't set values
$attributes[ woocommerce_sanitize_taxonomy_name( $attribute_names[ $i ] ) ] = array(
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
'name' => woocommerce_clean( $attribute_names[ $i ] ),
'value' => '',
'position' => $attribute_position[ $i ],
@ -788,7 +788,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
$values = implode( ' | ', array_map( 'woocommerce_clean', explode( '|', $attribute_values[ $i ] ) ) );
// Custom attribute - Add attribute to array and set the values
$attributes[ woocommerce_sanitize_taxonomy_name( $attribute_names[ $i ] ) ] = array(
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
'name' => woocommerce_clean( $attribute_names[ $i ] ),
'value' => $values,
'position' => $attribute_position[ $i ],

View File

@ -1122,7 +1122,7 @@ class WC_Product {
function get_attribute( $attr ) {
$attributes = $this->get_attributes();
$attr = woocommerce_sanitize_taxonomy_name( $attr );
$attr = sanitize_title( $attr );
if ( isset( $attributes[ $attr ] ) || isset( $attributes[ 'pa_' . $attr ] ) ) {

View File

@ -277,7 +277,7 @@ class WC_Checkout {
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $values['quantity'] ) )
woocommerce_add_order_item_meta( $item_id, apply_filters( 'woocommerce_backordered_item_meta_name', __( 'Backordered', 'woocommerce' ), $cart_item_key, $order_id ), $values['quantity'] - max( 0, $_product->get_total_stock() ) );
//allow plugins to add order item meta
// Allow plugins to add order item meta
do_action( 'woocommerce_add_order_item_meta', $item_id, $values );
}
}

View File

@ -31,7 +31,7 @@ global $woocommerce, $product, $post;
$selected_value = isset( $_POST[ 'attribute_' . sanitize_title( $name ) ] ) ? $_POST[ 'attribute_' . sanitize_title( $name ) ] : '';
// Get terms if this is a taxonomy - ordered
if ( taxonomy_exists( sanitize_title( $name ) ) ) {
if ( taxonomy_exists( $name ) ) {
$orderby = $woocommerce->attribute_orderby( $name );
@ -47,7 +47,7 @@ global $woocommerce, $product, $post;
break;
}
$terms = get_terms( sanitize_title( $name ), $args );
$terms = get_terms( $name, $args );
foreach ( $terms as $term ) {
if ( ! in_array( $term->slug, $options ) )

View File

@ -464,7 +464,7 @@ function woocommerce_save_attributes() {
if ( $values ) {
// Add attribute to array, but don't set values
$attributes[ woocommerce_sanitize_taxonomy_name( $attribute_names[ $i ] ) ] = array(
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
'name' => woocommerce_clean( $attribute_names[ $i ] ),
'value' => '',
'position' => $attribute_position[ $i ],
@ -480,7 +480,7 @@ function woocommerce_save_attributes() {
$values = implode( ' | ', array_map( 'woocommerce_clean', array_map( 'stripslashes', explode( '|', $attribute_values[ $i ] ) ) ) );
// Custom attribute - Add attribute to array and set the values
$attributes[ woocommerce_sanitize_taxonomy_name( $attribute_names[ $i ] ) ] = array(
$attributes[ sanitize_title( $attribute_names[ $i ] ) ] = array(
'name' => woocommerce_clean( $attribute_names[ $i ] ),
'value' => $values,
'position' => $attribute_position[ $i ],

View File

@ -95,21 +95,12 @@ function woocommerce_get_product_ids_on_sale() {
* @return void
*/
function woocommerce_sanitize_taxonomy_name( $taxonomy ) {
// If taxonomy name already has pa_ in front, don't sanitize the pa_ part
if ( strpos( $taxonomy, 'pa_' ) === 0 ) {
$taxonomy = substr( $taxonomy, 3 );
$prepend = 'pa_';
} else {
$prepend = '';
}
$taxonomy = strtolower( stripslashes( strip_tags( $taxonomy ) ) );
$taxonomy = preg_replace( '/&.+?;/', '', $taxonomy ); // Kill entities
$taxonomy = str_replace( array( '.', '\'', '"' ), '', $taxonomy ); // Kill quotes and full stops.
$taxonomy = str_replace( array( ' ', '_' ), '-', $taxonomy ); // Replace spaces and underscores.
return $prepend . $taxonomy;
return $taxonomy;
}
/**