当前位置: 首页>>代码示例>>PHP>>正文


PHP wc_check_if_attribute_name_is_reserved函数代码示例

本文整理汇总了PHP中wc_check_if_attribute_name_is_reserved函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_check_if_attribute_name_is_reserved函数的具体用法?PHP wc_check_if_attribute_name_is_reserved怎么用?PHP wc_check_if_attribute_name_is_reserved使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wc_check_if_attribute_name_is_reserved函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: valid_attribute_name

 /**
  * See if an attribute name is valid
  * @param  string $attribute_name
  * @return bool|WP_error result
  */
 private static function valid_attribute_name($attribute_name)
 {
     if (strlen($attribute_name) >= 28) {
         return new WP_Error('error', sprintf(__('Slug "%s" is too long (28 characters max). Shorten it, please.', 'woocommerce'), sanitize_title($attribute_name)));
     } elseif (wc_check_if_attribute_name_is_reserved($attribute_name)) {
         return new WP_Error('error', sprintf(__('Slug "%s" is not allowed because it is a reserved term. Change it, please.', 'woocommerce'), sanitize_title($attribute_name)));
     }
     return true;
 }
开发者ID:CannedHead,项目名称:feelingsurf,代码行数:14,代码来源:class-wc-admin-attributes.php

示例2: validate_attribute_data

 /**
  * Validate attribute data.
  *
  * @since  2.4.0
  * @param  string $name
  * @param  string $slug
  * @param  string $type
  * @param  string $order_by
  * @param  bool   $new_data
  * @return bool
  */
 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);
     } else {
         if (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);
         } else {
             if ($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;
 }
开发者ID:haltaction,项目名称:woocommerce,代码行数:37,代码来源:class-wc-api-products.php

示例3: validate_attribute_slug

 /**
  * Validate attribute slug.
  *
  * @param string $slug
  * @param bool $new_data
  * @return bool|WP_Error
  */
 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).', '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.', '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.', 'woocommerce'), $slug), array('status' => 400));
     }
     return true;
 }
开发者ID:tlovett1,项目名称:woocommerce,代码行数:18,代码来源:class-wc-rest-product-attributes-controller.php


注:本文中的wc_check_if_attribute_name_is_reserved函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。