Make WordPress Core


Ignore:
Timestamp:
08/27/2020 10:23:53 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Only display the auto-update links on the Network Admin > Themes screen for themes that support the feature.

Follow-up to [48669], [48688].

Props afragen, pbiron, audrasjb, desrosj, SergeyBiryukov.
Merges [48899] to the 5.5 branch.
Fixes #51129.

Location:
branches/5.5
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.5

  • branches/5.5/src/wp-admin/includes/class-wp-ms-themes-list-table.php

    r48660 r48900  
    152152                        $themes[ $filter ][ $key ] = $themes['all'][ $key ];
    153153
     154                        $theme_data = array(
     155                                'update_supported' => isset( $theme->update_supported ) ? $theme->update_supported : true,
     156                        );
     157
     158                        // Extra info if known. array_merge() ensures $theme_data has precedence if keys collide.
     159                        if ( isset( $current->response[ $key ] ) ) {
     160                                $theme_data = array_merge( (array) $current->response[ $key ], $theme_data );
     161                        } elseif ( isset( $current->no_update[ $key ] ) ) {
     162                                $theme_data = array_merge( (array) $current->no_update[ $key ], $theme_data );
     163                        } else {
     164                                $theme_data['update_supported'] = false;
     165                        }
     166
     167                        $theme->update_supported = $theme_data['update_supported'];
     168
     169                        /*
     170                         * Create the expected payload for the auto_update_theme filter, this is the same data
     171                         * as contained within $updates or $no_updates but used when the Theme is not known.
     172                         */
     173                        $filter_payload = array(
     174                                'theme'        => $key,
     175                                'new_version'  => '',
     176                                'url'          => '',
     177                                'package'      => '',
     178                                'requires'     => '',
     179                                'requires_php' => '',
     180                        );
     181
     182                        $filter_payload = array_merge( $filter_payload, array_intersect_key( $theme_data, $filter_payload ) );
     183
     184                        $type = 'theme';
     185                        /** This filter is documented in wp-admin/includes/class-wp-automatic-updater.php */
     186                        $auto_update_forced = apply_filters( "auto_update_{$type}", null, (object) $filter_payload );
     187
     188                        if ( ! is_null( $auto_update_forced ) ) {
     189                                $theme->auto_update_forced = $auto_update_forced;
     190                        }
     191
    154192                        if ( $this->show_autoupdates ) {
    155                                 if ( in_array( $key, $auto_updates, true ) ) {
    156                                         $themes['auto-update-enabled'][ $key ] = $themes['all'][ $key ];
     193                                $enabled = in_array( $key, $auto_updates, true ) && $theme->update_supported;
     194                                if ( isset( $theme->auto_update_forced ) ) {
     195                                        $enabled = (bool) $theme->auto_update_forced;
     196                                }
     197
     198                                if ( $enabled ) {
     199                                        $themes['auto-update-enabled'][ $key ] = $theme;
    157200                                } else {
    158                                         $themes['auto-update-disabled'][ $key ] = $themes['all'][ $key ];
     201                                        $themes['auto-update-disabled'][ $key ] = $theme;
    159202                                }
    160203                        }
     
    729772                $stylesheet = $theme->get_stylesheet();
    730773
    731                 if ( in_array( $stylesheet, $auto_updates, true ) ) {
     774                if ( isset( $theme->auto_update_forced ) ) {
     775                        if ( $theme->auto_update_forced ) {
     776                                // Forced on.
     777                                $text = __( 'Auto-updates enabled' );
     778                        } else {
     779                                $text = __( 'Auto-updates disabled' );
     780                        }
     781                        $action     = 'unavailable';
     782                        $time_class = ' hidden';
     783                } elseif ( empty( $theme->update_supported ) ) {
     784                        $text       = '';
     785                        $action     = 'unavailable';
     786                        $time_class = ' hidden';
     787                } elseif ( in_array( $stylesheet, $auto_updates, true ) ) {
    732788                        $text       = __( 'Disable auto-updates' );
    733789                        $action     = 'disable';
     
    748804                $url = add_query_arg( $query_args, 'themes.php' );
    749805
    750                 $html[] = sprintf(
    751                         '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
    752                         wp_nonce_url( $url, 'updates' ),
    753                         $action
    754                 );
    755 
    756                 $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
    757                 $html[] = '<span class="label">' . $text . '</span>';
    758                 $html[] = '</a>';
    759 
    760                 $available_updates = get_site_transient( 'update_themes' );
     806                if ( 'unavailable' === $action ) {
     807                        $html[] = '<span class="label">' . $text . '</span>';
     808                } else {
     809                        $html[] = sprintf(
     810                                '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
     811                                wp_nonce_url( $url, 'updates' ),
     812                                $action
     813                        );
     814
     815                        $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
     816                        $html[] = '<span class="label">' . $text . '</span>';
     817                        $html[] = '</a>';
     818
     819                }
     820
    761821                if ( isset( $available_updates->response[ $stylesheet ] ) ) {
    762822                        $html[] = sprintf(
Note: See TracChangeset for help on using the changeset viewer.