From 88d9e0e2b7997eb0c96dc737082c91b4e3f7ca6e Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 17 Jun 2026 15:10:37 +0000
Subject: [PATCH] =Fixed for single image upload fields populating the image meta. Need to check galleries now.
---
inc/managers/queue/executors/UploadExecutor.php | 57 +++++++++++++++++++++++++++++++++------------------------
1 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/inc/managers/queue/executors/UploadExecutor.php b/inc/managers/queue/executors/UploadExecutor.php
index 11fec65..b825232 100644
--- a/inc/managers/queue/executors/UploadExecutor.php
+++ b/inc/managers/queue/executors/UploadExecutor.php
@@ -288,6 +288,7 @@
error_log('Processing Meta Update with data: '.print_r($data, true));
foreach ($data as $uploadId => $info) {
if (!is_array($info)) {
+ error_log('Not an array for processing meta update: '.print_r($info, true));
continue;
}
$success = true;
@@ -313,8 +314,6 @@
continue;
}
-
-
$this->applyMeta($attachmentId, $info);
$updatedCount++;
$progress->advance(1);
@@ -325,10 +324,11 @@
$errors[] = $e->getMessage();
}
- if ($success) {
+ if ($success && $attachmentId) {
$postID = wp_get_post_parent_id($attachmentId);
if ($postID && !in_array($postID, $postsAttachedTo)){
$postsAttachedTo[] = $postID;
+ //TODO: is there a better way?
}
}
@@ -638,7 +638,7 @@
foreach($childPosts as $i => $imgID) {
$treatment = $i + 1;
- $child = $this->createTimelinePoint($imgID, $parent, $args['user'], $args['post_type'], $title, $treatment);
+ $child = $this->createTimelinePoint($imgID, $parent, $args['post_author'], $args['post_type'], $title, $treatment);
if ($child && !is_wp_error($child) && $child> 0 ) {
$createdChildren[] = $child;
$usedUploads[] = $imgID;
@@ -681,14 +681,7 @@
private function updateTimelineMetadata(int $parentId): void
{
// Get all child posts
- $children = get_children([
- 'post_parent' => $parentId,
- 'post_type' => get_post_type($parentId),
- 'post_status' => ['publish', 'draft'],
- 'orderby' => 'date',
- 'order' => 'DESC',
- 'fields' => 'ids'
- ]);
+ $children = jvbTimelinePoints($parentId, get_post_type($parentId), ['any']);
// Count includes parent + children
$number = count($children) + 1;
@@ -704,24 +697,40 @@
private function applyMeta(int $attachmentId, array $metadata): void
{
- if (array_key_exists('image-alt-text', $metadata)) {
- update_post_meta($attachmentId, '_wp_attachment_image_alt', sanitize_text_field($metadata['image-alt-text']));
- }
-
$postUpdates = [];
+ foreach ($metadata as $key => $value) {
+ //Remove the image_data| from the meta's group formatting
+ $base = 'image_data|';
+ $key = str_replace($base, '', $key);
+ if ($key === 'image-alt-text') {
+ error_log('Updating Image Alt Text: '.print_r($value, true));
+ update_post_meta($attachmentId, '_wp_attachment_image_alt', sanitize_text_field($value));
+ continue;
+ }
- if (array_key_exists('image-title', $metadata)) {
- $postUpdates['post_title'] = sanitize_text_field($metadata['image-title']);
+ $k = match ($key) {
+ 'image-title' => 'post_title',
+ 'image-caption' => 'post_excerpt',
+ 'image-description' => 'post_content',
+ default => false
+ };
+ if (!$k) {
+ error_log('No matching key for '.$key.' with value: '.print_r($value, true));
+ continue;
+ }
+ $v = match ($key) {
+ 'image-title' => sanitize_text_field($value),
+ default => sanitize_textarea_field($value)
+ };
+ $postUpdates[$k] = $v;
+
}
- if (array_key_exists('image-caption', $metadata)) {
- $postUpdates['post_excerpt'] = sanitize_textarea_field($metadata['image-caption']);
- }
- if (array_key_exists('image-description', $metadata)) {
- $postUpdates['post_excerpt']= sanitize_textarea_field($metadata['image-caption']);
- }
if (!empty($postUpdates)){
$postUpdates['ID'] = $attachmentId;
+ $postUpdates['post_type'] = 'attachment';
+
+ error_log('Updating Image post with data: '.print_r($postUpdates, true));
wp_update_post($postUpdates);
}
}
--
Gitblit v1.10.0