Make WordPress Core

Ticket #51129: 51129.diff

File 51129.diff, 3.4 KB (added by afragen, 3 years ago)
  • wp-admin/includes/class-wp-ms-themes-list-table.php

    diff --git a/wp-admin/includes/class-wp-ms-themes-list-table.php b/wp-admin/includes/class-wp-ms-themes-list-table.php
    index f67c7bd693..3531302014 100644
    a b class WP_MS_Themes_List_Table extends WP_List_Table { 
    136136
    137137                $current      = get_site_transient( 'update_themes' );
    138138                $maybe_update = current_user_can( 'update_themes' ) && ! $this->is_site_themes && $current;
     139                $theme_data   = array_merge( $current->response, $current->no_update );
    139140
    140141                foreach ( (array) $themes['all'] as $key => $theme ) {
    141142                        if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    151152                        $filter                    = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
    152153                        $themes[ $filter ][ $key ] = $themes['all'][ $key ];
    153154
     155                        // Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
     156                        if ( isset( $current->response[ $key ] ) ) {
     157                                $current->response[$key] = array_merge( (array) $current->response[ $key ], array( 'update-supported' => true ) );
     158                        } elseif ( isset( $current->no_update[ $key ] ) ) {
     159                                $current->no_update[$key] = array_merge( (array) $current->no_update[ $key ], array( 'update-supported' => true ) );
     160                        }
     161
     162                        /*
     163                         * Create the expected payload for the auto_update_theme filter, this is the same data
     164                         * as contained within $updates or $no_updates but used when the Theme is not known.
     165                         */
     166                        $filter_payload = array(
     167                                'theme'            => $key,
     168                                'new_version'      => $theme->get( 'Version' ),
     169                                'url'              => '',
     170                                'package'          => '',
     171                                'requires'         => $theme->get( 'RequiresWP' ),
     172                                'requires_php'     => $theme->get( 'RequiresPHP' ),
     173                                'update-supported' => false,
     174                        );
     175
     176                        $filter_payload = array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
     177
     178                        $type = 'theme';
     179                        /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
     180                        $auto_update_forced = apply_filters( "auto_update_{$type}", null, $filter_payload );
     181
     182                        if ( ! is_null( $auto_update_forced ) ) {
     183                                $themes['auto-update-forced'][$key] = $auto_update_forced;
     184                        }
     185
    154186                        if ( $this->show_autoupdates ) {
    155187                                if ( in_array( $key, $auto_updates, true ) ) {
    156188                                        $themes['auto-update-enabled'][ $key ] = $themes['all'][ $key ];
    157                                 } else {
     189                                } elseif( array_key_exists( $key, $current->response ) || array_key_exists( $key, $current->no_update ) ) {
    158190                                        $themes['auto-update-disabled'][ $key ] = $themes['all'][ $key ];
    159191                                }
    160192                        }
    161193                }
    162194
     195                set_site_transient( 'update_themes', $current );
     196
    163197                if ( $s ) {
    164198                        $status           = 'search';
    165199                        $themes['search'] = array_filter( array_merge( $themes['all'], $themes['broken'] ), array( $this, '_search_callback' ) );
    class WP_MS_Themes_List_Table extends WP_List_Table { 
    732766                        $text       = __( 'Disable auto-updates' );
    733767                        $action     = 'disable';
    734768                        $time_class = '';
    735                 } else {
     769                } elseif ( array_key_exists( $stylesheet, $available_updates->response ) || array_key_exists( $stylesheet, $available_updates->no_update ) ) {
    736770                        $text       = __( 'Enable auto-updates' );
    737771                        $action     = 'enable';
    738772                        $time_class = ' hidden';
     773                } else {
     774                        $text       = '';
     775                        $action     = 'unable';
     776                        $time_class = ' hidden';
    739777                }
    740778
    741779                $query_args = array(