當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。