Changeset 3306749
- Timestamp:
- 06/04/2025 10:14:37 PM (9 months ago)
- Location:
- content-api
- Files:
-
- 4 edited
- 1 copied
-
tags/1.0.11 (copied) (copied from content-api/trunk)
-
tags/1.0.11/content-api.php (modified) (19 diffs)
-
tags/1.0.11/readme.txt (modified) (2 diffs)
-
trunk/content-api.php (modified) (19 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
content-api/tags/1.0.11/content-api.php
r3306099 r3306749 5 5 * Plugin URI: https://www.polyplugins.com/contact/ 6 6 * Description: Adds various endpoints to create content 7 * Version: 1.0.1 07 * Version: 1.0.11 8 8 * Requires at least: 6.5 9 9 * Requires PHP: 7.4 … … 16 16 namespace PolyPlugins; 17 17 18 use Exception; 18 19 use WC_Product_Attribute; 19 20 use WC_Product_Simple; … … 507 508 'weight' => $weight ? floatval($weight) : '', 508 509 'stock_status' => $stock_status ? sanitize_text_field($stock_status) : '', 509 'manage_stock' => $manage_stock ? sanitize_text_field($manage_stock) : '',510 'manage_stock' => $manage_stock ? true : false, 510 511 'stock_quantity' => $stock_quantity ? absint($product->get_stock_quantity()) : 0, 511 512 'tags' => $tags ? array_map('sanitize_text_field', $tags) : array(), … … 544 545 $weight = isset($fields['weight']) ? floatval($fields['weight']) : ''; 545 546 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 546 $manage_stock = isset($fields['manage_stock']) ? sanitize_text_field($fields['manage_stock']) : '';547 $manage_stock = isset($fields['manage_stock']) ? wc_string_to_bool($fields['manage_stock']) : null; 547 548 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : false; 548 549 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 549 550 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 551 $attributes = isset($fields['attributes']) ? $fields['attributes'] : array(); 550 552 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 551 553 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); … … 576 578 return new WP_Error('product_not_found', 'Product not found with provided SKU', array('status' => 404)); 577 579 } 578 } 579 elseif ($product_id) { 580 } elseif ($product_id) { 580 581 $product = wc_get_product($product_id); 581 582 } … … 585 586 } 586 587 588 if ($sku) { 589 $product_id_by_sku = wc_get_product_id_by_sku($sku); 590 591 if ($product_id_by_sku != $product->get_id()) { 592 return new WP_Error('product_sku_exists', 'Product with provided SKU already exists', array('status' => 404)); 593 } 594 } 595 587 596 if ($slug) { 588 // Check if slug is empty after sanitization589 if (empty($slug)) {590 return new WP_Error('slug_invalid', 'Invalid slug format', array('status' => 400));591 }592 593 597 // Check if slug already exists for a different product 594 598 $existing_product_id = get_page_by_path($slug, OBJECT, get_post_types()); 595 if ($existing_product_id && (($product_id && $existing_product_id->ID != $product_id) || ($sku && $existing_product_id->ID != wc_get_product_id_by_sku($sku)))) { 599 600 if ($existing_product_id) { 596 601 return new WP_Error('slug_exists', 'Slug already in use by another product', array('status' => 400)); 597 602 } … … 644 649 } 645 650 646 $product->update_meta_data('_global_unique_id', $upc); 651 try { 652 $product->update_meta_data('_global_unique_id', $upc); 653 } catch (Exception $e) { 654 return new WP_Error('product_exception', 'An error occurred when attempting to update UPC. It may be in use, please check your trash.', array('status' => 500)); 655 } 647 656 } 648 657 … … 655 664 } 656 665 657 if ($manage_stock == 'true') {666 if ($manage_stock === true) { 658 667 $product->set_manage_stock(true); 659 } elseif ($manage_stock == 'false') {668 } elseif ($manage_stock === false) { 660 669 $product->set_manage_stock(false); 661 670 } … … 672 681 if ($categories) { 673 682 wp_set_object_terms($product_id, $categories, 'product_cat'); 683 } 684 685 if (!empty($attributes) && is_array($attributes)) { 686 $existing_attributes = $product->get_attributes(); 687 $attributes = $this->create_or_update_product_attributes($attributes, $existing_attributes); 688 689 if (is_wp_error($attributes)) { 690 return $attributes; 691 } 692 693 // Update product attributes 694 $product->set_attributes($attributes); 674 695 } 675 696 … … 737 758 738 759 // Save the product 739 $product_id = $product->save(); 760 try { 761 $product_id = $product->save(); 762 } catch (Exception $e) { 763 return new WP_Error('product_exception', 'Error saving product. This typically happens if you are trying to create a new product with a SKU already in use, please check your trash.', array('status' => 500)); 764 } 740 765 741 766 if (!$product_id) { … … 774 799 $weight = isset($fields['weight']) ? floatval($fields['weight']) : ''; 775 800 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 776 $manage_stock = isset($fields['manage_stock']) ? sanitize_text_field($fields['manage_stock']) : '';801 $manage_stock = isset($fields['manage_stock']) ? wc_string_to_bool($fields['manage_stock']) : null; 777 802 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : false; 778 803 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 779 804 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 805 $attributes = isset($fields['attributes']) ? $fields['attributes'] : array(); 780 806 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 781 807 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); … … 798 824 if ($slug) { 799 825 // Check if slug already exists for a different product 800 if (wc_get_product_id_by_sku($sku)) { 826 $existing_product_id = get_page_by_path($slug, OBJECT, get_post_types()); 827 828 if ($existing_product_id) { 801 829 return new WP_Error('slug_exists', 'Slug already in use by another product', array('status' => 400)); 802 830 } … … 850 878 } 851 879 852 $product->update_meta_data('_global_unique_id', $upc); 880 try { 881 $product->update_meta_data('_global_unique_id', $upc); 882 } catch (Exception $e) { 883 return new WP_Error('product_exception', 'An error occurred when attempting to update UPC. It may be in use, please check your trash.', array('status' => 500)); 884 } 853 885 } 854 886 … … 861 893 } 862 894 863 if ($manage_stock == 'true') {895 if ($manage_stock === true) { 864 896 $product->set_manage_stock(true); 865 } elseif ($manage_stock == 'false') {897 } elseif ($manage_stock === false) { 866 898 $product->set_manage_stock(false); 867 899 } … … 913 945 914 946 // Save the product 915 $product_id = $product->save(); 947 try { 948 $product_id = $product->save(); 949 } catch (Exception $e) { 950 return new WP_Error('product_exception', 'Error saving product. This typically happens if you are trying to create a new product with a SKU already in use, please check your trash.', array('status' => 500)); 951 } 916 952 917 953 if ($tags) { … … 921 957 if ($categories) { 922 958 wp_set_object_terms($product_id, $categories, 'product_cat'); 959 } 960 961 if (!empty($attributes) && is_array($attributes)) { 962 $existing_attributes = $product->get_attributes(); 963 $attributes = $this->create_or_update_product_attributes($attributes, $existing_attributes); 964 965 if (is_wp_error($attributes)) { 966 return $attributes; 967 } 968 969 // Update product attributes 970 $product->set_attributes($attributes); 923 971 } 924 972 … … 945 993 } 946 994 947 $product->save(); 995 try { 996 $product->save(); 997 } catch (Exception $e) { 998 return new WP_Error('product_exception', 'An error occurred when attempting to save the product.', array('status' => 500)); 999 } 948 1000 949 1001 if (!$product_id) { … … 2141 2193 // Update product attributes 2142 2194 $product->set_attributes($existing_attributes); 2143 $product->save(); 2195 2196 try { 2197 $product->save(); 2198 } catch (Exception $e) { 2199 return new WP_Error('product_exception', 'An error occurred when attempting to save the product.', array('status' => 500)); 2200 } 2144 2201 2145 2202 return new WP_REST_Response(array( … … 2518 2575 2519 2576 /** 2577 * Create or update product attributes 2578 * 2579 * @param array $attributes 2580 * @param array $existing_attributes 2581 * @return void 2582 */ 2583 private function create_or_update_product_attributes($attributes, $existing_attributes) { 2584 // Loop through new attributes and update/add them 2585 foreach ($attributes as $attribute) { 2586 if (!isset($attribute['name']) || !isset($attribute['value'])) { 2587 return new WP_Error('invalid_attribute', "Each attribute must include 'name' and 'value'", array('status' => 400)); 2588 } 2589 2590 $attr_name = sanitize_text_field($attribute['name']); 2591 $attr_slug = sanitize_title($attribute['name']); 2592 $attr_value = is_array($attribute['value']) ? array_map('sanitize_text_field', $attribute['value']) : array(sanitize_text_field($attribute['value'])); 2593 $taxonomy = wc_attribute_taxonomy_name($attr_slug); 2594 2595 if (!taxonomy_exists($taxonomy)) { 2596 $attribute_args = array( 2597 'name' => $attr_name, 2598 'slug' => $attr_slug, 2599 ); 2600 2601 $create_taxonomy = wc_create_attribute($attribute_args); 2602 2603 register_taxonomy( 2604 $taxonomy, 2605 apply_filters('woocommerce_taxonomy_objects_' . $taxonomy, array('product')), 2606 apply_filters('woocommerce_taxonomy_args_' . $taxonomy, array( 2607 'labels' => array( 2608 'name' => $attr_name, 2609 ), 2610 'hierarchical' => true, 2611 'show_ui' => false, 2612 'query_var' => true, 2613 'rewrite' => false, 2614 ) 2615 ) 2616 ); 2617 } 2618 2619 // Check if it's a global attribute (taxonomy-based) 2620 if (taxonomy_exists($taxonomy)) { 2621 // Ensure terms exist before assigning 2622 $term_ids = array(); 2623 2624 foreach ($attr_value as $term_name) { 2625 $term = term_exists($term_name, $taxonomy); 2626 2627 if (!$term) { 2628 $term = wp_insert_term($term_name, $taxonomy); 2629 } 2630 2631 if (!is_wp_error($term)) { 2632 $term_ids[] = (int) $term['term_id']; 2633 } 2634 } 2635 2636 // Set taxonomy-based attribute 2637 $existing_attributes[$taxonomy] = new WC_Product_Attribute(); 2638 $existing_attributes[$taxonomy]->set_id(wc_attribute_taxonomy_id_by_name($attr_slug)); 2639 $existing_attributes[$taxonomy]->set_name($taxonomy); 2640 $existing_attributes[$taxonomy]->set_options($term_ids); 2641 $existing_attributes[$taxonomy]->set_position(0); 2642 $existing_attributes[$taxonomy]->set_visible(true); 2643 $existing_attributes[$taxonomy]->set_variation(false); 2644 } else { 2645 return new WP_Error('attribute_does_not_exist', "The attribute ". $attr_slug . " does not exist. Attempt to create failed.", array('status' => 400)); 2646 } 2647 } 2648 2649 return $existing_attributes; 2650 } 2651 2652 /** 2520 2653 * Get product IDs with missing descriptions 2521 2654 * -
content-api/tags/1.0.11/readme.txt
r3306099 r3306749 3 3 Tags: content api, rest api, content, creative, api 4 4 Tested up to: 6.8 5 Stable tag: 1.0.1 05 Stable tag: 1.0.11 6 6 Requires PHP: 7.4 7 7 License: GPLv3 … … 85 85 == Changelog == 86 86 87 = 1.0.11 = 88 * Updated: [Get Product](https://www.polyplugins.com/docs/content-api/api/get-product/) manage_stock attribute to return a bool 89 * Updated: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) manage_stock attribute to be able to use bool 90 * Updated: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) manage_stock attribute to be able to use bool 91 * Bugfix: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) attributes attribute not creating product attributes when they don't exist. 92 * Bugfix: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) attributes attribute not creating product attributes when they don't exist. 93 * Bugfix: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) triggering error sku during slug check 94 * Bugfix: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) triggering error sku during slug check 95 * Bugfix: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) triggering Exception instead of WP Error when upc attribute is already in use 96 * Bugfix: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) triggering Exception instead of WP Error when upc attribute is already in use 97 87 98 = 1.0.10 = 88 99 * Updated: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) endpoint to not require quantity -
content-api/trunk/content-api.php
r3306099 r3306749 5 5 * Plugin URI: https://www.polyplugins.com/contact/ 6 6 * Description: Adds various endpoints to create content 7 * Version: 1.0.1 07 * Version: 1.0.11 8 8 * Requires at least: 6.5 9 9 * Requires PHP: 7.4 … … 16 16 namespace PolyPlugins; 17 17 18 use Exception; 18 19 use WC_Product_Attribute; 19 20 use WC_Product_Simple; … … 507 508 'weight' => $weight ? floatval($weight) : '', 508 509 'stock_status' => $stock_status ? sanitize_text_field($stock_status) : '', 509 'manage_stock' => $manage_stock ? sanitize_text_field($manage_stock) : '',510 'manage_stock' => $manage_stock ? true : false, 510 511 'stock_quantity' => $stock_quantity ? absint($product->get_stock_quantity()) : 0, 511 512 'tags' => $tags ? array_map('sanitize_text_field', $tags) : array(), … … 544 545 $weight = isset($fields['weight']) ? floatval($fields['weight']) : ''; 545 546 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 546 $manage_stock = isset($fields['manage_stock']) ? sanitize_text_field($fields['manage_stock']) : '';547 $manage_stock = isset($fields['manage_stock']) ? wc_string_to_bool($fields['manage_stock']) : null; 547 548 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : false; 548 549 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 549 550 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 551 $attributes = isset($fields['attributes']) ? $fields['attributes'] : array(); 550 552 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 551 553 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); … … 576 578 return new WP_Error('product_not_found', 'Product not found with provided SKU', array('status' => 404)); 577 579 } 578 } 579 elseif ($product_id) { 580 } elseif ($product_id) { 580 581 $product = wc_get_product($product_id); 581 582 } … … 585 586 } 586 587 588 if ($sku) { 589 $product_id_by_sku = wc_get_product_id_by_sku($sku); 590 591 if ($product_id_by_sku != $product->get_id()) { 592 return new WP_Error('product_sku_exists', 'Product with provided SKU already exists', array('status' => 404)); 593 } 594 } 595 587 596 if ($slug) { 588 // Check if slug is empty after sanitization589 if (empty($slug)) {590 return new WP_Error('slug_invalid', 'Invalid slug format', array('status' => 400));591 }592 593 597 // Check if slug already exists for a different product 594 598 $existing_product_id = get_page_by_path($slug, OBJECT, get_post_types()); 595 if ($existing_product_id && (($product_id && $existing_product_id->ID != $product_id) || ($sku && $existing_product_id->ID != wc_get_product_id_by_sku($sku)))) { 599 600 if ($existing_product_id) { 596 601 return new WP_Error('slug_exists', 'Slug already in use by another product', array('status' => 400)); 597 602 } … … 644 649 } 645 650 646 $product->update_meta_data('_global_unique_id', $upc); 651 try { 652 $product->update_meta_data('_global_unique_id', $upc); 653 } catch (Exception $e) { 654 return new WP_Error('product_exception', 'An error occurred when attempting to update UPC. It may be in use, please check your trash.', array('status' => 500)); 655 } 647 656 } 648 657 … … 655 664 } 656 665 657 if ($manage_stock == 'true') {666 if ($manage_stock === true) { 658 667 $product->set_manage_stock(true); 659 } elseif ($manage_stock == 'false') {668 } elseif ($manage_stock === false) { 660 669 $product->set_manage_stock(false); 661 670 } … … 672 681 if ($categories) { 673 682 wp_set_object_terms($product_id, $categories, 'product_cat'); 683 } 684 685 if (!empty($attributes) && is_array($attributes)) { 686 $existing_attributes = $product->get_attributes(); 687 $attributes = $this->create_or_update_product_attributes($attributes, $existing_attributes); 688 689 if (is_wp_error($attributes)) { 690 return $attributes; 691 } 692 693 // Update product attributes 694 $product->set_attributes($attributes); 674 695 } 675 696 … … 737 758 738 759 // Save the product 739 $product_id = $product->save(); 760 try { 761 $product_id = $product->save(); 762 } catch (Exception $e) { 763 return new WP_Error('product_exception', 'Error saving product. This typically happens if you are trying to create a new product with a SKU already in use, please check your trash.', array('status' => 500)); 764 } 740 765 741 766 if (!$product_id) { … … 774 799 $weight = isset($fields['weight']) ? floatval($fields['weight']) : ''; 775 800 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 776 $manage_stock = isset($fields['manage_stock']) ? sanitize_text_field($fields['manage_stock']) : '';801 $manage_stock = isset($fields['manage_stock']) ? wc_string_to_bool($fields['manage_stock']) : null; 777 802 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : false; 778 803 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 779 804 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 805 $attributes = isset($fields['attributes']) ? $fields['attributes'] : array(); 780 806 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 781 807 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); … … 798 824 if ($slug) { 799 825 // Check if slug already exists for a different product 800 if (wc_get_product_id_by_sku($sku)) { 826 $existing_product_id = get_page_by_path($slug, OBJECT, get_post_types()); 827 828 if ($existing_product_id) { 801 829 return new WP_Error('slug_exists', 'Slug already in use by another product', array('status' => 400)); 802 830 } … … 850 878 } 851 879 852 $product->update_meta_data('_global_unique_id', $upc); 880 try { 881 $product->update_meta_data('_global_unique_id', $upc); 882 } catch (Exception $e) { 883 return new WP_Error('product_exception', 'An error occurred when attempting to update UPC. It may be in use, please check your trash.', array('status' => 500)); 884 } 853 885 } 854 886 … … 861 893 } 862 894 863 if ($manage_stock == 'true') {895 if ($manage_stock === true) { 864 896 $product->set_manage_stock(true); 865 } elseif ($manage_stock == 'false') {897 } elseif ($manage_stock === false) { 866 898 $product->set_manage_stock(false); 867 899 } … … 913 945 914 946 // Save the product 915 $product_id = $product->save(); 947 try { 948 $product_id = $product->save(); 949 } catch (Exception $e) { 950 return new WP_Error('product_exception', 'Error saving product. This typically happens if you are trying to create a new product with a SKU already in use, please check your trash.', array('status' => 500)); 951 } 916 952 917 953 if ($tags) { … … 921 957 if ($categories) { 922 958 wp_set_object_terms($product_id, $categories, 'product_cat'); 959 } 960 961 if (!empty($attributes) && is_array($attributes)) { 962 $existing_attributes = $product->get_attributes(); 963 $attributes = $this->create_or_update_product_attributes($attributes, $existing_attributes); 964 965 if (is_wp_error($attributes)) { 966 return $attributes; 967 } 968 969 // Update product attributes 970 $product->set_attributes($attributes); 923 971 } 924 972 … … 945 993 } 946 994 947 $product->save(); 995 try { 996 $product->save(); 997 } catch (Exception $e) { 998 return new WP_Error('product_exception', 'An error occurred when attempting to save the product.', array('status' => 500)); 999 } 948 1000 949 1001 if (!$product_id) { … … 2141 2193 // Update product attributes 2142 2194 $product->set_attributes($existing_attributes); 2143 $product->save(); 2195 2196 try { 2197 $product->save(); 2198 } catch (Exception $e) { 2199 return new WP_Error('product_exception', 'An error occurred when attempting to save the product.', array('status' => 500)); 2200 } 2144 2201 2145 2202 return new WP_REST_Response(array( … … 2518 2575 2519 2576 /** 2577 * Create or update product attributes 2578 * 2579 * @param array $attributes 2580 * @param array $existing_attributes 2581 * @return void 2582 */ 2583 private function create_or_update_product_attributes($attributes, $existing_attributes) { 2584 // Loop through new attributes and update/add them 2585 foreach ($attributes as $attribute) { 2586 if (!isset($attribute['name']) || !isset($attribute['value'])) { 2587 return new WP_Error('invalid_attribute', "Each attribute must include 'name' and 'value'", array('status' => 400)); 2588 } 2589 2590 $attr_name = sanitize_text_field($attribute['name']); 2591 $attr_slug = sanitize_title($attribute['name']); 2592 $attr_value = is_array($attribute['value']) ? array_map('sanitize_text_field', $attribute['value']) : array(sanitize_text_field($attribute['value'])); 2593 $taxonomy = wc_attribute_taxonomy_name($attr_slug); 2594 2595 if (!taxonomy_exists($taxonomy)) { 2596 $attribute_args = array( 2597 'name' => $attr_name, 2598 'slug' => $attr_slug, 2599 ); 2600 2601 $create_taxonomy = wc_create_attribute($attribute_args); 2602 2603 register_taxonomy( 2604 $taxonomy, 2605 apply_filters('woocommerce_taxonomy_objects_' . $taxonomy, array('product')), 2606 apply_filters('woocommerce_taxonomy_args_' . $taxonomy, array( 2607 'labels' => array( 2608 'name' => $attr_name, 2609 ), 2610 'hierarchical' => true, 2611 'show_ui' => false, 2612 'query_var' => true, 2613 'rewrite' => false, 2614 ) 2615 ) 2616 ); 2617 } 2618 2619 // Check if it's a global attribute (taxonomy-based) 2620 if (taxonomy_exists($taxonomy)) { 2621 // Ensure terms exist before assigning 2622 $term_ids = array(); 2623 2624 foreach ($attr_value as $term_name) { 2625 $term = term_exists($term_name, $taxonomy); 2626 2627 if (!$term) { 2628 $term = wp_insert_term($term_name, $taxonomy); 2629 } 2630 2631 if (!is_wp_error($term)) { 2632 $term_ids[] = (int) $term['term_id']; 2633 } 2634 } 2635 2636 // Set taxonomy-based attribute 2637 $existing_attributes[$taxonomy] = new WC_Product_Attribute(); 2638 $existing_attributes[$taxonomy]->set_id(wc_attribute_taxonomy_id_by_name($attr_slug)); 2639 $existing_attributes[$taxonomy]->set_name($taxonomy); 2640 $existing_attributes[$taxonomy]->set_options($term_ids); 2641 $existing_attributes[$taxonomy]->set_position(0); 2642 $existing_attributes[$taxonomy]->set_visible(true); 2643 $existing_attributes[$taxonomy]->set_variation(false); 2644 } else { 2645 return new WP_Error('attribute_does_not_exist', "The attribute ". $attr_slug . " does not exist. Attempt to create failed.", array('status' => 400)); 2646 } 2647 } 2648 2649 return $existing_attributes; 2650 } 2651 2652 /** 2520 2653 * Get product IDs with missing descriptions 2521 2654 * -
content-api/trunk/readme.txt
r3306099 r3306749 3 3 Tags: content api, rest api, content, creative, api 4 4 Tested up to: 6.8 5 Stable tag: 1.0.1 05 Stable tag: 1.0.11 6 6 Requires PHP: 7.4 7 7 License: GPLv3 … … 85 85 == Changelog == 86 86 87 = 1.0.11 = 88 * Updated: [Get Product](https://www.polyplugins.com/docs/content-api/api/get-product/) manage_stock attribute to return a bool 89 * Updated: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) manage_stock attribute to be able to use bool 90 * Updated: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) manage_stock attribute to be able to use bool 91 * Bugfix: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) attributes attribute not creating product attributes when they don't exist. 92 * Bugfix: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) attributes attribute not creating product attributes when they don't exist. 93 * Bugfix: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) triggering error sku during slug check 94 * Bugfix: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) triggering error sku during slug check 95 * Bugfix: [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) triggering Exception instead of WP Error when upc attribute is already in use 96 * Bugfix: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) triggering Exception instead of WP Error when upc attribute is already in use 97 87 98 = 1.0.10 = 88 99 * Updated: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) endpoint to not require quantity
Note: See TracChangeset
for help on using the changeset viewer.