Make WordPress Core

Ticket #32137: 32137.3.patch

File 32137.3.patch, 1.7 KB (added by topdownjimmy, 10 years ago)

Fixing is_wp_error check in side_load_images

  • media.php

     
    865865                        return $src;
    866866                }
    867867
     868                if ( $return === 'id' ) {
     869                        return $id;
     870                }
     871
    868872                $alt = isset( $desc ) ? esc_attr( $desc ) : '';
    869873                $html = "<img src='$src' alt='$alt' />";
    870874                return $html;
  • 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                                        // Get the image URL from the image ID, according to image_default_size option.
     88                                        $src_array = wp_get_attachment_image_src( $image_id, get_option('image_default_size') );
     89                                        $new_src = $src_array[0];
     90
    8691                                        // Replace the POSTED content <img> with correct uploaded ones.
    8792                                        // Need to do it in two steps so we don't replace links to the original image if any.
    8893                                        $new_image = str_replace( $image_src, $new_src, $image );
     94
     95                                        // Replace the full image size class name with default image size class name,
     96                                        // if specified.
     97                                        if (get_option('image_default_size') != '' && get_option('image_default_size') !== 'full') {
     98                                                $new_image = str_replace( 'size-full', 'size-' . get_option('image_default_size'), $new_image );
     99                                        }
     100
    89101                                        $content = str_replace( $image, $new_image, $content );
    90102                                }
    91103                        }