BUG when creating Attributes with Scandinavian letters
-
Solution is provided in this message of this possible Bug. Also posted at github
Some wierd stuff happend when saving new Attributes and tracked it down as follow:
When creating new Attribute with a non english letter as the first char like : ?nskas ?ngervecka
No slug is created.
It should return :
onskas-angervecka
The problem.
Attribute names seems are created outside WP and uses :
woocommerce_sanitize_taxonomy_name()
found in : woocommerce-admin-attributes.php and it seems to return an empty string when string starts with “?”. No Hooks or filters are provided to pre-filter this.
Solution
In woocommerce-admin-attributes.php Line 51 I wrapped the string to be filtered with:sanitize_title_with_dashes($_POST['attribute_name'], '', 'save')
And Line 59:
sanitize_title($attribute_label, '', 'save')
The complete lines are provided at the end of this message.
About my fix
sanitize_title() is a WP cleanup for urls, and actually not a pretty title thing. Check out the codex. Maybe there is a better filter to use.The Attribute label is not passing WPs pre_insert_term filter, like cats and tags (And attribute values (!)) and if I understand right are Woo attribute names “Virtual” taxonomies. So a FILTER HOOK of names/labels would be nice!
I created one myself (when crashing the core file anyway) to clean the Labels like I do with Category names in my theme.
function ua_woocommerce_sanitize_taxonomy_label( $taxonomy )
However, Here is the fix (ends with // QQ) in context:
// Grab the submitted data $attribute_label = ( isset( $_POST['attribute_label'] ) ) ? (string) stripslashes( $_POST['attribute_label'] ) : ''; $attribute_name = ( isset( $_POST['attribute_name'] ) ) ? woocommerce_sanitize_taxonomy_name( stripslashes( (string) sanitize_title_with_dashes($_POST['attribute_name'], '', 'save') ) ) : ''; // QQ $attribute_type = ( isset( $_POST['attribute_type'] ) ) ? (string) stripslashes( $_POST['attribute_type'] ) : ''; $attribute_orderby = ( isset( $_POST['attribute_orderby'] ) ) ? (string) stripslashes( $_POST['attribute_orderby'] ) : ''; // Auto-generate the label or slug if only one of both was provided if ( ! $attribute_label ) { $attribute_label = ucwords( $attribute_name ); } elseif ( ! $attribute_name ) { $attribute_name = woocommerce_sanitize_taxonomy_name( stripslashes( sanitize_title($attribute_label, '', 'save') ) ); // QQ }
/ Swedish developer
- The topic ‘BUG when creating Attributes with Scandinavian letters’ is closed to new replies.