diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index c702e4f169..9a81a893b4 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -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 ); } }; diff --git a/src/wp-admin/includes/theme.php b/src/wp-admin/includes/theme.php index 5f063d9102..67d557096c 100644 --- a/src/wp-admin/includes/theme.php +++ b/src/wp-admin/includes/theme.php @@ -647,12 +647,16 @@ function wp_prepare_themes_for_js( $themes = null ) { } } - $updates = array(); + $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, diff --git a/src/wp-admin/themes.php b/src/wp-admin/themes.php index c2704934fb..157a42e629 100644 --- a/src/wp-admin/themes.php +++ b/src/wp-admin/themes.php @@ -675,17 +675,23 @@ if ( ! is_multisite() && $broken_themes ) { function wp_theme_auto_update_setting_template() { $template = '
- <# if ( data.autoupdate ) { #> - - <# } else { #> - + <# 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 ) { #> + + <# } else { #> + + <# } #> <# } #> <# if ( data.hasUpdate ) { #> - <# if ( data.autoupdate ) { #> + <# if ( data.autoupdate.supported && data.autoupdate.enabled ) { #> <# } else { #>