From f19df46584bf79d468142ba868a89b2e3e8dcd25 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Thu, 14 Sep 2023 11:25:19 +0000 Subject: [PATCH] Bundled Theme: Implement the_header_image_tag function for enhanced compatibility for older core themes. The `the_header_image_tag` function was introduced in WordPress 4.4 as part of [35594]. It is used in all themes created post WordPress 4.4 that supported header images. The function `get_header_image_tag` continues to get updated with new image features, like lazy loading, async decoding and fetch priority. To ensure our core themes maintain compatibility and benefit from these enhancements, a backward compatibility shim has been applied, integrating the `the_header_image_tag` function into the following core themes: - Twenty Ten - Twenty Eleven - Twenty Twelve - Twenty Fourteen - Twenty Sixteen This change ensures future compatibility and modern image features are applied for header images to these older themes. Props spacedmonkey, flixos90, mukesh27. Fixes #58675. Built from https://develop.svn.wordpress.org/trunk@56583 git-svn-id: http://core.svn.wordpress.org/trunk@56095 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-content/themes/twentyeleven/functions.php | 33 +++++++++++++++++++ wp-content/themes/twentyeleven/header.php | 12 +------ wp-content/themes/twentyfourteen/header.php | 2 +- .../twentyfourteen/inc/custom-header.php | 26 +++++++++++++++ wp-content/themes/twentysixteen/header.php | 12 ++++++- wp-content/themes/twentyten/functions.php | 33 +++++++++++++++++++ wp-content/themes/twentyten/header.php | 12 +------ wp-content/themes/twentytwelve/header.php | 2 +- .../themes/twentytwelve/inc/custom-header.php | 24 ++++++++++++++ wp-includes/version.php | 2 +- 10 files changed, 132 insertions(+), 26 deletions(-) diff --git a/wp-content/themes/twentyeleven/functions.php b/wp-content/themes/twentyeleven/functions.php index 4c478fd8e3..3ca5da5882 100644 --- a/wp-content/themes/twentyeleven/functions.php +++ b/wp-content/themes/twentyeleven/functions.php @@ -440,6 +440,39 @@ if ( ! function_exists( 'twentyeleven_admin_header_image' ) ) : } endif; // twentyeleven_admin_header_image() + +if ( ! function_exists( 'twentyeleven_header_image' ) ) : + /** + * Custom header image markup displayed. + * + * @since Twenty Eleven 4.5 + */ + function twentyeleven_header_image() { + $attrs = array( + 'alt' => get_bloginfo( 'name', 'display' ), + ); + + // Compatibility with versions of WordPress prior to 3.4. + if ( function_exists( 'get_custom_header' ) ) { + $custom_header = get_custom_header(); + $attrs['width'] = $custom_header->width; + $attrs['height'] = $custom_header->height; + } else { + $attrs['width'] = HEADER_IMAGE_WIDTH; + $attrs['height'] = HEADER_IMAGE_HEIGHT; + } + + if ( function_exists( 'the_header_image_tag' ) ) { + the_header_image_tag( $attrs ); + return; + } + + ?> + <?php echo esc_attr( $attrs['alt'] ); ?> + ID, 'post-thumbnail' ); } else { - // Compatibility with versions of WordPress prior to 3.4. - if ( function_exists( 'get_custom_header' ) ) { - $header_image_width = get_custom_header()->width; - $header_image_height = get_custom_header()->height; - } else { - $header_image_width = HEADER_IMAGE_WIDTH; - $header_image_height = HEADER_IMAGE_HEIGHT; - } - ?> - <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> - diff --git a/wp-content/themes/twentyfourteen/header.php b/wp-content/themes/twentyfourteen/header.php index ad3e128b0c..10b31fbf36 100644 --- a/wp-content/themes/twentyfourteen/header.php +++ b/wp-content/themes/twentyfourteen/header.php @@ -36,7 +36,7 @@ diff --git a/wp-content/themes/twentyfourteen/inc/custom-header.php b/wp-content/themes/twentyfourteen/inc/custom-header.php index d6692dbb41..9b8f35d7ce 100644 --- a/wp-content/themes/twentyfourteen/inc/custom-header.php +++ b/wp-content/themes/twentyfourteen/inc/custom-header.php @@ -151,3 +151,29 @@ if ( ! function_exists( 'twentyfourteen_admin_header_image' ) ) : get_bloginfo( 'name', 'display' ), + 'height' => $custom_header->height, + 'width' => $custom_header->width, + ); + if ( function_exists( 'the_header_image_tag' ) ) { + the_header_image_tag( $attrs ); + return; + } + ?> + <?php echo esc_attr( $attrs['alt'] ); ?> +
- <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> + get_bloginfo( 'name', 'display' ), + 'sizes' => $custom_header_sizes, + 'height' => $custom_header->height, + 'width' => $custom_header->width, + ); + + the_header_image_tag( $attrs ); + ?>
diff --git a/wp-content/themes/twentyten/functions.php b/wp-content/themes/twentyten/functions.php index 36e20c442c..eb4fe64ef3 100644 --- a/wp-content/themes/twentyten/functions.php +++ b/wp-content/themes/twentyten/functions.php @@ -290,6 +290,39 @@ if ( ! function_exists( 'twentyten_admin_header_style' ) ) : } endif; + +if ( ! function_exists( 'twentyten_header_image' ) ) : + /** + * Custom header image markup displayed. + * + * @since Twenty Ten 4.0 + */ + function twentyten_header_image() { + $attrs = array( + 'alt' => get_bloginfo( 'name', 'display' ), + ); + + // Compatibility with versions of WordPress prior to 3.4. + if ( function_exists( 'get_custom_header' ) ) { + $custom_header = get_custom_header(); + $attrs['width'] = $custom_header->width; + $attrs['height'] = $custom_header->height; + } else { + $attrs['width'] = HEADER_IMAGE_WIDTH; + $attrs['height'] = HEADER_IMAGE_HEIGHT; + } + + if ( function_exists( 'the_header_image_tag' ) ) { + the_header_image_tag( $attrs ); + return; + } + + ?> + <?php echo esc_attr( $attrs['alt'] ); ?> + ID, 'post-thumbnail' ); } else { - // Compatibility with versions of WordPress prior to 3.4. - if ( function_exists( 'get_custom_header' ) ) { - $header_image_width = get_custom_header()->width; - $header_image_height = get_custom_header()->height; - } else { - $header_image_width = HEADER_IMAGE_WIDTH; - $header_image_height = HEADER_IMAGE_HEIGHT; - } - ?> - - diff --git a/wp-content/themes/twentytwelve/header.php b/wp-content/themes/twentytwelve/header.php index 0d4cf9441a..13fbebead9 100644 --- a/wp-content/themes/twentytwelve/header.php +++ b/wp-content/themes/twentytwelve/header.php @@ -54,7 +54,7 @@ - <?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?> + diff --git a/wp-content/themes/twentytwelve/inc/custom-header.php b/wp-content/themes/twentytwelve/inc/custom-header.php index 84b3556c24..a20df42367 100644 --- a/wp-content/themes/twentytwelve/inc/custom-header.php +++ b/wp-content/themes/twentytwelve/inc/custom-header.php @@ -166,3 +166,27 @@ function twentytwelve_admin_header_image() { get_bloginfo( 'name', 'display' ), + 'class' => 'header-image', + 'height' => $custom_header->height, + 'width' => $custom_header->width, + ); + + if ( function_exists( 'the_header_image_tag' ) ) { + the_header_image_tag( $attrs ); + return; + } + ?> + <?php echo esc_attr( $attrs['alt'] ); ?> +