WC_API_Products::validate_attribute_data( string $name, string $slug, string $type, string $order_by, bool $new_data = true )
Validate attribute data.
Description Description
Parameters Parameters
- $name
-
(Required)
- $slug
-
(Required)
- $type
-
(Required)
- $order_by
-
(Required)
- $new_data
-
(Optional)
Default value: true
Return Return
(bool)
Source Source
File: includes/legacy/api/v2/class-wc-api-products.php
protected function validate_attribute_data( $name, $slug, $type, $order_by, $new_data = true ) { if ( empty( $name ) ) { throw new WC_API_Exception( 'woocommerce_api_missing_product_attribute_name', sprintf( __( 'Missing parameter %s', 'woocommerce' ), 'name' ), 400 ); } if ( strlen( $slug ) >= 28 ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_slug_too_long', sprintf( __( 'Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce' ), $slug ), 400 ); } elseif ( wc_check_if_attribute_name_is_reserved( $slug ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_slug_reserved_name', sprintf( __( 'Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce' ), $slug ), 400 ); } elseif ( $new_data && taxonomy_exists( wc_attribute_taxonomy_name( $slug ) ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_slug_already_exists', sprintf( __( 'Slug "%s" is already in use. Change it, please.', 'woocommerce' ), $slug ), 400 ); } // Validate the attribute type if ( ! in_array( wc_clean( $type ), array_keys( wc_get_attribute_types() ) ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_type', sprintf( __( 'Invalid product attribute type - the product attribute type must be any of these: %s', 'woocommerce' ), implode( ', ', array_keys( wc_get_attribute_types() ) ) ), 400 ); } // Validate the attribute order by if ( ! in_array( wc_clean( $order_by ), array( 'menu_order', 'name', 'name_num', 'id' ) ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_product_attribute_order_by', sprintf( __( 'Invalid product attribute order_by type - the product attribute order_by type must be any of these: %s', 'woocommerce' ), implode( ', ', array( 'menu_order', 'name', 'name_num', 'id' ) ) ), 400 ); } return true; }
Changelog Changelog
Version | Description |
---|---|
2.4.0 | Introduced. |