Changeset 35498
- Timestamp:
- 11/04/2015 12:21:23 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r35491 r35498 887 887 */ 888 888 function _wp_upload_dir_baseurl() { 889 static $baseurl = null; 890 891 if ( ! $baseurl ) { 889 static $baseurl = array(); 890 891 $blog_id = get_current_blog_id(); 892 893 if ( empty( $baseurl[$blog_id] ) ) { 892 894 $uploads_dir = wp_upload_dir(); 893 $baseurl = $uploads_dir['baseurl'];894 } 895 896 return $baseurl ;895 $baseurl[$blog_id] = $uploads_dir['baseurl']; 896 } 897 898 return $baseurl[$blog_id]; 897 899 } 898 900 … … 946 948 } 947 949 948 $image_ url= $image[0];950 $image_src = $image[0]; 949 951 $size_array = array( 950 952 absint( $image[1] ), … … 952 954 ); 953 955 954 return wp_calculate_image_srcset( $image_ url, $size_array, $image_meta, $attachment_id );956 return wp_calculate_image_srcset( $image_src, $size_array, $image_meta, $attachment_id ); 955 957 } 956 958 … … 960 962 * @since 4.4.0 961 963 * 962 * @param string $image_ name The file name, path, URL, or partial path or URL, of the image being matched.964 * @param string $image_src The 'src' of the image. 963 965 * @param array $size_array Array of width and height values in pixels (in that order). 964 966 * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. … … 966 968 * @return string|bool The 'srcset' attribute value. False on error or when only one source exists. 967 969 */ 968 function wp_calculate_image_srcset( $image_ name, $size_array, $image_meta, $attachment_id = 0 ) {970 function wp_calculate_image_srcset( $image_src, $size_array, $image_meta, $attachment_id = 0 ) { 969 971 if ( empty( $image_meta['sizes'] ) ) { 970 972 return false; … … 981 983 return false; 982 984 } 985 986 $image_basename = wp_basename( $image_meta['file'] ); 987 $image_baseurl = _wp_upload_dir_baseurl(); 983 988 984 989 // Add full size to the '$image_sizes' array. … … 986 991 'width' => $image_meta['width'], 987 992 'height' => $image_meta['height'], 988 'file' => wp_basename( $image_meta['file'] ),993 'file' => $image_basename, 989 994 ); 990 995 991 $image_baseurl = _wp_upload_dir_baseurl(); 992 $dirname = dirname( $image_meta['file'] ); 993 994 if ( $dirname !== '.' ) { 995 $image_baseurl = path_join( $image_baseurl, $dirname ); 996 } 996 // Uploads are (or have been) in year/month sub-directories. 997 if ( $image_basename !== $image_meta['file'] ) { 998 $dirname = dirname( $image_meta['file'] ); 999 1000 if ( $dirname !== '.' ) { 1001 $image_baseurl = trailingslashit( $image_baseurl ) . $dirname; 1002 } 1003 } 1004 1005 $image_baseurl = trailingslashit( $image_baseurl ); 997 1006 998 1007 // Calculate the image aspect ratio. … … 1004 1013 * out images that are leftovers from previous versions. 1005 1014 */ 1006 $image_edited = preg_match( '/-e[0-9]{13}/', $image_name, $image_edit_hash );1015 $image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash ); 1007 1016 1008 1017 /** … … 1034 1043 continue; 1035 1044 } 1036 1037 $candidate_url = $image['file'];1038 1045 1039 1046 // Calculate the new image ratio. … … 1045 1052 1046 1053 // If the new ratio differs by less than 0.01, use it. 1047 if ( abs( $image_ratio - $image_ratio_compare ) < 0.01 && ! array_key_exists( $candidate_url, $sources )) {1054 if ( abs( $image_ratio - $image_ratio_compare ) < 0.01 ) { 1048 1055 // Add the URL, descriptor, and value to the sources array to be returned. 1049 1056 $sources[ $image['width'] ] = array( 1050 'url' => path_join( $image_baseurl, $candidate_url ),1057 'url' => $image_baseurl . $image['file'], 1051 1058 'descriptor' => 'w', 1052 1059 'value' => $image['width'], … … 1101 1108 * @param int $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed 1102 1109 * when using the image size name as argument for `$size`. 1103 * @param string $image_ urlOptional. The URL to the image file.1110 * @param string $image_src Optional. The URL to the image file. 1104 1111 * 1105 1112 * @return string|bool A valid source size value for use in a 'sizes' attribute or false. 1106 1113 */ 1107 function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $image_ url= null ) {1114 function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $image_src = null ) { 1108 1115 $width = 0; 1109 1116 … … 1140 1147 * @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'. 1141 1148 * @param int $attachment_id Image attachment ID of the original image. 1142 * @param string $image_ urlOptional. The URL to the image file.1143 */ 1144 return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $image_ url);1149 * @param string $image_src Optional. The URL to the image file. 1150 */ 1151 return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $image_src ); 1145 1152 } 1146 1153 -
trunk/tests/phpunit/tests/media.php
r35479 r35498 786 786 foreach ( $sizes as $size ) { 787 787 $size_array = $this->_get_image_size_array_from_name( $size ); 788 $image_url = wp_get_attachment_image_url( self::$large_id, $size );788 $image_url = wp_get_attachment_image_url( $id, $size ); 789 789 $this->assertSame( $expected, wp_calculate_image_srcset( $image_url, $size_array, $image_meta ) ); 790 790 } 791 792 // Remove the attachment 793 wp_delete_attachment( $id ); 791 794 792 795 // Leave the uploads option the way you found it. … … 801 804 // Start by getting the attachment metadata. 802 805 $image_meta = wp_get_attachment_metadata( self::$large_id ); 803 $image_url = wp_get_attachment_image_url( self::$large_id );806 $image_url = wp_get_attachment_image_url( self::$large_id, 'medium' ); 804 807 $size_array = $this->_get_image_size_array_from_name( 'medium' ); 805 808 … … 807 810 $hash = 'e' . time() . rand(100, 999); 808 811 812 $filename_base = basename( $image_meta['file'], '.png' ); 813 814 // Add the hash to the image URL 815 $image_url = str_replace( $filename_base, $filename_base . '-' . $hash, $image_url ); 816 809 817 // Replace file paths for full and medium sizes with hashed versions. 810 $filename_base = basename( $image_meta['file'], '.png' );811 818 $image_meta['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['file'] ); 812 819 $image_meta['sizes']['medium']['file'] = str_replace( $filename_base, $filename_base . '-' . $hash, $image_meta['sizes']['medium']['file'] );
Note: See TracChangeset
for help on using the changeset viewer.