diff --git src/wp-includes/media.php src/wp-includes/media.php
index 30df322..29933a6 100644
|
|
function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon |
879 | 879 | * |
880 | 880 | * @type array $values { |
881 | 881 | * @type string $url An image URL. |
882 | | * @type string $descriptor A width or density descriptor used in a srcset. |
| 882 | * @type string $descriptor A width or density descriptor used in a 'srcset'. |
883 | 883 | * @type int $value The descriptor value representing a width or |
884 | 884 | * or pixel density. |
885 | 885 | * } |
886 | 886 | * } |
887 | | * |
888 | 887 | */ |
889 | 888 | function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' ) { |
890 | 889 | // Get the intermediate size. |
… |
… |
function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' |
905 | 904 | return false; |
906 | 905 | } |
907 | 906 | |
908 | | // Use the URL from the intermediate size or build the url from the metadata. |
| 907 | // Use the URL from the intermediate size or build the URL from the metadata. |
909 | 908 | if ( ! empty( $image['url'] ) ) { |
910 | 909 | $img_url = $image['url']; |
911 | 910 | } else { |
… |
… |
function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' |
934 | 933 | $img_edited = preg_match( '/-e[0-9]{13}/', $img_url, $img_edit_hash ); |
935 | 934 | |
936 | 935 | /** |
937 | | * Filter the maximum width included in a srcset attribute. |
| 936 | * Filter the maximum width included in a 'srcset' attribute. |
938 | 937 | * |
939 | 938 | * @since 4.4.0 |
940 | 939 | * |
941 | | * @param array|string $size Size of image, either array or string. |
| 940 | * @param int $max_width The maximum width to include in the 'srcset'. Default '1600'. |
| 941 | * @param array|string $size Image size. Image size or an array of width and height |
| 942 | * values in pixels (in that order). |
942 | 943 | */ |
943 | 944 | $max_srcset_width = apply_filters( 'max_srcset_image_width', 1600, $size ); |
944 | 945 | |
945 | 946 | /* |
946 | | * Set up arrays to hold url candidates and matched image sources so |
947 | | * we can avoid duplicates without looping through the full sources array |
| 947 | * Set up arrays to hold URL candidates and matched image sources so |
| 948 | * we can avoid duplicates without looping through the full sources array. |
948 | 949 | */ |
949 | 950 | $candidates = $sources = array(); |
950 | 951 | |
… |
… |
function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' |
959 | 960 | continue; |
960 | 961 | } |
961 | 962 | |
962 | | // Filter out images that are wider than $max_srcset_width. |
| 963 | // Filter out images that are wider than `$max_srcset_width`. |
963 | 964 | if ( $max_srcset_width && $img['width'] > $max_srcset_width ) { |
964 | 965 | continue; |
965 | 966 | } |
… |
… |
function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' |
978 | 979 | // Add the URL to our list of candidates. |
979 | 980 | $candidates[] = $candidate_url; |
980 | 981 | |
981 | | // Add the url, descriptor, and value to the sources array to be returned. |
| 982 | // Add the URL, descriptor, and value to the sources array to be returned. |
982 | 983 | $sources[] = array( |
983 | 984 | 'url' => $candidate_url, |
984 | 985 | 'descriptor' => 'w', |
… |
… |
function wp_get_attachment_image_srcset_array( $attachment_id, $size = 'medium' |
994 | 995 | * |
995 | 996 | * @param array $sources An array of image urls and widths. |
996 | 997 | * @param int $attachment_id Attachment ID for image. |
997 | | * @param array|string $size Image size. Accepts any valid image size, or an array of width and height |
998 | | * values in pixels (in that order). Default 'medium'. |
| 998 | * @param array|string $size Image size. Image size or an array of width and height |
| 999 | * values in pixels (in that order). |
999 | 1000 | */ |
1000 | 1001 | return apply_filters( 'wp_get_attachment_image_srcset_array', $sources, $attachment_id, $size ); |
1001 | 1002 | } |
… |
… |
function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium' ) { |
1028 | 1029 | * |
1029 | 1030 | * @since 4.4.0 |
1030 | 1031 | * |
1031 | | * @param string $srcset A source set formated for a `srcset` attribute. |
| 1032 | * @param string $srcset A source set formatted for a `srcset` attribute. |
1032 | 1033 | * @param int $attachment_id Attachment ID for image. |
1033 | | * @param array|string $size Image size. Accepts any valid image size, or an array of width and height |
1034 | | * values in pixels (in that order). Default 'medium'. |
| 1034 | * @param array|string $size Image size. Image size or an array of width and height |
| 1035 | * values in pixels (in that order). |
1035 | 1036 | */ |
1036 | 1037 | return apply_filters( 'wp_get_attachment_image_srcset', rtrim( $srcset, ', ' ), $attachment_id, $size ); |
1037 | 1038 | } |
… |
… |
function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $width |
1060 | 1061 | $img_width = $image ? $image['width'] : false; |
1061 | 1062 | } |
1062 | 1063 | |
1063 | | // Bail early if $img_width isn't set. |
| 1064 | // Bail early if `$img_width` isn't set. |
1064 | 1065 | if ( ! $img_width ) { |
1065 | 1066 | return false; |
1066 | 1067 | } |
… |
… |
function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $width |
1075 | 1076 | * |
1076 | 1077 | * @param string $sizes A source size value for use in a 'sizes' attribute. |
1077 | 1078 | * @param int $attachment_id Post ID of the original image. |
1078 | | * @param array|string $size Image size. Accepts any valid image size, or an array of width and height |
1079 | | * values in pixels (in that order). Default 'medium'. |
| 1079 | * @param array|string $size Image size. Image size or an array of width and height |
| 1080 | * values in pixels (in that order). |
1080 | 1081 | * @param int $width Display width of the image. |
1081 | 1082 | */ |
1082 | 1083 | return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $attachment_id, $size, $width ); |
… |
… |
function wp_make_content_images_responsive( $content ) { |
1108 | 1109 | |
1109 | 1110 | if ( 0 < count( $attachment_ids ) ) { |
1110 | 1111 | /* |
1111 | | * Warm object caches for use with wp_get_attachment_metadata. |
| 1112 | * Warm object caches for use with `wp_get_attachment_metadata`. |
1112 | 1113 | * |
1113 | 1114 | * To avoid making a database call for each image, a single query |
1114 | 1115 | * warms the object cache with the meta information for all images. |
… |
… |
function wp_img_add_srcset_and_sizes( $image ) { |
1140 | 1141 | return $image; |
1141 | 1142 | } |
1142 | 1143 | |
1143 | | // Parse id, size, width, and height from the `img` element. |
| 1144 | // Parse ID, size, width, and height from the `img` element. |
1144 | 1145 | $id = preg_match( '/wp-image-([0-9]+)/i', $image, $match_id ) ? (int) $match_id[1] : false; |
1145 | 1146 | $size = preg_match( '/size-([^\s|"]+)/i', $image, $match_size ) ? $match_size[1] : false; |
1146 | 1147 | $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : false; |
… |
… |
function wp_img_add_srcset_and_sizes( $image ) { |
1160 | 1161 | if ( $id && ! $size ) { |
1161 | 1162 | $meta = wp_get_attachment_metadata( $id ); |
1162 | 1163 | |
1163 | | // Parse the image src value from the img element. |
| 1164 | // Parse the image 'src' value from the 'img' element. |
1164 | 1165 | $src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : false; |
1165 | 1166 | |
1166 | | // Return early if the metadata does not exist or the src value is empty. |
| 1167 | // Return early if the metadata does not exist or the 'src' value is empty. |
1167 | 1168 | if ( ! $meta || ! $src ) { |
1168 | 1169 | return $image; |
1169 | 1170 | } |
… |
… |
function wp_img_add_srcset_and_sizes( $image ) { |
1196 | 1197 | // Format the srcset and sizes string and escape attributes. |
1197 | 1198 | $srcset_and_sizes = sprintf( ' srcset="%s" sizes="%s"', esc_attr( $srcset ), esc_attr( $sizes) ); |
1198 | 1199 | |
1199 | | // Add srcset and sizes attributes to the image markup. |
| 1200 | // Add 'srcset' and 'sizes' attributes to the image markup. |
1200 | 1201 | $image = preg_replace( '/<img ([^>]+)[\s?][\/?]>/', '<img $1' . $srcset_and_sizes . ' />', $image ); |
1201 | 1202 | } |
1202 | 1203 | } |