Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark plugins that don't support auto-updates as Unavailable. #431

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 64 additions & 24 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,44 @@ public function prepare_items() {
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.
Expand Down Expand Up @@ -1060,7 +1085,20 @@ public function single_row( $item ) {

$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 = '';
Expand All @@ -1079,19 +1117,21 @@ public function single_row( $item ) {

$url = add_query_arg( $query_args, 'plugins.php' );

$html[] = sprintf(
'<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
wp_nonce_url( $url, 'updates' ),
$action
);

$html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
$html[] = '<span class="label">' . $text . '</span>';
$html[] = '</a>';
if ( 'unavailable' == $action ) {
$html[] = '<span class="label">' . $text . '</span>';
} else {
$html[] = sprintf(
'<a href="%s" class="toggle-auto-update aria-button-if-js" data-wp-action="%s">',
wp_nonce_url( $url, 'updates' ),
$action
);

$available_updates = get_site_transient( 'update_plugins' );
$html[] = '<span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>';
$html[] = '<span class="label">' . $text . '</span>';
$html[] = '</a>';
}

if ( isset( $available_updates->response[ $plugin_file ] ) ) {
if ( ! empty( $plugin_data['update'] ) ) {
$html[] = sprintf(
'<div class="auto-update-time%s">%s</div>',
$time_class,
Expand Down
11 changes: 9 additions & 2 deletions src/wp-admin/includes/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,13 @@ function wp_recovery_mode_nag() {
* @return bool True if auto-updates are enabled for `$type`, false otherwise.
*/
function wp_is_auto_update_enabled_for_type( $type ) {
if ( ! class_exists( 'WP_Automatic_Updater' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-automatic-updater.php';
}

$updater = new WP_Automatic_Updater();
$enabled = ! $updater->is_disabled();

switch ( $type ) {
case 'plugin':
/**
Expand All @@ -958,7 +965,7 @@ function wp_is_auto_update_enabled_for_type( $type ) {
*
* @param bool $enabled True if plugins auto-update is enabled, false otherwise.
*/
return apply_filters( 'plugins_auto_update_enabled', true );
return apply_filters( 'plugins_auto_update_enabled', $enabled );
case 'theme':
/**
* Filters whether themes auto-update is enabled.
Expand All @@ -967,7 +974,7 @@ function wp_is_auto_update_enabled_for_type( $type ) {
*
* @param bool $enabled True if themes auto-update is enabled, false otherwise.
*/
return apply_filters( 'themes_auto_update_enabled', true );
return apply_filters( 'themes_auto_update_enabled', $enabled );
}

return false;
Expand Down
1 change: 1 addition & 0 deletions src/wp-admin/plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@
'title' => __( 'Auto-updates' ),
'content' =>
'<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>' .
'<p>' . __( 'Auto-updates are only available for plugins recognized by WordPress.org, or that include a compatible update system.' ) . '</p>' .
'<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>',
)
);
Expand Down