Make WordPress Core

Changeset 48669


Ignore:
Timestamp:
07/28/2020 04:30:48 PM (6 years ago)
Author:
whyisjake
Message:

Upgrade/Install: Enhance auto-updates to be disabled for plugins that don't suport updates.

This removes the toggle UI when updates aren't available. When plugins use the filter, the UI is updated to show that they are being controlled via code. And then removed entirely when not available.

See #50798.
Fixes #50280.

Props elrae, pbiron, SergeyBiryukov, audrasjb, azaozz, StephenCronin, whyisjake, dd32, TimothyBlynJacobs, desrosj.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-plugins-list-table.php

    r48451 r48669  
    204204                        // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide.
    205205                        if ( isset( $plugin_info->response[ $plugin_file ] ) ) {
    206                                 $plugin_data                    = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data );
    207                                 $plugins['all'][ $plugin_file ] = $plugin_data;
    208                                 // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade.
    209                                 if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
    210                                         $plugins['upgrade'][ $plugin_file ] = $plugin_data;
    211                                 }
     206                                $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], array( 'auto-update-supported' => true ), $plugin_data );
    212207                        } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) {
    213                                 $plugin_data                    = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data );
    214                                 $plugins['all'][ $plugin_file ] = $plugin_data;
    215                                 // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade.
    216                                 if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
    217                                         $plugins['upgrade'][ $plugin_file ] = $plugin_data;
    218                                 }
     208                                $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], array( 'auto-update-supported' => true ), $plugin_data );
     209                        } elseif ( empty( $plugin_data['auto-update-supported'] ) ) {
     210                                $plugin_data['auto-update-supported'] = false;
     211                        }
     212
     213                        /*
     214                         * Create the payload that's used for the auto_update_plugin filter.
     215                         * This is the same data contained within $plugin_info->(response|no_update) however
     216                         * not all plugins will be contained in those keys, this avoids unexpected warnings.
     217                         */
     218                        $filter_payload = array(
     219                                'id'            => $plugin_file,
     220                                'slug'          => '',
     221                                'plugin'        => $plugin_file,
     222                                'new_version'   => '',
     223                                'url'           => '',
     224                                'package'       => '',
     225                                'icons'         => array(),
     226                                'banners'       => array(),
     227                                'banners_rtl'   => array(),
     228                                'tested'        => '',
     229                                'requires_php'  => '',
     230                                'compatibility' => new stdClass(),
     231                        );
     232                        $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $plugin_data, $filter_payload ) );
     233
     234                        /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
     235                        $auto_update_forced = apply_filters( 'auto_update_plugin', null, $filter_payload );
     236                        if ( ! is_null( $auto_update_forced ) ) {
     237                                $plugin_data['auto-update-forced'] = $auto_update_forced;
     238                        }
     239
     240                        $plugins['all'][ $plugin_file ] = $plugin_data;
     241                        // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade.
     242                        if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) {
     243                                $plugins['upgrade'][ $plugin_file ] = $plugin_data;
    219244                        }
    220245
     
    10611086                                        $html = array();
    10621087
    1063                                         if ( in_array( $plugin_file, $auto_updates, true ) ) {
     1088                                        if ( isset( $plugin_data['auto-update-forced'] ) ) {
     1089                                                if ( $plugin_data['auto-update-forced'] ) {
     1090                                                        // Forced on
     1091                                                        $text = __( 'Auto-updates enabled' );
     1092                                                } else {
     1093                                                        $text = __( 'Auto-updates disabled' );
     1094                                                }
     1095                                                $action     = 'unavailable';
     1096                                                $time_class = ' hidden';
     1097                                        } elseif ( ! $plugin_data['auto-update-supported'] ) {
     1098                                                $text       = '';
     1099                                                $action     = 'unavailable';
     1100                                                $time_class = ' hidden';
     1101                                        } elseif ( in_array( $plugin_file, $auto_updates, true ) ) {
    10641102                                                $text       = __( 'Disable auto-updates' );
    10651103                                                $action     = 'disable';
     
    10801118                                        $url = add_query_arg( $query_args, 'plugins.php' );
    10811119
    1082                                         $html[] = sprintf(
    1083                                                 '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
    1084                                                 wp_nonce_url( $url, 'updates' ),
    1085                                                 $action
    1086                                         );
    1087 
    1088                                         $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
    1089                                         $html[] = '<span class="label">' . $text . '</span>';
    1090                                         $html[] = '</a>';
    1091 
    1092                                         $available_updates = get_site_transient( 'update_plugins' );
    1093 
    1094                                         if ( isset( $available_updates->response[ $plugin_file ] ) ) {
     1120                                        if ( 'unavailable' == $action ) {
     1121                                                $html[] = '<span class="label">' . $text . '</span>';
     1122                                        } else {
     1123                                                $html[] = sprintf(
     1124                                                        '<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
     1125                                                        wp_nonce_url( $url, 'updates' ),
     1126                                                        $action
     1127                                                );
     1128
     1129                                                $html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
     1130                                                $html[] = '<span class="label">' . $text . '</span>';
     1131                                                $html[] = '</a>';
     1132                                        }
     1133
     1134                                        if ( ! empty( $plugin_data['update'] ) ) {
    10951135                                                $html[] = sprintf(
    10961136                                                        '<div class="auto-update-time%s">%s</div>',
  • trunk/src/wp-admin/plugins.php

    r48095 r48669  
    575575                        'content' =>
    576576                                        '<p>' . __( 'Auto-updates can be enabled or disabled for each individual plugin. Plugins with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>' .
     577                                        '<p>' . __( 'Auto-updates are only available for plugins recognized by WordPress.org, or that include a compatible update system.' ) . '</p>' .
    577578                                        '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>',
    578579                )
Note: See TracChangeset for help on using the changeset viewer.