From d51aa96069dbe4baf1dd59319ad59f6b465da4dd Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 10 Nov 2015 01:58:38 +0000 Subject: [PATCH] Responsive images: fix args order and streamline the srcset and sizes generation and better inline docs in `get_header_image_tag()`. See #21389. git-svn-id: https://develop.svn.wordpress.org/trunk@35595 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/theme.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php index e9d7500e25..395d42810a 100644 --- a/src/wp-includes/theme.php +++ b/src/wp-includes/theme.php @@ -994,12 +994,13 @@ function get_header_image() { } /** - * Create image markup for a custom header image. + * Create image tag markup for a custom header image. * * @since 4.4.0 * - * @param array $attr Optional. Attributes for the image markup. Default empty. - * @return string HTML element or empty string on failure. + * @param array $attr Optional. Additional attributes for the image tag. Can be used + * to override the default attributes. Default empty. + * @return string HTML image element markup or empty string on failure. */ function get_header_image_tag( $attr = array() ) { $header = get_custom_header(); @@ -1027,15 +1028,12 @@ function get_header_image_tag( $attr = array() ) { $size_array = array( $width, $height ); if ( is_array( $image_meta ) ) { - $srcset = wp_calculate_image_srcset( $header->url, $size_array, $image_meta, $header->attachment_id ); - $sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $header->attachment_id, $header->url ); + $srcset = wp_calculate_image_srcset( $size_array, $header->url, $image_meta, $header->attachment_id ); + $sizes = ! empty( $attr['sizes'] ) ? $attr['sizes'] : wp_calculate_image_sizes( $size_array, $header->url, $image_meta, $header->attachment_id ); - if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) { + if ( $srcset && $sizes ) { $attr['srcset'] = $srcset; - - if ( empty( $attr['sizes'] ) ) { - $attr['sizes'] = $sizes; - } + $attr['sizes'] = $sizes; } } } @@ -1054,9 +1052,9 @@ function get_header_image_tag( $attr = array() ) { * * @since 4.4.0 * - * @param string $html The HTML markup being filtered. - * @param object $header The custom header object returned by 'get_custom_header()' - * @param array $attr An array of attributes for the image markup. + * @param string $html The HTML image tag markup being filtered. + * @param object $header The custom header object returned by 'get_custom_header()'. + * @param array $attr Array of the attributes for the image tag. */ return apply_filters( 'get_header_image_tag', $html, $header, $attr ); }