WC_REST_Product_Attributes_V1_Controller::validate_attribute_slug()protectedWC 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.

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)
The slug to validate.
$new_data(true|false)
If we are creating new data.
Default: true

Changelog

Deprecated since 3.2.0

WC_REST_Product_Attributes_V1_Controller::validate_attribute_slug() code WC 8.7.0

protected function validate_attribute_slug( $slug, $new_data = true ) {
	if ( strlen( $slug ) > 28 ) {
		/* translators: %s: slug being validated */
		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 ) ) {
		/* 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;
}