Fake duplicate images
-
Hi everyone! I have a problem that I don’t seem to find anywhere.
I have created a script that uploads images from an AWS bucket to the WordPress uploads folder. However, whenever I upload an image that gets overwritten (because it has the same image name), it becomes a duplicated in the media section, even tho the image only exists once in the uploads folder. So what is created is indeed a fake duplicate, also because if I delete (from the WordPress media section) the original images and leave the duplicates, which don’t work since they don’t in reality exist, and they are just there on the front end. I thought it would be a caching problem, but I tried deleting it, and also restarting my WordPress container (since I host it on a pc with Docker), and they are still there! In my script I do use a piece of code that triggers the library update also (so that I can see when I uploaded new images), and I’ll leave that there in case someone more expert than me can figure out if there’s a problem with that part. Thank you!!// Trigger media library update $wp_filetype = wp_check_filetype($file_name, null); $attachment = [ 'guid' => $upload_dir['url'] . '/' . $file_name, 'post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($file_name), 'post_content' => '', 'post_status' => 'inherit', ]; $attach_id = wp_insert_attachment($attachment, $upload_path); require_once ABSPATH . 'wp-admin/includes/image.php'; $attach_data = wp_generate_attachment_metadata($attach_id, $upload_path); wp_update_attachment_metadata($attach_id, $attach_data);
- The topic ‘Fake duplicate images’ is closed to new replies.