Upgrade/Install: Only show auto-update for themes that support the feature.

Similar to the changes for plugins in [48669], let's only show the UI for themes when updates are supported for that theme.

See #50280.
Props dd32.

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


git-svn-id: http://core.svn.wordpress.org/trunk@48450 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2020-07-29 20:01:08 +00:00
parent 1d552ea6b1
commit e6bfdde581
6 changed files with 57 additions and 14 deletions

View File

@ -648,11 +648,15 @@ function wp_prepare_themes_for_js( $themes = null ) {
}
$updates = array();
$no_updates = array();
if ( current_user_can( 'update_themes' ) ) {
$updates_transient = get_site_transient( 'update_themes' );
if ( isset( $updates_transient->response ) ) {
$updates = $updates_transient->response;
}
if ( isset( $updates_transient->no_update ) ) {
$no_updates = $updates_transient->no_update;
}
}
WP_Theme::sort_by_name( $themes );
@ -690,6 +694,31 @@ function wp_prepare_themes_for_js( $themes = null ) {
$auto_update = in_array( $slug, $auto_updates, true );
$auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';
if ( isset( $updates[ $slug ] ) ) {
$auto_update_supported = true;
$auto_update_filter_payload = (object) $updates[ $slug ];
} elseif ( isset( $no_updates[ $slug ] ) ) {
$auto_update_supported = true;
$auto_update_filter_payload = (object) $no_updates[ $slug ];
} else {
$auto_update_supported = false;
/*
* Create the expected payload for the auto_update_theme filter, this is the same data
* as contained within $updates or $no_updates but used when the Theme is not known.
*/
$auto_update_filter_payload = (object) array(
'theme' => $slug,
'new_version' => $theme->get( 'Version' ),
'url' => '',
'package' => '',
'requires' => $theme->get( 'RequiresWP' ),
'requires_php' => $theme->get( 'RequiresPHP' ),
);
}
/** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
$auto_update_forced = apply_filters( 'auto_update_theme', null, $auto_update_filter_payload );
$prepared_themes[ $slug ] = array(
'id' => $slug,
'name' => $theme->display( 'Name' ),
@ -710,7 +739,11 @@ function wp_prepare_themes_for_js( $themes = null ) {
'hasUpdate' => isset( $updates[ $slug ] ),
'hasPackage' => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
'update' => get_theme_update_available( $theme ),
'autoupdate' => $auto_update,
'autoupdate' => array(
'enabled' => $auto_update || $auto_update_forced,
'supported' => $auto_update_supported,
'forced' => $auto_update_forced,
),
'actions' => array(
'activate' => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
'customize' => $customize_action,

View File

@ -802,8 +802,11 @@ themes.view.Details = wp.Backbone.View.extend({
// Support concurrent clicks in different Theme Details overlays.
callback = function( event, data ) {
var autoupdate;
if ( _this.model.get( 'id' ) === data.asset ) {
_this.model.set( { autoupdate: 'enable' === data.state } );
autoupdate = _this.model.get( 'autoupdate' );
autoupdate.enabled = 'enable' === data.state;
_this.model.set( { autoupdate: autoupdate } );
$( document ).off( 'wp-auto-update-setting-changed', callback );
}
};

File diff suppressed because one or more lines are too long

View File

@ -675,7 +675,12 @@ if ( ! is_multisite() && $broken_themes ) {
function wp_theme_auto_update_setting_template() {
$template = '
<div class="theme-autoupdate">
<# if ( data.autoupdate ) { #>
<# if ( data.autoupdate.supported ) { #>
<# if ( data.autoupdate.forced === false ) { #>
' . __( 'Auto-updates disabled' ) . '
<# } else if ( data.autoupdate.forced ) { #>
' . __( 'Auto-updates enabled' ) . '
<# } else if ( data.autoupdate.enabled ) { #>
<button type="button" class="toggle-auto-update button-link" data-slug="{{ data.id }}" data-wp-action="disable">
<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span><span class="label">' . __( 'Disable auto-updates' ) . '</span>
</button>
@ -684,8 +689,9 @@ function wp_theme_auto_update_setting_template() {
<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span><span class="label">' . __( 'Enable auto-updates' ) . '</span>
</button>
<# } #>
<# } #>
<# if ( data.hasUpdate ) { #>
<# if ( data.autoupdate ) { #>
<# if ( data.autoupdate.supported && data.autoupdate.enabled ) { #>
<span class="auto-update-time">
<# } else { #>
<span class="auto-update-time hidden">

View File

@ -621,6 +621,7 @@ function wp_update_themes( $extra_stats = array() ) {
if ( is_array( $response ) ) {
$new_update->response = $response['themes'];
$new_update->no_update = $response['no_update'];
$new_update->translations = $response['translations'];
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.6-alpha-48686';
$wp_version = '5.6-alpha-48688';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.