Themes: Add version to theme screenshot URL for better browser cache handling.

This change appends the theme version number to the URL of screenshots that appear in various place of the WordPress Admin. As a result, browsers will be able to refresh the screenshot as needed when the theme is updated.

Props codente, desrosj, audrasjb, SergeyBiryukov.
Fixes #53370.


Built from https://develop.svn.wordpress.org/trunk@52947


git-svn-id: http://core.svn.wordpress.org/trunk@52536 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
audrasjb 2022-03-17 22:21:07 +00:00
parent d6589948ca
commit a32545f854
7 changed files with 11 additions and 11 deletions

View File

@ -359,7 +359,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
?> ?>
<a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>"> <a class="screenshot install-theme-preview" href="<?php echo esc_url( $preview_url ); ?>" title="<?php echo esc_attr( $preview_title ); ?>">
<img src="<?php echo esc_url( $theme->screenshot_url ); ?>" width="150" alt="" /> <img src="<?php echo esc_url( $theme->screenshot_url . '?ver=' . $theme->version ); ?>" width="150" alt="" />
</a> </a>
<h3><?php echo $name; ?></h3> <h3><?php echo $name; ?></h3>
@ -502,7 +502,7 @@ class WP_Theme_Install_List_Table extends WP_Themes_List_Table {
?> ?>
</span> </span>
<?php if ( isset( $theme->screenshot_url ) ) : ?> <?php if ( isset( $theme->screenshot_url ) ) : ?>
<img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url ); ?>" alt="" /> <img class="theme-screenshot" src="<?php echo esc_url( $theme->screenshot_url . '?ver=' . $theme->version ); ?>" alt="" />
<?php endif; ?> <?php endif; ?>
<div class="theme-details"> <div class="theme-details">
<?php <?php

View File

@ -823,7 +823,7 @@ function customize_themes_print_templates() {
<div class="theme-about wp-clearfix"> <div class="theme-about wp-clearfix">
<div class="theme-screenshots"> <div class="theme-screenshots">
<# if ( data.screenshot && data.screenshot[0] ) { #> <# if ( data.screenshot && data.screenshot[0] ) { #>
<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div> <div class="screenshot"><img src="{{ data.screenshot[0] }}?ver={{ data.version }}" alt="" /></div>
<# } else { #> <# } else { #>
<div class="screenshot blank"></div> <div class="screenshot blank"></div>
<# } #> <# } #>

View File

@ -282,7 +282,7 @@ if ( $tab ) {
<script id="tmpl-theme" type="text/template"> <script id="tmpl-theme" type="text/template">
<# if ( data.screenshot_url ) { #> <# if ( data.screenshot_url ) { #>
<div class="theme-screenshot"> <div class="theme-screenshot">
<img src="{{ data.screenshot_url }}" alt="" /> <img src="{{ data.screenshot_url }}?ver={{ data.version }}" alt="" />
</div> </div>
<# } else { #> <# } else { #>
<div class="theme-screenshot blank"></div> <div class="theme-screenshot blank"></div>
@ -456,7 +456,7 @@ if ( $tab ) {
?> ?>
</span> </span>
<img class="theme-screenshot" src="{{ data.screenshot_url }}" alt="" /> <img class="theme-screenshot" src="{{ data.screenshot_url }}?ver={{ data.version }}" alt="" />
<div class="theme-details"> <div class="theme-details">
<# if ( data.rating ) { #> <# if ( data.rating ) { #>

View File

@ -388,7 +388,7 @@ foreach ( $themes as $theme ) :
<div class="theme<?php echo $active_class; ?>"> <div class="theme<?php echo $active_class; ?>">
<?php if ( ! empty( $theme['screenshot'][0] ) ) { ?> <?php if ( ! empty( $theme['screenshot'][0] ) ) { ?>
<div class="theme-screenshot"> <div class="theme-screenshot">
<img src="<?php echo esc_attr( $theme['screenshot'][0] ); ?>" alt="" /> <img src="<?php echo esc_attr( $theme['screenshot'][0] . '?ver=' . $theme['version'] ); ?>" alt="" />
</div> </div>
<?php } else { ?> <?php } else { ?>
<div class="theme-screenshot blank"></div> <div class="theme-screenshot blank"></div>
@ -739,7 +739,7 @@ function wp_theme_auto_update_setting_template() {
<script id="tmpl-theme" type="text/template"> <script id="tmpl-theme" type="text/template">
<# if ( data.screenshot[0] ) { #> <# if ( data.screenshot[0] ) { #>
<div class="theme-screenshot"> <div class="theme-screenshot">
<img src="{{ data.screenshot[0] }}" alt="" /> <img src="{{ data.screenshot[0] }}?ver={{ data.version }}" alt="" />
</div> </div>
<# } else { #> <# } else { #>
<div class="theme-screenshot blank"></div> <div class="theme-screenshot blank"></div>
@ -947,7 +947,7 @@ function wp_theme_auto_update_setting_template() {
<div class="theme-about wp-clearfix"> <div class="theme-about wp-clearfix">
<div class="theme-screenshots"> <div class="theme-screenshots">
<# if ( data.screenshot[0] ) { #> <# if ( data.screenshot[0] ) { #>
<div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div> <div class="screenshot"><img src="{{ data.screenshot[0] }}?ver={{ data.version }}" alt="" /></div>
<# } else { #> <# } else { #>
<div class="screenshot blank"></div> <div class="screenshot blank"></div>
<# } #> <# } #>

View File

@ -755,7 +755,7 @@ function list_theme_updates() {
<?php endif; ?> <?php endif; ?>
</td> </td>
<td class="plugin-title"><p> <td class="plugin-title"><p>
<img src="<?php echo esc_url( $theme->get_screenshot() ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" /> <img src="<?php echo esc_url( $theme->get_screenshot() . '?ver=' . $theme->version ); ?>" width="85" height="64" class="updates-table-screenshot" alt="" />
<strong><?php echo $theme->display( 'Name' ); ?></strong> <strong><?php echo $theme->display( 'Name' ); ?></strong>
<?php <?php
printf( printf(

View File

@ -74,7 +74,7 @@ class WP_Customize_Theme_Control extends WP_Customize_Control {
<# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #> <# if ( data.theme.screenshot && data.theme.screenshot[0] ) { #>
<div class="theme-screenshot"> <div class="theme-screenshot">
<img data-src="{{ data.theme.screenshot[0] }}" alt="" /> <img data-src="{{ data.theme.screenshot[0] }}?ver={{ data.theme.version }}" alt="" />
</div> </div>
<# } else { #> <# } else { #>
<div class="theme-screenshot blank"></div> <div class="theme-screenshot blank"></div>

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.0-alpha-52946'; $wp_version = '6.0-alpha-52947';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.