From 0f1f9bdb03070f914939c4f0dd008aaa2de3a059 Mon Sep 17 00:00:00 2001 From: whyisjake Date: Tue, 28 Jul 2020 16:32:01 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@48669 git-svn-id: http://core.svn.wordpress.org/trunk@48431 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-plugins-list-table.php | 88 ++++++++++++++----- wp-admin/plugins.php | 1 + wp-includes/version.php | 2 +- 3 files changed, 66 insertions(+), 25 deletions(-) diff --git a/wp-admin/includes/class-wp-plugins-list-table.php b/wp-admin/includes/class-wp-plugins-list-table.php index 56bc665b66..5041911b33 100644 --- a/wp-admin/includes/class-wp-plugins-list-table.php +++ b/wp-admin/includes/class-wp-plugins-list-table.php @@ -203,19 +203,44 @@ class WP_Plugins_List_Table extends WP_List_Table { foreach ( (array) $plugins['all'] as $plugin_file => $plugin_data ) { // Extra info if known. array_merge() ensures $plugin_data has precedence if keys collide. if ( isset( $plugin_info->response[ $plugin_file ] ) ) { - $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], $plugin_data ); - $plugins['all'][ $plugin_file ] = $plugin_data; - // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade. - if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { - $plugins['upgrade'][ $plugin_file ] = $plugin_data; - } + $plugin_data = array_merge( (array) $plugin_info->response[ $plugin_file ], array( 'auto-update-supported' => true ), $plugin_data ); } elseif ( isset( $plugin_info->no_update[ $plugin_file ] ) ) { - $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], $plugin_data ); - $plugins['all'][ $plugin_file ] = $plugin_data; - // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade. - if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { - $plugins['upgrade'][ $plugin_file ] = $plugin_data; - } + $plugin_data = array_merge( (array) $plugin_info->no_update[ $plugin_file ], array( 'auto-update-supported' => true ), $plugin_data ); + } elseif ( empty( $plugin_data['auto-update-supported'] ) ) { + $plugin_data['auto-update-supported'] = false; + } + + /* + * Create the payload that's used for the auto_update_plugin filter. + * This is the same data contained within $plugin_info->(response|no_update) however + * not all plugins will be contained in those keys, this avoids unexpected warnings. + */ + $filter_payload = array( + 'id' => $plugin_file, + 'slug' => '', + 'plugin' => $plugin_file, + 'new_version' => '', + 'url' => '', + 'package' => '', + 'icons' => array(), + 'banners' => array(), + 'banners_rtl' => array(), + 'tested' => '', + 'requires_php' => '', + 'compatibility' => new stdClass(), + ); + $filter_payload = (object) array_merge( $filter_payload, array_intersect_key( $plugin_data, $filter_payload ) ); + + /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */ + $auto_update_forced = apply_filters( 'auto_update_plugin', null, $filter_payload ); + if ( ! is_null( $auto_update_forced ) ) { + $plugin_data['auto-update-forced'] = $auto_update_forced; + } + + $plugins['all'][ $plugin_file ] = $plugin_data; + // Make sure that $plugins['upgrade'] also receives the extra info since it is used on ?plugin_status=upgrade. + if ( isset( $plugins['upgrade'][ $plugin_file ] ) ) { + $plugins['upgrade'][ $plugin_file ] = $plugin_data; } // Filter into individual sections. @@ -1060,7 +1085,20 @@ class WP_Plugins_List_Table extends WP_List_Table { $html = array(); - if ( in_array( $plugin_file, $auto_updates, true ) ) { + if ( isset( $plugin_data['auto-update-forced'] ) ) { + if ( $plugin_data['auto-update-forced'] ) { + // Forced on + $text = __( 'Auto-updates enabled' ); + } else { + $text = __( 'Auto-updates disabled' ); + } + $action = 'unavailable'; + $time_class = ' hidden'; + } elseif ( ! $plugin_data['auto-update-supported'] ) { + $text = ''; + $action = 'unavailable'; + $time_class = ' hidden'; + } elseif ( in_array( $plugin_file, $auto_updates, true ) ) { $text = __( 'Disable auto-updates' ); $action = 'disable'; $time_class = ''; @@ -1079,19 +1117,21 @@ class WP_Plugins_List_Table extends WP_List_Table { $url = add_query_arg( $query_args, 'plugins.php' ); - $html[] = sprintf( - '', - wp_nonce_url( $url, 'updates' ), - $action - ); + if ( 'unavailable' == $action ) { + $html[] = '' . $text . ''; + } else { + $html[] = sprintf( + '', + wp_nonce_url( $url, 'updates' ), + $action + ); - $html[] = ''; - $html[] = '' . $text . ''; - $html[] = ''; + $html[] = ''; + $html[] = '' . $text . ''; + $html[] = ''; + } - $available_updates = get_site_transient( 'update_plugins' ); - - if ( isset( $available_updates->response[ $plugin_file ] ) ) { + if ( ! empty( $plugin_data['update'] ) ) { $html[] = sprintf( '
%s
', $time_class, diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index 42f196f15a..fe8ea41fb2 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -574,6 +574,7 @@ if ( current_user_can( 'update_plugins' ) && wp_is_auto_update_enabled_for_type( 'title' => __( 'Auto-updates' ), 'content' => '

' . __( '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.' ) . '

' . + '

' . __( 'Auto-updates are only available for plugins recognized by WordPress.org, or that include a compatible update system.' ) . '

' . '

' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '

', ) ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 4914aa80e5..aa428ad11b 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-beta4-48668'; +$wp_version = '5.5-beta4-48669'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.