WordPress.org

Make WordPress Core

Ticket #14148: 14148.diff

File 14148.diff, 2.8 KB (added by kawauso, 4 years ago)

Compact patch based on danorton's but adding corrections for thumbnails and intermediate sizes. Tidy up comments a bit too.

  • media.php

     
    145145 
    146146        // try for a new style intermediate size 
    147147        if ( $intermediate = image_get_intermediate_size($id, $size) ) { 
    148                 $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); 
     148                $img_url = str_replace($img_url_basename, urlencode( $intermediate['file'] ), $img_url); 
    149149                $width = $intermediate['width']; 
    150150                $height = $intermediate['height']; 
    151151                $is_intermediate = true; 
     
    153153        elseif ( $size == 'thumbnail' ) { 
    154154                // fall back to the old thumbnail 
    155155                if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) { 
    156                         $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url); 
     156                        $img_url = str_replace($img_url_basename, urlencode( wp_basename($thumb_file) ), $img_url); 
    157157                        $width = $info[0]; 
    158158                        $height = $info[1]; 
    159159                        $is_intermediate = true; 
  • post.php

     
    38093809                return false; 
    38103810 
    38113811        $url = ''; 
    3812         if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file 
    3813                 if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { //Get upload directory 
    3814                         if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location 
    3815                                 $url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location 
    3816                         elseif ( false !== strpos($file, 'wp-content/uploads') ) 
    3817                                 $url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 ); 
    3818                         else 
    3819                                 $url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir. 
     3812        if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true ) ) { // Get attached file 
     3813                if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) { // Get upload directory 
     3814                        if ( 0 === strpos( $file, $uploads['basedir'] ) ) // Check that the upload base exists in the file location 
     3815                                $file = substr( $file, strlen( $uploads['basedir'] ) + 1 ); 
     3816                        elseif ( false !== strpos( $file, 'wp-content/uploads' ) ) 
     3817                                $file = substr( $file, strpos($file, 'wp-content/uploads' ) + 19 ); 
     3818                        $url = $uploads['baseurl'] . '/' . implode( '/', urlencode_deep( explode( '/', $file ) ) ); 
    38203819                } 
    38213820        } 
    38223821 
    3823         if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this. 
     3822        if ( empty($url) ) // If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this. 
    38243823                $url = get_the_guid( $post->ID ); 
    38253824 
    38263825        $url = apply_filters( 'wp_get_attachment_url', $url, $post->ID );