Only logged in customers who have purchased this product may leave a review.
function product_imager_set_images() { check_ajax_referer('product_imager_nonce', 'security'); $product_id = isset($_POST['product_id']) ? intval($_POST['product_id']) : 0; $image_urls = isset($_POST['image_urls']) ? (array) $_POST['image_urls'] : []; if (empty($product_id)) { wp_send_json_error(['message' => __('Error: Product ID is missing.', 'product-imager')]); } if (empty($image_urls)) { wp_send_json_error(['message' => __('Error: No images were selected.', 'product-imager')]); } // Example logic for testing download without changing existing functionality $upload_dir = wp_upload_dir(); $product_images_dir = $upload_dir['basedir'] . '/productimages'; if (!file_exists($product_images_dir)) { if (!wp_mkdir_p($product_images_dir)) { wp_send_json_error(['message' => __('Error: Failed to create directory for images.', 'product-imager')]); } } $successful_downloads = []; foreach ($image_urls as $image_url) { if (!filter_var($image_url, FILTER_VALIDATE_URL)) { continue; } $image_data = wp_remote_get($image_url); if (is_wp_error($image_data)) { continue; } $image_body = wp_remote_retrieve_body($image_data); $image_name = sanitize_file_name(basename(parse_url($image_url, PHP_URL_PATH))); $file_path = $product_images_dir . '/' . $image_name; if (file_put_contents($file_path, $image_body) !== false) { $successful_downloads[] = $file_path; } } if (empty($successful_downloads)) { wp_send_json_error(['message' => __('Error: No images were downloaded successfully.', 'product-imager')]); } wp_send_json_success(['message' => __('Images downloaded successfully!', 'product-imager')]); }
Only logged in customers who have purchased this product may leave a review.
Online Market Place.
A RESTONE Site.
Reviews
There are no reviews yet.