Changeset 3288715
- Timestamp:
- 05/06/2025 10:23:50 PM (10 months ago)
- Location:
- content-api
- Files:
-
- 4 edited
- 1 copied
-
tags/1.0.4 (copied) (copied from content-api/trunk)
-
tags/1.0.4/content-api.php (modified) (10 diffs)
-
tags/1.0.4/readme.txt (modified) (2 diffs)
-
trunk/content-api.php (modified) (10 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
content-api/tags/1.0.4/content-api.php
r3288294 r3288715 5 5 * Plugin URI: https://www.polyplugins.com/contact/ 6 6 * Description: Adds various endpoints to create content 7 * Version: 1.0. 37 * Version: 1.0.4 8 8 * Requires at least: 6.5 9 9 * Requires PHP: 7.4 … … 17 17 18 18 use WC_Product_Attribute; 19 use WC_Product_Simple; 19 20 use WP_Error; 20 21 use WP_REST_Request; … … 60 61 'methods' => 'PATCH', 61 62 'callback' => array($this, 'update_product'), 63 'permission_callback' => array($this, 'has_permission'), // Add your permission callback for security 64 )); 65 66 register_rest_route('content-api/v1', '/product/', array( 67 'methods' => 'POST', 68 'callback' => array($this, 'create_product'), 62 69 'permission_callback' => array($this, 'has_permission'), // Add your permission callback for security 63 70 )); … … 414 421 $regular_price = $product->get_regular_price(); 415 422 $sale_price = $product->get_sale_price(); 423 $map_price = $product->get_meta('_map_price'); 424 $cost = $product->get_meta('_cost'); 416 425 $sku = $product->get_sku(); 417 426 $stock_status = $product->get_stock_status(); 418 427 $stock_quantity = $product->get_stock_quantity(); 419 428 $tags = wp_get_post_terms($product->get_id(), 'product_tag', array('fields' => 'names')); 420 $images = array_map(function($image) {return $image['src'];}, $product->get_gallery_image_ids() ? wp_get_attachment_image_src($product->get_image_id(), 'full') : array()); 429 $categories = wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'names')); 430 431 $images = array(); 432 $gallery_ids = $product->get_gallery_image_ids(); 433 434 foreach ($gallery_ids as $id) { 435 $image = wp_get_attachment_image_src($id, 'full'); 436 if ($image) { 437 $images[] = $image[0]; 438 } 439 } 440 441 $featured_image = wp_get_attachment_image_src($product->get_image_id(), 'full'); 442 443 if ($featured_image) { 444 array_unshift($images, $featured_image[0]); 445 } 446 421 447 $featured_image = wp_get_attachment_url($product->get_image_id()); 422 448 … … 429 455 'price' => $regular_price ? floatval($regular_price) : '', 430 456 'sale_price' => $sale_price ? floatval($sale_price) : '', 457 'map_price' => $map_price ? floatval($map_price) : '', 458 'cost' => $cost ? floatval($cost) : '', 431 459 'sku' => $sku ? sanitize_text_field($sku) : '', 432 460 'stock_status' => $stock_status ? sanitize_text_field($product->get_stock_status()) : '', 433 461 'stock_quantity' => $stock_quantity ? absint($product->get_stock_quantity()) : 0, 434 462 'tags' => $tags ? array_map('sanitize_text_field', $tags) : array(), 463 'categories' => $categories ? array_map('sanitize_text_field', $categories) : array(), 435 464 'images' => $images ? array_map('esc_url_raw', $images) : array(), 436 465 'featured_image' => $featured_image ? esc_url_raw($featured_image) : '', … … 457 486 $price = isset($fields['price']) ? floatval($fields['price']) : ''; 458 487 $sale_price = isset($fields['sale_price']) ? floatval($fields['sale_price']) : ''; 488 $map_price = isset($fields['map_price']) ? floatval($fields['map_price']) : ''; 489 $cost = isset($fields['cost']) ? floatval($fields['cost']) : ''; 459 490 $sku = isset($fields['sku']) ? sanitize_text_field($fields['sku']) : ''; 460 491 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 461 492 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : ''; 462 493 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 494 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 463 495 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 464 496 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); … … 540 572 } 541 573 574 if ($map_price) { 575 $product->update_meta_data('_map_price', $map_price); 576 } 577 578 if ($cost) { 579 $product->update_meta_data('_cost', $cost); 580 } 581 542 582 if ($sku) { 543 583 $product->set_sku($sku); … … 549 589 550 590 if ($stock_quantity) { 591 $product->set_manage_stock(true); 551 592 $product->set_stock_quantity($stock_quantity); 552 593 } … … 554 595 if ($tags) { 555 596 wp_set_object_terms($product_id, $tags, 'product_tag'); 597 } 598 599 if ($categories) { 600 wp_set_object_terms($product_id, $categories, 'product_cat'); 556 601 } 557 602 … … 630 675 'product_id' => $product_id, 631 676 'message' => 'Product updated successfully' 677 ), 200); 678 } 679 680 /** 681 * Create product 682 * 683 * @param mixed $request 684 * @return void 685 */ 686 public function create_product(WP_REST_Request $request) { 687 $this->options = get_option('content_api_options_polyplugins'); 688 689 $fields = $request->get_json_params(); 690 $name = isset($fields['name']) ? sanitize_text_field($fields['name']) : ''; 691 $status = isset($fields['status']) ? sanitize_text_field($fields['status']) : 'draft'; 692 $slug = isset($fields['slug']) ? sanitize_title($fields['slug']) : ''; 693 $description = isset($fields['description']) ? wp_kses_post($fields['description']) : ''; 694 $short_description = isset($fields['short_description']) ? wp_kses_post($fields['short_description']) : ''; 695 $price = isset($fields['price']) ? floatval($fields['price']) : ''; 696 $sale_price = isset($fields['sale_price']) ? floatval($fields['sale_price']) : ''; 697 $map_price = isset($fields['map_price']) ? floatval($fields['map_price']) : ''; 698 $cost = isset($fields['cost']) ? floatval($fields['cost']) : ''; 699 $sku = isset($fields['sku']) ? sanitize_text_field($fields['sku']) : ''; 700 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 701 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : ''; 702 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 703 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 704 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 705 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); 706 $yoast = isset($fields['yoast']) ? $fields['yoast'] : ''; 707 708 if ($sku) { 709 if ($sku !== sanitize_text_field($sku)) { 710 return new WP_Error('sku_invalid', 'SKU is invalid', array('status' => 400)); 711 } 712 } 713 714 if ($sku) { 715 $product_id_by_sku = wc_get_product_id_by_sku($sku); 716 717 if ($product_id_by_sku) { 718 return new WP_Error('product_sku_exists', 'Product with provided SKU already exists', array('status' => 404)); 719 } 720 } 721 722 if ($slug) { 723 // Check if slug already exists for a different product 724 if (wc_get_product_id_by_sku($sku)) { 725 return new WP_Error('slug_exists', 'Slug already in use by another product', array('status' => 400)); 726 } 727 } 728 729 $product = new WC_Product_Simple(); 730 731 if ($name) { 732 $product->set_name($name); 733 } 734 735 if ($status) { 736 $product->set_status($status); 737 } 738 739 if ($slug) { 740 $product->set_slug($slug); 741 } 742 743 if ($description) { 744 $product->set_description($description); 745 } 746 747 if ($short_description) { 748 $product->set_short_description($short_description); 749 } 750 751 if ($price) { 752 $product->set_regular_price($price); 753 } 754 755 if ($sale_price) { 756 $product->set_sale_price($sale_price); 757 } 758 759 if ($map_price) { 760 $product->update_meta_data('_map_price', $map_price); 761 } 762 763 if ($cost) { 764 $product->update_meta_data('_cost', $cost); 765 } 766 767 if ($sku) { 768 $product->set_sku($sku); 769 } 770 771 if ($stock_status) { 772 $product->set_stock_status($stock_status); 773 } 774 775 if ($stock_quantity) { 776 $product->set_manage_stock(true); 777 $product->set_stock_quantity($stock_quantity); 778 } 779 780 // Assign Yoast Meta Title 781 if (isset($yoast['title'])) { 782 $product->update_meta_data('_yoast_wpseo_title', sanitize_text_field($yoast['title'])); 783 } 784 785 // Assign Yoast Meta Description 786 if (isset($yoast['description'])) { 787 $product->update_meta_data('_yoast_wpseo_metadesc', sanitize_text_field($yoast['description'])); 788 } 789 790 // Assign Yoast Facebook Open Graph Title 791 if (isset($yoast['premium']['social_appearance']['title'])) { 792 $product->update_meta_data('_yoast_wpseo_opengraph-title', sanitize_text_field($yoast['premium']['social_appearance']['title'])); 793 } 794 795 // Assign Yoast Facebook Open Graph Description 796 if (isset($yoast['premium']['social_appearance']['description'])) { 797 $product->update_meta_data('_yoast_wpseo_opengraph-description', sanitize_text_field($yoast['premium']['social_appearance']['description'])); 798 } 799 800 // Assign Yoast Facebook Open Graph Image 801 if (isset($yoast['premium']['social_appearance']['image'])) { 802 $product->update_meta_data('_yoast_wpseo_opengraph-image', sanitize_url($yoast['premium']['social_appearance']['image'])); 803 } 804 805 // Assign Yoast Facebook Open Graph Title 806 if (isset($yoast['premium']['x']['title'])) { 807 $product->update_meta_data('_yoast_wpseo_twitter-title', sanitize_text_field($yoast['premium']['x']['title'])); 808 } 809 810 // Assign Yoast Facebook Open Graph Description 811 if (isset($yoast['premium']['x']['description'])) { 812 $product->update_meta_data('_yoast_wpseo_twitter-description', sanitize_text_field($yoast['premium']['x']['description'])); 813 } 814 815 // Assign Yoast Facebook Open Graph Image 816 if (isset($yoast['premium']['x']['image'])) { 817 $product->update_meta_data('_yoast_wpseo_twitter-image', sanitize_url($yoast['premium']['x']['image'])); 818 } 819 820 // Save the product 821 $product_id = $product->save(); 822 823 if ($tags) { 824 wp_set_object_terms($product_id, $tags, 'product_tag'); 825 } 826 827 if ($categories) { 828 wp_set_object_terms($product_id, $categories, 'product_cat'); 829 } 830 831 // Handle featured image 832 if ($featured_image) { 833 $image_id = $this->upload_image_to_media_library($featured_image, $product_id); 834 835 if ($image_id && !is_wp_error($image_id)) { 836 $product->set_image_id($image_id); 837 } 838 } 839 840 // Handle gallery images 841 if ($images) { 842 $image_ids = array(); 843 foreach ($images as $image_url) { 844 $image_id = $this->upload_image_to_media_library($image_url, $product_id); 845 if ($image_id && !is_wp_error($image_id)) { 846 $image_ids[] = $image_id; 847 } 848 } 849 850 $product->set_gallery_image_ids($image_ids); 851 } 852 853 $product->save(); 854 855 if (!$product_id) { 856 return new WP_Error('creation_failed', 'Failed to create product', array('status' => 500)); 857 } 858 859 // Return success response 860 return new WP_REST_Response(array( 861 'success' => true, 862 'product_id' => $product_id, 863 'message' => 'Product created successfully' 632 864 ), 200); 633 865 } -
content-api/tags/1.0.4/readme.txt
r3288294 r3288715 3 3 Tags: content api, rest api, content, creative, api 4 4 Tested up to: 6.8 5 Stable tag: 1.0. 35 Stable tag: 1.0.4 6 6 Requires PHP: 7.4 7 7 License: GPLv3 … … 85 85 == Changelog == 86 86 87 = 1.0.4 = 88 * Added: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) endpoint 89 * Added: cost, map_price, and categories attributes to [Get Product](https://www.polyplugins.com/docs/content-api/api/get-product/) endpoint 90 * Added: cost, map_price, and categories attributes to [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) endpoint 91 * Bugfix: Get Product endpoint error when fetching images 92 87 93 = 1.0.3 = 88 94 * Added: [Get Product Category](https://www.polyplugins.com/docs/content-api/api/get-product-category/) endpoint -
content-api/trunk/content-api.php
r3288294 r3288715 5 5 * Plugin URI: https://www.polyplugins.com/contact/ 6 6 * Description: Adds various endpoints to create content 7 * Version: 1.0. 37 * Version: 1.0.4 8 8 * Requires at least: 6.5 9 9 * Requires PHP: 7.4 … … 17 17 18 18 use WC_Product_Attribute; 19 use WC_Product_Simple; 19 20 use WP_Error; 20 21 use WP_REST_Request; … … 60 61 'methods' => 'PATCH', 61 62 'callback' => array($this, 'update_product'), 63 'permission_callback' => array($this, 'has_permission'), // Add your permission callback for security 64 )); 65 66 register_rest_route('content-api/v1', '/product/', array( 67 'methods' => 'POST', 68 'callback' => array($this, 'create_product'), 62 69 'permission_callback' => array($this, 'has_permission'), // Add your permission callback for security 63 70 )); … … 414 421 $regular_price = $product->get_regular_price(); 415 422 $sale_price = $product->get_sale_price(); 423 $map_price = $product->get_meta('_map_price'); 424 $cost = $product->get_meta('_cost'); 416 425 $sku = $product->get_sku(); 417 426 $stock_status = $product->get_stock_status(); 418 427 $stock_quantity = $product->get_stock_quantity(); 419 428 $tags = wp_get_post_terms($product->get_id(), 'product_tag', array('fields' => 'names')); 420 $images = array_map(function($image) {return $image['src'];}, $product->get_gallery_image_ids() ? wp_get_attachment_image_src($product->get_image_id(), 'full') : array()); 429 $categories = wp_get_post_terms($product->get_id(), 'product_cat', array('fields' => 'names')); 430 431 $images = array(); 432 $gallery_ids = $product->get_gallery_image_ids(); 433 434 foreach ($gallery_ids as $id) { 435 $image = wp_get_attachment_image_src($id, 'full'); 436 if ($image) { 437 $images[] = $image[0]; 438 } 439 } 440 441 $featured_image = wp_get_attachment_image_src($product->get_image_id(), 'full'); 442 443 if ($featured_image) { 444 array_unshift($images, $featured_image[0]); 445 } 446 421 447 $featured_image = wp_get_attachment_url($product->get_image_id()); 422 448 … … 429 455 'price' => $regular_price ? floatval($regular_price) : '', 430 456 'sale_price' => $sale_price ? floatval($sale_price) : '', 457 'map_price' => $map_price ? floatval($map_price) : '', 458 'cost' => $cost ? floatval($cost) : '', 431 459 'sku' => $sku ? sanitize_text_field($sku) : '', 432 460 'stock_status' => $stock_status ? sanitize_text_field($product->get_stock_status()) : '', 433 461 'stock_quantity' => $stock_quantity ? absint($product->get_stock_quantity()) : 0, 434 462 'tags' => $tags ? array_map('sanitize_text_field', $tags) : array(), 463 'categories' => $categories ? array_map('sanitize_text_field', $categories) : array(), 435 464 'images' => $images ? array_map('esc_url_raw', $images) : array(), 436 465 'featured_image' => $featured_image ? esc_url_raw($featured_image) : '', … … 457 486 $price = isset($fields['price']) ? floatval($fields['price']) : ''; 458 487 $sale_price = isset($fields['sale_price']) ? floatval($fields['sale_price']) : ''; 488 $map_price = isset($fields['map_price']) ? floatval($fields['map_price']) : ''; 489 $cost = isset($fields['cost']) ? floatval($fields['cost']) : ''; 459 490 $sku = isset($fields['sku']) ? sanitize_text_field($fields['sku']) : ''; 460 491 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 461 492 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : ''; 462 493 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 494 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 463 495 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 464 496 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); … … 540 572 } 541 573 574 if ($map_price) { 575 $product->update_meta_data('_map_price', $map_price); 576 } 577 578 if ($cost) { 579 $product->update_meta_data('_cost', $cost); 580 } 581 542 582 if ($sku) { 543 583 $product->set_sku($sku); … … 549 589 550 590 if ($stock_quantity) { 591 $product->set_manage_stock(true); 551 592 $product->set_stock_quantity($stock_quantity); 552 593 } … … 554 595 if ($tags) { 555 596 wp_set_object_terms($product_id, $tags, 'product_tag'); 597 } 598 599 if ($categories) { 600 wp_set_object_terms($product_id, $categories, 'product_cat'); 556 601 } 557 602 … … 630 675 'product_id' => $product_id, 631 676 'message' => 'Product updated successfully' 677 ), 200); 678 } 679 680 /** 681 * Create product 682 * 683 * @param mixed $request 684 * @return void 685 */ 686 public function create_product(WP_REST_Request $request) { 687 $this->options = get_option('content_api_options_polyplugins'); 688 689 $fields = $request->get_json_params(); 690 $name = isset($fields['name']) ? sanitize_text_field($fields['name']) : ''; 691 $status = isset($fields['status']) ? sanitize_text_field($fields['status']) : 'draft'; 692 $slug = isset($fields['slug']) ? sanitize_title($fields['slug']) : ''; 693 $description = isset($fields['description']) ? wp_kses_post($fields['description']) : ''; 694 $short_description = isset($fields['short_description']) ? wp_kses_post($fields['short_description']) : ''; 695 $price = isset($fields['price']) ? floatval($fields['price']) : ''; 696 $sale_price = isset($fields['sale_price']) ? floatval($fields['sale_price']) : ''; 697 $map_price = isset($fields['map_price']) ? floatval($fields['map_price']) : ''; 698 $cost = isset($fields['cost']) ? floatval($fields['cost']) : ''; 699 $sku = isset($fields['sku']) ? sanitize_text_field($fields['sku']) : ''; 700 $stock_status = isset($fields['stock_status']) ? sanitize_text_field($fields['stock_status']) : ''; 701 $stock_quantity = isset($fields['stock_quantity']) ? intval($fields['stock_quantity']) : ''; 702 $tags = isset($fields['tags']) && is_array($fields['tags']) ? array_map('sanitize_text_field', $fields['tags']) : array(); 703 $categories = isset($fields['categories']) && is_array($fields['categories']) ? array_map('sanitize_text_field', $fields['categories']) : array(); 704 $featured_image = isset($fields['featured_image']) ? sanitize_url($fields['featured_image']) : ''; 705 $images = isset($fields['images']) && is_array($fields['images']) ? array_map('sanitize_url', $fields['images']) : array(); 706 $yoast = isset($fields['yoast']) ? $fields['yoast'] : ''; 707 708 if ($sku) { 709 if ($sku !== sanitize_text_field($sku)) { 710 return new WP_Error('sku_invalid', 'SKU is invalid', array('status' => 400)); 711 } 712 } 713 714 if ($sku) { 715 $product_id_by_sku = wc_get_product_id_by_sku($sku); 716 717 if ($product_id_by_sku) { 718 return new WP_Error('product_sku_exists', 'Product with provided SKU already exists', array('status' => 404)); 719 } 720 } 721 722 if ($slug) { 723 // Check if slug already exists for a different product 724 if (wc_get_product_id_by_sku($sku)) { 725 return new WP_Error('slug_exists', 'Slug already in use by another product', array('status' => 400)); 726 } 727 } 728 729 $product = new WC_Product_Simple(); 730 731 if ($name) { 732 $product->set_name($name); 733 } 734 735 if ($status) { 736 $product->set_status($status); 737 } 738 739 if ($slug) { 740 $product->set_slug($slug); 741 } 742 743 if ($description) { 744 $product->set_description($description); 745 } 746 747 if ($short_description) { 748 $product->set_short_description($short_description); 749 } 750 751 if ($price) { 752 $product->set_regular_price($price); 753 } 754 755 if ($sale_price) { 756 $product->set_sale_price($sale_price); 757 } 758 759 if ($map_price) { 760 $product->update_meta_data('_map_price', $map_price); 761 } 762 763 if ($cost) { 764 $product->update_meta_data('_cost', $cost); 765 } 766 767 if ($sku) { 768 $product->set_sku($sku); 769 } 770 771 if ($stock_status) { 772 $product->set_stock_status($stock_status); 773 } 774 775 if ($stock_quantity) { 776 $product->set_manage_stock(true); 777 $product->set_stock_quantity($stock_quantity); 778 } 779 780 // Assign Yoast Meta Title 781 if (isset($yoast['title'])) { 782 $product->update_meta_data('_yoast_wpseo_title', sanitize_text_field($yoast['title'])); 783 } 784 785 // Assign Yoast Meta Description 786 if (isset($yoast['description'])) { 787 $product->update_meta_data('_yoast_wpseo_metadesc', sanitize_text_field($yoast['description'])); 788 } 789 790 // Assign Yoast Facebook Open Graph Title 791 if (isset($yoast['premium']['social_appearance']['title'])) { 792 $product->update_meta_data('_yoast_wpseo_opengraph-title', sanitize_text_field($yoast['premium']['social_appearance']['title'])); 793 } 794 795 // Assign Yoast Facebook Open Graph Description 796 if (isset($yoast['premium']['social_appearance']['description'])) { 797 $product->update_meta_data('_yoast_wpseo_opengraph-description', sanitize_text_field($yoast['premium']['social_appearance']['description'])); 798 } 799 800 // Assign Yoast Facebook Open Graph Image 801 if (isset($yoast['premium']['social_appearance']['image'])) { 802 $product->update_meta_data('_yoast_wpseo_opengraph-image', sanitize_url($yoast['premium']['social_appearance']['image'])); 803 } 804 805 // Assign Yoast Facebook Open Graph Title 806 if (isset($yoast['premium']['x']['title'])) { 807 $product->update_meta_data('_yoast_wpseo_twitter-title', sanitize_text_field($yoast['premium']['x']['title'])); 808 } 809 810 // Assign Yoast Facebook Open Graph Description 811 if (isset($yoast['premium']['x']['description'])) { 812 $product->update_meta_data('_yoast_wpseo_twitter-description', sanitize_text_field($yoast['premium']['x']['description'])); 813 } 814 815 // Assign Yoast Facebook Open Graph Image 816 if (isset($yoast['premium']['x']['image'])) { 817 $product->update_meta_data('_yoast_wpseo_twitter-image', sanitize_url($yoast['premium']['x']['image'])); 818 } 819 820 // Save the product 821 $product_id = $product->save(); 822 823 if ($tags) { 824 wp_set_object_terms($product_id, $tags, 'product_tag'); 825 } 826 827 if ($categories) { 828 wp_set_object_terms($product_id, $categories, 'product_cat'); 829 } 830 831 // Handle featured image 832 if ($featured_image) { 833 $image_id = $this->upload_image_to_media_library($featured_image, $product_id); 834 835 if ($image_id && !is_wp_error($image_id)) { 836 $product->set_image_id($image_id); 837 } 838 } 839 840 // Handle gallery images 841 if ($images) { 842 $image_ids = array(); 843 foreach ($images as $image_url) { 844 $image_id = $this->upload_image_to_media_library($image_url, $product_id); 845 if ($image_id && !is_wp_error($image_id)) { 846 $image_ids[] = $image_id; 847 } 848 } 849 850 $product->set_gallery_image_ids($image_ids); 851 } 852 853 $product->save(); 854 855 if (!$product_id) { 856 return new WP_Error('creation_failed', 'Failed to create product', array('status' => 500)); 857 } 858 859 // Return success response 860 return new WP_REST_Response(array( 861 'success' => true, 862 'product_id' => $product_id, 863 'message' => 'Product created successfully' 632 864 ), 200); 633 865 } -
content-api/trunk/readme.txt
r3288294 r3288715 3 3 Tags: content api, rest api, content, creative, api 4 4 Tested up to: 6.8 5 Stable tag: 1.0. 35 Stable tag: 1.0.4 6 6 Requires PHP: 7.4 7 7 License: GPLv3 … … 85 85 == Changelog == 86 86 87 = 1.0.4 = 88 * Added: [Create Product](https://www.polyplugins.com/docs/content-api/api/create-product/) endpoint 89 * Added: cost, map_price, and categories attributes to [Get Product](https://www.polyplugins.com/docs/content-api/api/get-product/) endpoint 90 * Added: cost, map_price, and categories attributes to [Update Product](https://www.polyplugins.com/docs/content-api/api/update-product/) endpoint 91 * Bugfix: Get Product endpoint error when fetching images 92 87 93 = 1.0.3 = 88 94 * Added: [Get Product Category](https://www.polyplugins.com/docs/content-api/api/get-product-category/) endpoint
Note: See TracChangeset
for help on using the changeset viewer.