Make WordPress Core

Ticket #32137: 32137.6.patch

File 32137.6.patch, 2.4 KB (added by topdownjimmy, 10 years ago)

Thanks for the feedback @stephdau.

  • wp-admin/includes/media.php

     
    861861
    862862        // Finally check to make sure the file has been saved, then return the HTML.
    863863        if ( ! empty( $src ) ) {
    864                 if ( $return === 'src' ) {
     864                if ( 'src' === $return ) {
    865865                        return $src;
    866866                }
    867867
     868                if ( 'id' === $return ) {
     869                        return $id;
     870                }
     871
    868872                $alt = isset( $desc ) ? esc_attr( $desc ) : '';
    869873                $html = "<img src='$src' alt='$alt' />";
    870874                return $html;
  • wp-admin/includes/class-wp-press-this.php

     
    7979                                        continue;
    8080                                }
    8181
    82                                 // Sideload image, which gives us a new image src.
    83                                 $new_src = media_sideload_image( $image_src, $post_id, null, 'src' );
     82                                // Sideload image, which gives us a new image ID.
     83                                $image_id = media_sideload_image( $image_src, $post_id, null, 'id' );
    8484
    85                                 if ( ! is_wp_error( $new_src ) ) {
     85                                if ( ! is_wp_error( $image_id ) ) {
     86
     87                                        $image_default_size = get_option('image_default_size');
     88
     89                                        // Get the image URI from the image ID, according to image_default_size option.
     90                                        $src_array = wp_get_attachment_image_src( $image_id, $image_default_size );
     91                                        $new_src = $src_array[0];
     92                                       
     93                                        // Make sure we got an image URI
     94                                        if ( ! preg_match( '/[^\?]+\.(?:jpe?g|jpe|gif|png)(?:\?|$)/i', $new_src ) ) {
     95                                                continue;
     96                                        }
     97
    8698                                        // Replace the POSTED content <img> with correct uploaded ones.
    8799                                        // Need to do it in two steps so we don't replace links to the original image if any.
    88100                                        $new_image = str_replace( $image_src, $new_src, $image );
    89101                                        $content = str_replace( $image, $new_image, $content );
     102
     103                                        // Replace the full image size class name with default image size class name,
     104                                        // if specified.
     105                                        if ( ! preg_match( '/(class=["\'][^"^\']+)["\']/', $image, $class_matches ) ) {
     106                                                continue;
     107                                        }
     108                                        $class = $class_matches[1];
     109                                        $new_class = $class;
     110                                        if ( '' !== $image_default_size && 'full' !== $image_default_size ) {
     111                                                $new_class = str_replace( 'size-full', 'size-' . $image_default_size, $class );
     112                                        }
     113                                        $content = str_replace( $class, $new_class, $content );
    90114                                }
    91115                        }
    92116                }