File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -649,6 +649,24 @@ public function replace( $args, $assoc_args = array() ) {
649649 && is_array ( $ old_metadata )
650650 ) {
651651 $ this ->remove_old_images ( $ old_metadata , $ old_fullsizepath , array () );
652+
653+ // Also delete the previous full-size file itself to avoid leaving an orphan.
654+ if ( $ old_fullsizepath !== $ new_file_path && file_exists ( $ old_fullsizepath ) ) {
655+ @unlink ( $ old_fullsizepath );
656+ }
657+
658+ // For big-image scaling (WP 5.3+), delete the original image if present in metadata.
659+ if ( ! empty ( $ old_metadata ['original_image ' ] ) && ! empty ( $ old_metadata ['file ' ] ) ) {
660+ $ uploads = wp_get_upload_dir ();
661+ if ( ! empty ( $ uploads ['basedir ' ] ) ) {
662+ $ dirname = dirname ( $ old_metadata ['file ' ] );
663+ $ original_image_rel = ( '. ' === $ dirname || '/ ' === $ dirname ) ? $ old_metadata ['original_image ' ] : $ dirname . '/ ' . $ old_metadata ['original_image ' ];
664+ $ original_image_abspath = $ uploads ['basedir ' ] . '/ ' . $ original_image_rel ;
665+ if ( $ original_image_abspath !== $ new_file_path && file_exists ( $ original_image_abspath ) ) {
666+ @unlink ( $ original_image_abspath );
667+ }
668+ }
669+ }
652670 }
653671
654672 // Update the attachment's MIME type.
You can’t perform that action at this time.
0 commit comments