Make WordPress Core

Ticket #32137: 32137.7.patch

File 32137.7.patch, 2.3 KB (added by topdownjimmy, 11 years ago)

FIX: I think this may be a better approach for validating the output of wp_get_attachment_image_src? I'm not positive.

  • 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
     92                                        if ( !empty($src_array) ) {
     93                                                continue;
     94                                        }
     95                                        $new_src = $src_array[0];
     96
    8697                                        // Replace the POSTED content <img> with correct uploaded ones.
    8798                                        // Need to do it in two steps so we don't replace links to the original image if any.
    8899                                        $new_image = str_replace( $image_src, $new_src, $image );
    89100                                        $content = str_replace( $image, $new_image, $content );
     101
     102                                        // Replace the full image size class name with default image size class name,
     103                                        // if specified.
     104                                        if ( ! preg_match( '/(class=["\'][^"^\']+)["\']/', $image, $class_matches ) ) {
     105                                                continue;
     106                                        }
     107                                        $class = $class_matches[1];
     108                                        $new_class = $class;
     109                                        if ( '' !== $image_default_size && 'full' !== $image_default_size ) {
     110                                                $new_class = str_replace( 'size-full', 'size-' . $image_default_size, $class );
     111                                        }
     112                                        $content = str_replace( $class, $new_class, $content );
    90113                                }
    91114                        }
    92115                }