From f3335b02c80046d11574dceaf5cd5fedf7d8be72 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20Droz?= <raphael.droz+floss@gmail.com>
Date: Thu, 30 Aug 2018 11:33:39 -0300
Subject: [PATCH] #44867 image editor: save modified image as a new copy
---
wp-admin/includes/image-edit.php | 32 +++++++++++++++++++++++++++++++-
wp-admin/js/image-edit.js | 1 +
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php
index efa9865..773f3b9 100644
|
a
|
b
|
function wp_image_editor($post_id, $msg = false) { |
| 171 | 171 | <label class="imgedit-label"> |
| 172 | 172 | <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> |
| 173 | 173 | <?php _e('All sizes except thumbnail'); ?></label> |
| | 174 | |
| | 175 | <label class="imgedit-label"> |
| | 176 | <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="new" /> |
| | 177 | <?php _e('A newly created image'); ?></label> |
| 174 | 178 | </fieldset> |
| 175 | 179 | </div> |
| 176 | 180 | </div> |
| … |
… |
function wp_save_image( $post_id ) { |
| 792 | 796 | } |
| 793 | 797 | } |
| 794 | 798 | |
| | 799 | if ( 'new' == $target ) { |
| | 800 | $original_post_id = $post_id; |
| | 801 | $post_id = NULL; |
| | 802 | } |
| | 803 | |
| 795 | 804 | // Save the full-size file, also needed to create sub-sizes. |
| 796 | 805 | if ( !wp_save_image_file($new_path, $img, $post->post_mime_type, $post_id) ) { |
| 797 | 806 | $return->error = esc_js( __('Unable to save the image.') ); |
| … |
… |
function wp_save_image( $post_id ) { |
| 830 | 839 | } elseif ( 'thumbnail' == $target ) { |
| 831 | 840 | $sizes = array( 'thumbnail' ); |
| 832 | 841 | $success = $delete = $nocrop = true; |
| | 842 | } elseif ( 'new' == $target ) { |
| | 843 | $new_post = (array)$post; |
| | 844 | unset( $new_post['ID'], $new_post['post_date'], $new_post['post_date_gmt'], $new_post['post_modified'], $new_post['post_modified_gmt'] ); |
| | 845 | $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'; |
| | 846 | |
| | 847 | $wp_upload_dir = wp_upload_dir(); |
| | 848 | $new_post['guid'] = $wp_upload_dir['url'] . '/' . basename( $new_path ); |
| | 849 | $post_id = wp_insert_attachment( $new_post, $new_path, 0, TRUE ); |
| | 850 | if ( is_wp_error( $post_id ) ) { |
| | 851 | $return->error = esc_js( __('Unable to create a new atachment.') ); |
| | 852 | return $return; |
| | 853 | } |
| | 854 | $return->refresh = TRUE; |
| | 855 | $return->debug = sprintf( __( 'New attachment created: %d.'), $post_id ); |
| | 856 | $success = true; |
| | 857 | |
| | 858 | update_attached_file( $post_id, $new_path ); |
| | 859 | update_post_meta( $post_id, '_wp_attachment_derive_from', $original_post_id ); |
| | 860 | |
| | 861 | $sizes = get_intermediate_image_sizes(); |
| | 862 | $delete = $nocrop = false; |
| 833 | 863 | } |
| 834 | 864 | |
| 835 | 865 | /* |
| … |
… |
function wp_save_image( $post_id ) { |
| 886 | 916 | wp_update_attachment_metadata( $post_id, $meta ); |
| 887 | 917 | update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes); |
| 888 | 918 | |
| 889 | | if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) { |
| | 919 | if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' || $target == 'new' ) { |
| 890 | 920 | // Check if it's an image edit from attachment edit screen |
| 891 | 921 | if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' == $_REQUEST['context'] ) { |
| 892 | 922 | $thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true ); |
diff --git a/wp-admin/js/image-edit.js b/wp-admin/js/image-edit.js
index 14af25e..7c23631 100644
|
a
|
b
|
function(r) { |
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | if ( self._view ) { |
| | 499 | if ( ret.refresh ) { /* ToDo: refresh media view when going back. */ } |
| 499 | 500 | self._view.save(); |
| 500 | 501 | } else { |
| 501 | 502 | imageEdit.close(postid); |