File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -720,9 +720,11 @@ private function make_copy( $path ) {
720720 * Finds an existing attachment whose basename matches the given filename.
721721 *
722722 * Searches the `_wp_attached_file` post meta, which stores the path relative to
723- * the uploads directory (e.g. '2026/03/image.jpg' or just 'image.jpg'). Matches
724- * the first attachment found when multiple files share the same basename across
725- * different upload subdirectories.
723+ * the uploads directory (e.g. '2026/03/image.jpg' or just 'image.jpg'). Also
724+ * checks `_wp_original_image_file` (absolute path, WP 5.3+) to handle images
725+ * that were scaled down on upload (stored as 'image-scaled.jpg') but whose
726+ * original filename is still 'image.jpg'. Matches the first attachment found
727+ * when multiple files share the same basename across different subdirectories.
726728 *
727729 * @param string $basename Filename basename to search for (e.g. 'image.jpg').
728730 * @return int|false Attachment ID if found, false otherwise.
@@ -746,7 +748,7 @@ private function find_duplicate_attachment( $basename ) {
746748 ON p.ID = pm.post_id
747749 WHERE p.post_type = 'attachment'
748750 AND p.post_status != 'trash'
749- AND pm.meta_key = '_wp_attached_file'
751+ AND pm.meta_key IN ( '_wp_attached_file', '_wp_original_image_file')
750752 AND ( pm.meta_value = %s OR RIGHT(pm.meta_value, %d) = %s )
751753 LIMIT 1 " ,
752754 $ basename ,
You can’t perform that action at this time.
0 commit comments