WC_REST_Product_Attributes_V1_Controller::validate_attribute_slug
Устарела с версии 3.2.0. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.
Validate attribute slug.
Метод класса: WC_REST_Product_Attributes_V1_Controller{}
Хуков нет.
Возвращает
bool|WP_Error.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->validate_attribute_slug( $slug, $new_data );
- $slug(строка) (обязательный)
- The slug to validate.
- $new_data(true|false)
- If we are creating new data.
По умолчанию:true
Список изменений
| Устарела с | 3.2.0 |
Код WC_REST_Product_Attributes_V1_Controller::validate_attribute_slug() WC REST Product Attributes V1 Controller::validate attribute slug WC 11.1.2
protected function validate_attribute_slug( $slug, $new_data = true ) {
// Validate slug length against the byte budget left by WordPress's 32-byte taxonomy
// name limit once the 'pa_' prefix is accounted for (see wc_get_attribute_slug_max_byte_length()).
$slug_byte_length = strlen( $slug );
$max_byte_length = wc_get_attribute_slug_max_byte_length();
if ( $slug_byte_length > $max_byte_length ) {
return new WP_Error(
'woocommerce_rest_invalid_product_attribute_slug_too_long',
/* translators: %s: slug being validated */
sprintf( __( 'Slug "%s" is too long. Please use a shorter slug.', 'woocommerce' ), $slug ),
array(
'status' => 400,
'slug_byte_length' => $slug_byte_length,
'slug_byte_length_limit' => $max_byte_length,
)
);
} elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) {
/* translators: %s: slug being validated */
return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
} elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) {
/* translators: %s: slug being validated */
return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
}
return true;
}