Created
April 30, 2026 20:06
-
-
Save drzraf/07448c98ea75424e605c788521d38b52 to your computer and use it in GitHub Desktop.
WordPress #44867 patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php | |
| # https://core.trac.wordpress.org/raw-attachment/ticket/44867/fullpatch-v9-44867-image-editor-save-modified-image-as-a-new-copy.patch (gist'ed since WP now requires auth to download raw file) | |
| index 7f9ebf7f9f..9037bcb34d 100644 | |
| --- a/wp-admin/includes/image-edit.php | |
| +++ b/wp-admin/includes/image-edit.php | |
| @@ -310,6 +310,11 @@ function wp_image_editor( $post_id, $msg = false ) { | |
| <label for="imgedit-target-thumbnail"><?php _e( 'Thumbnail' ); ?></label> | |
| </span> | |
| + <span class="imgedit-label"> | |
| + <input type="radio" id="imgedit-target-newfile" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> | |
| + <label for="imgedit-target-newfile"><?php _e('A newly created image'); ?></label> | |
| + </span> | |
| + | |
| <span class="imgedit-label"> | |
| <input type="radio" id="imgedit-target-nothumb" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> | |
| <label for="imgedit-target-nothumb"><?php _e( 'All sizes except thumbnail' ); ?></label> | |
| @@ -1006,6 +1011,11 @@ function wp_save_image( $post_id ) { | |
| } | |
| } | |
| + if ('new' == $target) { | |
| + $original_post_id = $post_id; | |
| + $post_id = NULL; | |
| + } | |
| + | |
| $saved_image = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ); | |
| // Save the full-size file, also needed to create sub-sizes. | |
| if ( ! $saved_image ) { | |
| @@ -1059,6 +1069,31 @@ function wp_save_image( $post_id ) { | |
| $success = true; | |
| $delete = true; | |
| $nocrop = true; | |
| + } elseif ( 'new' === $target ) { | |
| + $size = $img->get_size(); | |
| + $meta['width'] = $size['width']; // cropped and saved as a copy | |
| + $meta['height'] = $size['height']; | |
| + | |
| + $new_post = (array)$post; | |
| + unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); | |
| + $new_post['post_title'] = preg_match('/\.[a-z]{3}$/', $new_post['post_title']) ? preg_replace('/(\.[a-z]{3})/', '-media-copy\1', $new_post['post_title']) : $new_post['post_title'] . '-mediacopy'; | |
| + | |
| + $wp_upload_dir = wp_upload_dir(); | |
| + $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); | |
| + $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); | |
| + if ( is_wp_error( $post_id ) ) { | |
| + $return->error = esc_js( __('Unable to create a new atachment.') ); | |
| + return $return; | |
| + } | |
| + $return->refresh = TRUE; | |
| + $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); | |
| + $success = true; | |
| + | |
| + update_attached_file( $post_id, $new_path ); | |
| + update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); | |
| + | |
| + $sizes = get_intermediate_image_sizes(); | |
| + $delete = $nocrop = false; | |
| } | |
| /* | |
| diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js | |
| index d1603051d7..8c87418a21 100644 | |
| --- a/wp-admin/js/image-edit.js | |
| +++ b/wp-admin/js/image-edit.js | |
| @@ -780,6 +780,7 @@ | |
| } | |
| if ( self._view ) { | |
| + if ( response.data.refresh ) { /* ToDo: refresh media view when going back. */ } | |
| self._view.save(); | |
| } else { | |
| imageEdit.close(postid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment