diff --git src/wp-admin/includes/image-edit.php src/wp-admin/includes/image-edit.php
index 5a82b41..3d422a5 100644
|
|
|
function wp_image_editor($post_id, $msg = false) { |
| 134 | 134 | <p id="imgedit-save-target-<?php echo $post_id; ?>"> |
| 135 | 135 | <strong><?php _e('Apply changes to:'); ?></strong><br /> |
| 136 | 136 | |
| 137 | | <label class="imgedit-label"> |
| 138 | | <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="all" checked="checked" /> |
| 139 | | <?php _e('All image sizes'); ?></label> |
| | 137 | <?php |
| | 138 | $image_sizes = get_intermediate_image_sizes(); |
| | 139 | $image_sizes[] = 'full'; |
| | 140 | |
| | 141 | /** This filter is documented in wp-admin/includes/media.php */ |
| | 142 | $image_size_names = apply_filters( 'image_size_names_choose', array( |
| | 143 | 'thumbnail' => __( 'Thumbnail' ), |
| | 144 | 'medium' => __( 'Medium' ), |
| | 145 | 'large' => __( 'Large' ), |
| | 146 | 'post-thumbnail' => __( 'Featured Image' ), |
| | 147 | 'full' => __( 'Full Size' ), |
| | 148 | ) ); |
| | 149 | |
| | 150 | foreach ( $image_sizes as $image_size ) { |
| | 151 | if ( ! isset( $image_size_names[ $image_size ] ) ) { |
| | 152 | continue; |
| | 153 | } |
| | 154 | ?> |
| | 155 | |
| | 156 | <label class="imgedit-label"> |
| | 157 | <input type="checkbox" name="imgedit-target-<?php echo $post_id; ?>" value="<?php echo esc_attr( $image_size ); ?>" checked="checked" /> |
| | 158 | <?php echo esc_html( $image_size_names[ $image_size ] ); ?></label> |
| 140 | 159 | |
| 141 | | <label class="imgedit-label"> |
| 142 | | <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="thumbnail" /> |
| 143 | | <?php _e('Thumbnail'); ?></label> |
| | 160 | <?php |
| | 161 | } |
| | 162 | ?> |
| 144 | 163 | |
| 145 | | <label class="imgedit-label"> |
| 146 | | <input type="radio" name="imgedit-target-<?php echo $post_id; ?>" value="nothumb" /> |
| 147 | | <?php _e('All sizes except thumbnail'); ?></label> |
| 148 | 164 | </p> |
| 149 | 165 | </div> |
| 150 | 166 | |
| … |
… |
function wp_save_image( $post_id ) { |
| 679 | 695 | global $_wp_additional_image_sizes; |
| 680 | 696 | |
| 681 | 697 | $return = new stdClass; |
| 682 | | $success = $delete = $scaled = $nocrop = false; |
| | 698 | $success = $scaled = false; |
| 683 | 699 | $post = get_post( $post_id ); |
| 684 | 700 | |
| 685 | 701 | $img = wp_get_image_editor( _load_image_to_edit_path( $post_id, 'full' ) ); |
| … |
… |
function wp_save_image( $post_id ) { |
| 690 | 706 | |
| 691 | 707 | $fwidth = !empty($_REQUEST['fwidth']) ? intval($_REQUEST['fwidth']) : 0; |
| 692 | 708 | $fheight = !empty($_REQUEST['fheight']) ? intval($_REQUEST['fheight']) : 0; |
| 693 | | $target = !empty($_REQUEST['target']) ? preg_replace('/[^a-z0-9_-]+/i', '', $_REQUEST['target']) : ''; |
| | 709 | $target = !empty($_REQUEST['target']) ? $_REQUEST['target'] : array(); |
| 694 | 710 | $scale = !empty($_REQUEST['do']) && 'scale' == $_REQUEST['do']; |
| 695 | 711 | |
| | 712 | if ( ! is_array( $target ) ) { |
| | 713 | $target = array( $target ); |
| | 714 | } |
| | 715 | |
| | 716 | // Sanitize image sizes |
| | 717 | foreach( $target as &$image_size ) { |
| | 718 | $image_size = preg_replace( '/[^a-z0-9_-]+/i', '', $image_size ); |
| | 719 | } |
| | 720 | |
| 696 | 721 | if ( $scale && $fwidth > 0 && $fheight > 0 ) { |
| 697 | 722 | $size = $img->get_size(); |
| 698 | 723 | $sX = $size['width']; |
| … |
… |
function wp_save_image( $post_id ) { |
| 739 | 764 | if ( defined('IMAGE_EDIT_OVERWRITE') && IMAGE_EDIT_OVERWRITE && |
| 740 | 765 | isset($backup_sizes['full-orig']) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) { |
| 741 | 766 | |
| 742 | | if ( 'thumbnail' == $target ) |
| 743 | | $new_path = "{$path_parts['dirname']}/{$filename}-temp.{$path_parts['extension']}"; |
| 744 | | else |
| 745 | | $new_path = $path; |
| | 767 | $new_path = $path; |
| 746 | 768 | } else { |
| 747 | 769 | while( true ) { |
| 748 | 770 | $filename = preg_replace( '/-e([0-9]+)$/', '', $filename ); |
| … |
… |
function wp_save_image( $post_id ) { |
| 762 | 784 | return $return; |
| 763 | 785 | } |
| 764 | 786 | |
| 765 | | if ( 'nothumb' == $target || 'all' == $target || 'full' == $target || $scaled ) { |
| | 787 | if ( in_array( 'full', $target ) || $scaled ) { |
| 766 | 788 | $tag = false; |
| 767 | 789 | if ( isset($backup_sizes['full-orig']) ) { |
| 768 | 790 | if ( ( !defined('IMAGE_EDIT_OVERWRITE') || !IMAGE_EDIT_OVERWRITE ) && $backup_sizes['full-orig']['file'] != $path_parts['basename'] ) |
| … |
… |
function wp_save_image( $post_id ) { |
| 782 | 804 | $meta['width'] = $size['width']; |
| 783 | 805 | $meta['height'] = $size['height']; |
| 784 | 806 | |
| 785 | | if ( $success && ('nothumb' == $target || 'all' == $target) ) { |
| 786 | | $sizes = get_intermediate_image_sizes(); |
| 787 | | if ( 'nothumb' == $target ) |
| 788 | | $sizes = array_diff( $sizes, array('thumbnail') ); |
| 789 | | } |
| 790 | | |
| 791 | 807 | $return->fw = $meta['width']; |
| 792 | 808 | $return->fh = $meta['height']; |
| 793 | | } elseif ( 'thumbnail' == $target ) { |
| 794 | | $sizes = array( 'thumbnail' ); |
| 795 | | $success = $delete = $nocrop = true; |
| | 809 | } |
| | 810 | else { |
| | 811 | $success = true; |
| 796 | 812 | } |
| 797 | 813 | |
| 798 | | if ( isset( $sizes ) ) { |
| | 814 | /** |
| | 815 | * Previously there were radio buttons under "Apply changes to:" |
| | 816 | * and when you selected "Thumbnail", it would turn off cropping. |
| | 817 | * We want to preserve this behaviour here for now. |
| | 818 | */ |
| | 819 | $nocrop = in_array( 'thumbnail', $target ) && 1 == count( $target ); |
| | 820 | |
| | 821 | if ( $success && ! $scaled ) { |
| | 822 | $sizes = get_intermediate_image_sizes(); |
| | 823 | // Excludes 'full' and any incorrect image sizes |
| | 824 | $sizes = array_intersect( $sizes, $target ); |
| | 825 | |
| 799 | 826 | $_sizes = array(); |
| 800 | 827 | |
| 801 | 828 | foreach ( $sizes as $size ) { |
| … |
… |
function wp_save_image( $post_id ) { |
| 834 | 861 | wp_update_attachment_metadata( $post_id, $meta ); |
| 835 | 862 | update_post_meta( $post_id, '_wp_attachment_backup_sizes', $backup_sizes); |
| 836 | 863 | |
| 837 | | if ( $target == 'thumbnail' || $target == 'all' || $target == 'full' ) { |
| | 864 | if ( ! $scaled ) { |
| 838 | 865 | // Check if it's an image edit from attachment edit screen |
| 839 | 866 | if ( ! empty( $_REQUEST['context'] ) && 'edit-attachment' == $_REQUEST['context'] ) { |
| 840 | 867 | $thumb_url = wp_get_attachment_image_src( $post_id, array( 900, 600 ), true ); |
| … |
… |
function wp_save_image( $post_id ) { |
| 848 | 875 | } |
| 849 | 876 | } |
| 850 | 877 | } |
| 851 | | } else { |
| 852 | | $delete = true; |
| 853 | 878 | } |
| 854 | 879 | |
| 855 | | if ( $delete ) { |
| | 880 | if ( ! $success || ( ! $scaled && ! in_array( 'full', $target ) ) ) { |
| 856 | 881 | wp_delete_file( $new_path ); |
| 857 | 882 | } |
| 858 | 883 | |
diff --git src/wp-admin/js/image-edit.js src/wp-admin/js/image-edit.js
index 7bf2928..b8ae4a5 100644
|
|
|
var imageEdit = window.imageEdit = { |
| 68 | 68 | }, |
| 69 | 69 | |
| 70 | 70 | getTarget : function(postid) { |
| 71 | | return $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).val() || 'full'; |
| | 71 | var target = new Array(); |
| | 72 | $('input[name="imgedit-target-' + postid + '"]:checked', '#imgedit-save-target-' + postid).each(function() { |
| | 73 | target.push(jQuery(this).val()); |
| | 74 | }); |
| | 75 | return target; |
| 72 | 76 | }, |
| 73 | 77 | |
| 74 | 78 | scaleChanged : function(postid, x) { |