Make WordPress Core


Ignore:
Timestamp:
07/29/2020 07:59:30 PM (6 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.

See #50280.
Props dd32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/theme.php

    r48659 r48688  
    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,
Note: See TracChangeset for help on using the changeset viewer.