Make WordPress Core

Changeset 48698


Ignore:
Timestamp:
07/30/2020 10:02:54 PM (4 years ago)
Author:
whyisjake
Message:

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.

This brings the changes from [48688] to the 5.5 branch.

See #50280.
Props dd32.

Location:
branches/5.5
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/js/_enqueues/wp/theme.js

    r48650 r48698  
    803803        // Support concurrent clicks in different Theme Details overlays.
    804804        callback = function( event, data ) {
     805            var autoupdate;
    805806            if ( _this.model.get( 'id' ) === data.asset ) {
    806                 _this.model.set( { autoupdate: 'enable' === data.state } );
     807                autoupdate = _this.model.get( 'autoupdate' );
     808                autoupdate.enabled = 'enable' === data.state;
     809                _this.model.set( { autoupdate: autoupdate } );
    807810                $( document ).off( 'wp-auto-update-setting-changed', callback );
    808811            }
  • branches/5.5/src/wp-admin/includes/theme.php

    r48659 r48698  
    648648    }
    649649
    650     $updates = array();
     650    $updates    = array();
     651    $no_updates = array();
    651652    if ( current_user_can( 'update_themes' ) ) {
    652653        $updates_transient = get_site_transient( 'update_themes' );
    653654        if ( isset( $updates_transient->response ) ) {
    654655            $updates = $updates_transient->response;
     656        }
     657        if ( isset( $updates_transient->no_update ) ) {
     658            $no_updates = $updates_transient->no_update;
    655659        }
    656660    }
     
    690694        $auto_update        = in_array( $slug, $auto_updates, true );
    691695        $auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update';
     696
     697        if ( isset( $updates[ $slug ] ) ) {
     698            $auto_update_supported      = true;
     699            $auto_update_filter_payload = (object) $updates[ $slug ];
     700        } elseif ( isset( $no_updates[ $slug ] ) ) {
     701            $auto_update_supported      = true;
     702            $auto_update_filter_payload = (object) $no_updates[ $slug ];
     703        } else {
     704            $auto_update_supported = false;
     705            /*
     706             * Create the expected payload for the auto_update_theme filter, this is the same data
     707             * as contained within $updates or $no_updates but used when the Theme is not known.
     708             */
     709            $auto_update_filter_payload = (object) array(
     710                'theme'        => $slug,
     711                'new_version'  => $theme->get( 'Version' ),
     712                'url'          => '',
     713                'package'      => '',
     714                'requires'     => $theme->get( 'RequiresWP' ),
     715                'requires_php' => $theme->get( 'RequiresPHP' ),
     716            );
     717        }
     718
     719        /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
     720        $auto_update_forced = apply_filters( 'auto_update_theme', null, $auto_update_filter_payload );
    692721
    693722        $prepared_themes[ $slug ] = array(
     
    711740            'hasPackage'     => isset( $updates[ $slug ] ) && ! empty( $updates[ $slug ]['package'] ),
    712741            'update'         => get_theme_update_available( $theme ),
    713             'autoupdate'     => $auto_update,
     742            'autoupdate'     => array(
     743                'enabled'   => $auto_update || $auto_update_forced,
     744                'supported' => $auto_update_supported,
     745                'forced'    => $auto_update_forced,
     746            ),
    714747            'actions'        => array(
    715748                'activate'   => current_user_can( 'switch_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=activate&stylesheet=' . $encoded_slug ), 'switch-theme_' . $slug ) : null,
  • branches/5.5/src/wp-admin/themes.php

    r48659 r48698  
    676676    $template = '
    677677        <div class="theme-autoupdate">
    678             <# if ( data.autoupdate ) { #>
    679                 <button type="button" class="toggle-auto-update button-link" data-slug="{{ data.id }}" data-wp-action="disable">
    680                     <span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span><span class="label">' . __( 'Disable auto-updates' ) . '</span>
    681                 </button>
    682             <# } else { #>
    683                 <button type="button" class="toggle-auto-update button-link" data-slug="{{ data.id }}" data-wp-action="enable">
    684                     <span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span><span class="label">' . __( 'Enable auto-updates' ) . '</span>
    685                 </button>
     678            <# if ( data.autoupdate.supported ) { #>
     679                <# if ( data.autoupdate.forced === false ) { #>
     680                    ' . __( 'Auto-updates disabled' ) . '
     681                <# } else if ( data.autoupdate.forced ) { #>
     682                    ' . __( 'Auto-updates enabled' ) . '
     683                <# } else if ( data.autoupdate.enabled ) { #>
     684                    <button type="button" class="toggle-auto-update button-link" data-slug="{{ data.id }}" data-wp-action="disable">
     685                        <span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span><span class="label">' . __( 'Disable auto-updates' ) . '</span>
     686                    </button>
     687                <# } else { #>
     688                    <button type="button" class="toggle-auto-update button-link" data-slug="{{ data.id }}" data-wp-action="enable">
     689                        <span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span><span class="label">' . __( 'Enable auto-updates' ) . '</span>
     690                    </button>
     691                <# } #>
    686692            <# } #>
    687693            <# if ( data.hasUpdate ) { #>
    688                 <# if ( data.autoupdate ) { #>
     694                <# if ( data.autoupdate.supported && data.autoupdate.enabled ) { #>
    689695                    <span class="auto-update-time">
    690696                <# } else { #>
  • branches/5.5/src/wp-includes/update.php

    r48344 r48698  
    622622    if ( is_array( $response ) ) {
    623623        $new_update->response     = $response['themes'];
     624        $new_update->no_update    = $response['no_update'];
    624625        $new_update->translations = $response['translations'];
    625626    }
Note: See TracChangeset for help on using the changeset viewer.