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')]); } // Define the uploads directory for downloaded images $upload_dir = wp_upload_dir(); $product_images_dir = $upload_dir['basedir'] . '/productimages'; // Ensure the directory exists if (!file_exists($product_images_dir)) { if (!wp_mkdir_p($product_images_dir)) { error_log('Failed to create directory: ' . $product_images_dir); wp_send_json_error(['message' => __('Error: Failed to create the product images directory.', 'product-imager')]); } } $attachment_ids = []; foreach ($image_urls as $image_url) { // Validate URL if (!filter_var($image_url, FILTER_VALIDATE_URL)) { error_log('Invalid image URL: ' . $image_url); continue; // Skip invalid URLs } // Fetch the image content $response = wp_remote_get($image_url, ['timeout' => 30]); if (is_wp_error($response)) { error_log('Failed to fetch image: ' . $image_url . ' - ' . $response->get_error_message()); continue; } $image_body = wp_remote_retrieve_body($response); if (empty($image_body)) { error_log('Empty image body for URL: ' . $image_url); continue; } // Save the image locally $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) { error_log('Failed to save image: ' . $file_path); continue; } else { error_log('Image successfully saved to: ' . $file_path); } // Add the image to the WordPress Media Library $attachment_id = media_handle_sideload([ 'name' => $image_name, 'tmp_name' => $file_path, ], 0); if (is_wp_error($attachment_id)) { unlink($file_path); // Clean up on failure error_log('Failed to add image to media library: ' . $image_name . ' - ' . $attachment_id->get_error_message()); continue; } else { error_log('Image successfully added to media library with ID: ' . $attachment_id); } $attachment_ids[] = $attachment_id; } if (empty($attachment_ids)) { wp_send_json_error(['message' => __('Error: No images were successfully uploaded.', 'product-imager')]); } // Set the first image as the featured image set_post_thumbnail($product_id, $attachment_ids[0]); // Add additional images to the product gallery if (count($attachment_ids) > 1) { update_post_meta($product_id, '_product_image_gallery', implode(',', array_slice($attachment_ids, 1))); } wp_send_json_success(['message' => __('Product images updated successfully!', 'product-imager')]); } Seafood – Page 7 – Horizon Foods – Wholesale Food Distributor
et-loader

Needing Assistance? Call Us: 443-402-1728
Show

Lobster Tails by the Lb

$31.13

Magic Seasoning Blackened Redfish 24-oz Can

$14.51

Magic Seasoning Blackened Redfish 4 24-oz Cans/Case

$56.53

Mahi Mahi 8-oz Individual Filet

$6.23

Mrs Fridays Breaded Shrimp 3-lb Box

$35.78

Mrs Fridays Breaded Shrimp 4/3-lb Boxes/Case

$130.71

Mrs. Fridays Popcorn Shrimp 4/2.5-lb Bags/Case

$76.04

Old Bay 1-lb Can

$12.44

Old Bay 12/1-lb Cans/Case

$134.82

Old Bay Crab Cake Seasoning Packet

$3.85

Old Bay Seasoning, 3/7.5 Lb. Bottles/Case

$178.26

Old Bay Seasoning, 7.5 Lb Bottle

$60.81
Showing 84 of 108 items
Load More

We are your go to crab meat supplier!

Premium Crab Meat

ON SALE NOW

Account Menu
Account Menu
Address

704 Pulaski Hwy, Joppatowne, MD 21085

Information

Hotline: 443-402-1728
jennifer@horizonfoodstore.com

Follow Us

Cart