WC_REST_Product_Attributes_V1_Controller::validate_attribute_slug() protected WC 1.0
Deprecated from version 3.2.0. It is no longer supported and can be removed in future releases. It is recommended to replace this function with the same one.╳
Validate attribute slug.
{} It's a method of the class: WC_REST_Product_Attributes_V1_Controller{}
No Hooks.
Return
true/false|WP_Error.
Usage
// protected - for code of main (parent) or child class $result = $this->validate_attribute_slug( $slug, $new_data );
- $slug(string) (required)
- -
- $new_data(true/false)
- -
Changelog
Deprecated | 3.2.0 |
Code of WC_REST_Product_Attributes_V1_Controller::validate_attribute_slug() WC REST Product Attributes V1 Controller::validate attribute slug WC 5.0.0
protected function validate_attribute_slug( $slug, $new_data = true ) {
if ( strlen( $slug ) >= 28 ) {
return new WP_Error( 'woocommerce_rest_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), array( 'status' => 400 ) );
} elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) {
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 ) ) ) {
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;
}