|
@@ 1015-1031 (lines=17) @@
|
| 1012 |
|
* Default null. |
| 1013 |
|
* @return string|bool A 'srcset' value string or false. |
| 1014 |
|
*/ |
| 1015 |
|
function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) { |
| 1016 |
|
if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { |
| 1017 |
|
return false; |
| 1018 |
|
} |
| 1019 |
|
|
| 1020 |
|
if ( ! is_array( $image_meta ) ) { |
| 1021 |
|
$image_meta = wp_get_attachment_metadata( $attachment_id ); |
| 1022 |
|
} |
| 1023 |
|
|
| 1024 |
|
$image_src = $image[0]; |
| 1025 |
|
$size_array = array( |
| 1026 |
|
absint( $image[1] ), |
| 1027 |
|
absint( $image[2] ) |
| 1028 |
|
); |
| 1029 |
|
|
| 1030 |
|
return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id ); |
| 1031 |
|
} |
| 1032 |
|
|
| 1033 |
|
/** |
| 1034 |
|
* A helper function to calculate the image sources to include in a 'srcset' attribute. |
|
@@ 1233-1249 (lines=17) @@
|
| 1230 |
|
* Default null. |
| 1231 |
|
* @return string|bool A valid source size value for use in a 'sizes' attribute or false. |
| 1232 |
|
*/ |
| 1233 |
|
function wp_get_attachment_image_sizes( $attachment_id, $size = 'medium', $image_meta = null ) { |
| 1234 |
|
if ( ! $image = wp_get_attachment_image_src( $attachment_id, $size ) ) { |
| 1235 |
|
return false; |
| 1236 |
|
} |
| 1237 |
|
|
| 1238 |
|
if ( ! is_array( $image_meta ) ) { |
| 1239 |
|
$image_meta = wp_get_attachment_metadata( $attachment_id ); |
| 1240 |
|
} |
| 1241 |
|
|
| 1242 |
|
$image_src = $image[0]; |
| 1243 |
|
$size_array = array( |
| 1244 |
|
absint( $image[1] ), |
| 1245 |
|
absint( $image[2] ) |
| 1246 |
|
); |
| 1247 |
|
|
| 1248 |
|
return wp_calculate_image_sizes( $size_array, $image_src, $image_meta, $attachment_id ); |
| 1249 |
|
} |
| 1250 |
|
|
| 1251 |
|
/** |
| 1252 |
|
* Creates a 'sizes' attribute value for an image. |