wc_attribute_taxonomy_slug cache

This commit is contained in:
Mike Jolley 2019-01-30 13:27:48 +00:00
parent a5bc236c66
commit 4622af890a
1 changed files with 11 additions and 1 deletions

View File

@ -678,6 +678,16 @@ function wc_delete_attribute( $id ) {
* @return string
*/
function wc_attribute_taxonomy_slug( $attribute_name ) {
$cache_key = 'slug-' . $attribute_name;
$cache_value = wp_cache_get( $cache_key, 'woocommerce-attributes' );
if ( $cache_value ) {
return $cache_value;
}
$attribute_name = wc_sanitize_taxonomy_name( $attribute_name );
return 0 === strpos( $attribute_name, 'pa_' ) ? substr( $attribute_name, 3 ) : $attribute_name;
$attribute_slug = 0 === strpos( $attribute_name, 'pa_' ) ? substr( $attribute_name, 3 ) : $attribute_name;
wp_cache_set( $cache_key, $attribute_slug, 'woocommerce-attributes' );
return $attribute_slug;
}