Make WordPress Core

Ticket #20657: 20657.8.patch

File 20657.8.patch, 3.1 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/custom-header.php

     
    788788        <?php } ?>
    789789        <?php wp_nonce_field( 'custom-header-crop-image' ) ?>
    790790
    791         <?php submit_button( __( 'Crop and Publish' ) ); ?>
     791        <p class="submit"><?php
     792        submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false );
     793        if ( isset( $oitar ) && 1 == $oitar )
     794                submit_button( __( 'Skip Cropping, Use Image as Is' ), 'primary', 'skip-cropping', false );
     795        ?>
    792796        </p>
    793797</form>
    794798</div>
     
    867871                else
    868872                        $dst_width = get_theme_support( 'custom-header', 'width' );
    869873
    870                 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
    871                 if ( ! $cropped || is_wp_error( $cropped ) )
    872                         wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
     874                if ( ! isset( $_POST['skip-cropping'] ) ) {
     875                        $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
     876                        if ( ! $cropped || is_wp_error( $cropped ) )
     877                                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
     878                } else {
     879                        $cropped = get_attached_file( $attachment_id );
     880                }
    873881
    874882                $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
    875                 $is_cropped = ( get_attached_file( $attachment_id ) != $cropped );
    876883
    877884                $parent = get_post($attachment_id);
    878885                $parent_url = $parent->guid;
     
    890897                        'guid' => $url,
    891898                        'context' => 'custom-header'
    892899                );
    893                 if ( ! empty( $_POST['new-attachment'] ) )
     900                if ( ! empty( $_POST['new-attachment'] ) && ! isset( $_POST['skip-cropping'] ) )
    894901                        unset( $object['ID'] );
    895902
    896903                // Update the attachment
     
    913920                $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
    914921                if ( file_exists( $medium ) )
    915922                        @unlink( apply_filters( 'wp_delete_file', $medium ) );
    916                 if ( empty( $_POST['new-attachment'] ) && $is_cropped )
     923                if ( empty( $_POST['new-attachment'] ) && ! isset( $_POST['skip-cropping'] ) )
    917924                        @unlink( apply_filters( 'wp_delete_file', $original ) );
    918925
    919926                return $this->finished();
  • wp-admin/includes/image.php

     
    4444 * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
    4545 */
    4646function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
    47         if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h )
    48                 return ( is_numeric( $src ) ) ? get_attached_file( $src ) : $src;
    49 
    5047        if ( is_numeric( $src ) ) { // Handle int as attachment ID
    5148                $src_file = get_attached_file( $src );
    5249                if ( ! file_exists( $src_file ) ) {