This commit is contained in:
IGNY8 VPS (Salman)
2026-01-10 07:04:24 +00:00
parent be2c190eca
commit ceee9ba34d
8 changed files with 269 additions and 75 deletions

View File

@@ -847,6 +847,7 @@ function igny8_set_featured_image($post_id, $image_data) {
/**
* Set image gallery for post (1-5 images)
* Also saves structured image metadata with caption, prompt, position, and is_featured
*
* @param int $post_id Post ID
* @param array $gallery_images Array of image URLs or image data
@@ -854,11 +855,12 @@ function igny8_set_featured_image($post_id, $image_data) {
*/
function igny8_set_image_gallery($post_id, $gallery_images) {
$attachment_ids = array();
$imported_images_meta = array();
// Limit to 5 images
$gallery_images = array_slice($gallery_images, 0, 5);
foreach ($gallery_images as $image_data) {
foreach ($gallery_images as $index => $image_data) {
$image_url = is_array($image_data) ? ($image_data['url'] ?? $image_data['src'] ?? '') : $image_data;
if (empty($image_url)) {
@@ -875,6 +877,18 @@ function igny8_set_image_gallery($post_id, $gallery_images) {
if ($attachment_id) {
$attachment_ids[] = $attachment_id;
// Build structured image data for template use
$img_meta = array(
'attachment_id' => $attachment_id,
'url' => wp_get_attachment_url($attachment_id),
'position' => is_array($image_data) ? (isset($image_data['position']) ? intval($image_data['position']) : $index) : $index,
'prompt' => is_array($image_data) ? ($image_data['prompt'] ?? '') : '',
'caption' => is_array($image_data) ? ($image_data['caption'] ?? '') : '',
'is_featured' => is_array($image_data) ? (isset($image_data['is_featured']) && $image_data['is_featured']) : false,
);
$imported_images_meta[] = $img_meta;
}
}
@@ -887,6 +901,11 @@ function igny8_set_image_gallery($post_id, $gallery_images) {
update_post_meta($post_id, '_gallery_images', $attachment_ids); // Generic
}
// Store structured image metadata for template rendering
if (!empty($imported_images_meta)) {
update_post_meta($post_id, '_igny8_imported_images', $imported_images_meta);
}
return $attachment_ids;
}