WC_REST_Product_Attributes_Controller::generate_unique_slug()
Generates a unique slug for a given attribute name. We do this so that we can create more than one attribute with the same name.
Метод класса: WC_REST_Product_Attributes_Controller{}
Хуков нет.
Возвращает
Строку
. The auto-generated slug
Использование
// private - только в коде основоного (родительского) класса $result = $this->generate_unique_slug( $attribute_name );
- $attribute_name(строка) (обязательный)
- The attribute name to generate a slug for.
Код WC_REST_Product_Attributes_Controller::generate_unique_slug() WC REST Product Attributes Controller::generate unique slug WC 9.7.1
private function generate_unique_slug( $attribute_name ) { global $wpdb; $root_slug = wc_sanitize_taxonomy_name( $attribute_name ); $results = $wpdb->get_results( $wpdb->prepare( "SELECT attribute_name FROM {$wpdb->prefix}woocommerce_attribute_taxonomies WHERE attribute_name LIKE %s ORDER BY attribute_id DESC LIMIT 1", $root_slug . '%' ) ); // The slug is already unique! if ( empty( $results ) ) { return $root_slug; } $last_created_slug = $results[0]->attribute_name; $suffix = intval( substr( $last_created_slug, strrpos( $last_created_slug, '-' ) + 1 ) ); return $root_slug . '-' . ( $suffix + 1 ); }