-
Notifications
You must be signed in to change notification settings - Fork 14
Saved featured image on post save #1028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -112,8 +112,8 @@ public function insert_attachments( $images ) { | |||||||||||||||||||||||||||||||||
| $existing = $this->check_existing_attachments( $images ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| foreach ( $images as $image ) { | ||||||||||||||||||||||||||||||||||
| if ( ! isset( $image['isEdit'] ) && array_key_exists( $image['meta']['resourceS3'], $existing ) ) { | ||||||||||||||||||||||||||||||||||
| $ids[] = $existing[ $image['meta']['resourceS3'] ]; | ||||||||||||||||||||||||||||||||||
| if ( ! isset( $image['isEdit'] ) && array_key_exists( $image['resourceS3'], $existing ) ) { | ||||||||||||||||||||||||||||||||||
| $ids[] = $existing[ $image['resourceS3'] ]; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
@@ -143,7 +143,7 @@ private function insert_attachment( $image ) { | |||||||||||||||||||||||||||||||||
| $args = [ | ||||||||||||||||||||||||||||||||||
| 'post_title' => $name, | ||||||||||||||||||||||||||||||||||
| 'post_type' => 'attachment', | ||||||||||||||||||||||||||||||||||
| 'post_mime_type' => $image['meta']['mimeType'], | ||||||||||||||||||||||||||||||||||
| 'post_mime_type' => $image['mimeType'], | ||||||||||||||||||||||||||||||||||
| 'guid' => $image['url'], | ||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -153,24 +153,24 @@ private function insert_attachment( $image ) { | |||||||||||||||||||||||||||||||||
| return $id; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| update_post_meta( $id, self::OM_DAM_IMPORTED_FLAG, $image['meta']['resourceS3'] ); | ||||||||||||||||||||||||||||||||||
| update_post_meta( $id, self::OM_DAM_IMPORTED_FLAG, $image['resourceS3'] ); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ( isset( $image['isEdit'] ) ) { | ||||||||||||||||||||||||||||||||||
| update_post_meta( $id, self::IS_EDIT_FLAG, true ); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| $metadata = []; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| $metadata['file'] = '/id:' . $image['meta']['resourceS3'] . '/' . get_home_url() . '/' . $filename; | ||||||||||||||||||||||||||||||||||
| $metadata['mime-type'] = $image['meta']['mimeType']; | ||||||||||||||||||||||||||||||||||
| $metadata['file'] = '/id:' . $image['resourceS3'] . '/' . get_home_url() . '/' . $filename; | ||||||||||||||||||||||||||||||||||
| $metadata['mime-type'] = $image['mimeType']; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
Comment on lines
146
to
166
|
||||||||||||||||||||||||||||||||||
| if ( isset( $image['meta']['filesize'] ) ) { | ||||||||||||||||||||||||||||||||||
| $metadata['filesize'] = $image['meta']['fileSize']; | ||||||||||||||||||||||||||||||||||
| if ( isset( $image['fileSize'] ) ) { | ||||||||||||||||||||||||||||||||||
| $metadata['fileSize'] = $image['fileSize']; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if ( isset( $image['meta']['originalWidth'] ) && isset( $image['meta']['originalHeight'] ) ) { | ||||||||||||||||||||||||||||||||||
| $metadata['width'] = $image['meta']['originalWidth']; | ||||||||||||||||||||||||||||||||||
| $metadata['height'] = $image['meta']['originalHeight']; | ||||||||||||||||||||||||||||||||||
| if ( isset( $image['originalWidth'] ) && isset( $image['originalHeight'] ) ) { | ||||||||||||||||||||||||||||||||||
| $metadata['width'] = $image['originalWidth']; | ||||||||||||||||||||||||||||||||||
| $metadata['height'] = $image['originalHeight']; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| wp_update_attachment_metadata( $id, $metadata ); | ||||||||||||||||||||||||||||||||||
|
|
@@ -197,7 +197,6 @@ private function insert_attachment( $image ) { | |||||||||||||||||||||||||||||||||
| * @return array $image. | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
| public function alter_attachment_image_src( $image, $attachment_id, $size, $icon ) { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Skip if not DAM image. | ||||||||||||||||||||||||||||||||||
| if ( ! $this->is_dam_imported_image( $attachment_id ) ) { | ||||||||||||||||||||||||||||||||||
| return $image; | ||||||||||||||||||||||||||||||||||
|
|
@@ -287,7 +286,7 @@ private function check_existing_attachments( $images ) { | |||||||||||||||||||||||||||||||||
| $remaining = array_filter( | ||||||||||||||||||||||||||||||||||
| $images, | ||||||||||||||||||||||||||||||||||
| function ( $image ) use ( $already_imported ) { | ||||||||||||||||||||||||||||||||||
| return ! array_key_exists( $image['meta']['resourceS3'], $already_imported ); | ||||||||||||||||||||||||||||||||||
| return ! array_key_exists( $image['resourceS3'], $already_imported ); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
| return ! array_key_exists( $image['resourceS3'], $already_imported ); | |
| // Support both top-level `resourceS3` and nested `meta.resourceS3`. | |
| $resource_key = null; | |
| if ( isset( $image['resourceS3'] ) ) { | |
| $resource_key = $image['resourceS3']; | |
| } elseif ( isset( $image['meta'] ) && is_array( $image['meta'] ) && isset( $image['meta']['resourceS3'] ) ) { | |
| $resource_key = $image['meta']['resourceS3']; | |
| } | |
| // If we cannot determine a resource key, treat the image as not yet imported. | |
| if ( null === $resource_key ) { | |
| return true; | |
| } | |
| return ! array_key_exists( $resource_key, $already_imported ); |
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop now pulls S3 ids from $image['resourceS3'], but other parts of the codebase (and tests) provide meta.resourceS3. If the incoming images still contain the nested meta object, the query will be built with empty/undefined values and existing attachments won’t be detected. Consider normalizing $images before calling get_dam_imported_attachments() or reading from both keys here.
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_offloaded_attachments() now uses $image['resourceS3'] when building the LIKE and map key. If the images payload is still { meta: { resourceS3: ... } }, this will break offloaded-attachment detection and can cause duplicate inserts. Normalize the image structure before this point or fall back to $image['meta']['resourceS3'].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$imagesobjects are still sent through the media modal without any normalization (seeassets/src/media/modal/messageHandler.js), and the existing unit tests build DAM images as{ url, meta: { resourceS3, mimeType, ... } }. Switching to$image['resourceS3']here will trigger undefined-index notices and prevent duplicate detection when the payload still containsmeta.resourceS3. Consider normalizing once at the start ofinsert_attachments()(or in the REST handler) to support both shapes ($image['resourceS3'] ?? $image['meta']['resourceS3'] ?? null).