Skip to content
Open
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
24 changes: 8 additions & 16 deletions src/js/_enqueues/wp/updates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2470,18 +2470,13 @@
* @since 4.2.0
*/
$( window ).on( 'beforeunload', wp.updates.beforeunload );
} );

/**
* Click handler for enabling and disabling plugin and theme auto-updates.
*
* @since 5.5.0
*
* TODO: this needs to be refactored to be like the remainder of the handlers
* in this file.
*/
$( document ).ready( function() {
$( $document ).on( 'click', '.column-auto-updates a.toggle-auto-update, .theme-overlay a.toggle-auto-update', function( event ) {
/**
* Click handler for enabling and disabling plugin and theme auto-updates.
*
* @since 5.5.0
*/
$document.on( 'click', '.column-auto-updates a.toggle-auto-update, .theme-overlay a.toggle-auto-update', function( event ) {
var data, asset, type, $parent;
var $anchor = $( this ),
action = $anchor.attr( 'data-wp-action' ),
Expand Down Expand Up @@ -2522,14 +2517,12 @@
$parent.find( '.notice.error' ).addClass( 'hidden' );

// Show loading status.
// TODO: make it readable when network is fast, or possibly remove the interim text change.
if ( 'enable' === action ) {
$label.text( wp.updates.l10n.autoUpdatesEnabling );
} else {
$label.text( wp.updates.l10n.autoUpdatesDisabling );
}

// TODO: Needs design review - the link text jumps under the mouse (part may get selected).
$anchor.find( '.dashicons-update' ).removeClass( 'hidden' );

data = {
Expand All @@ -2546,9 +2539,8 @@
var href = $anchor.attr( 'href' );

if ( ! response.success ) {
// if WP returns 0 for response (which can happen in a few cases
// that aren't quite failures), output the general error message,
// since we won't have response.data.error.
// if WP returns 0 for response (which can happen in a few cases),
// output the general error message since we won't have response.data.error.
if ( response.data && response.data.error ) {
errorMessage = response.data.error;
} else {
Expand Down
20 changes: 9 additions & 11 deletions src/wp-admin/includes/class-wp-automatic-updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ public function should_update( $type, $item, $context ) {
if ( 'core' === $type ) {
$update = Core_Upgrader::should_update_to_version( $item->current );
} elseif ( 'plugin' === $type || 'theme' === $type ) {
$update = false;
if ( wp_is_auto_update_enabled_for_type( $type ) ) {
$update = ! empty( $item->autoupdate );

if ( ! $update && wp_is_auto_update_enabled_for_type( $type ) ) {
// Check if the site admin has enabled auto-updates by default for the specific item.
$auto_updates = (array) get_site_option( "auto_update_{$type}s", array() );
$update = in_array( $item->{$type}, $auto_updates, true ) || ! empty( $item->autoupdate );
$update = in_array( $item->{$type}, $auto_updates, true );
}
} else {
$update = ! empty( $item->autoupdate );
Expand Down Expand Up @@ -976,8 +978,7 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
$body[] = __( 'The following plugins failed to update:' );
// List failed updates.
foreach ( $failed_updates['plugin'] as $item ) {
/* translators: %s: Name of the related plugin. */
$body[] = ' ' . sprintf( __( '- %s' ), $item->name );
$body[] = "- {$item->name}";
}
$body[] = "\n";
}
Expand All @@ -986,8 +987,7 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
$body[] = __( 'The following themes failed to update:' );
// List failed updates.
foreach ( $failed_updates['theme'] as $item ) {
/* translators: %s: Name of the related plugin. */
$body[] = ' ' . sprintf( __( '- %s' ), $item->name );
$body[] = "- {$item->name}";
}
$body[] = "\n";
}
Expand All @@ -996,8 +996,7 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
$body[] = __( 'The following plugins were successfully updated:' );
// List successful updates.
foreach ( $successful_updates['plugin'] as $item ) {
/* translators: %s: Name of the related plugin. */
$body[] = ' ' . sprintf( __( '- %s' ), $item->name );
$body[] = "- {$item->name}";
}
$body[] = "\n";
}
Expand All @@ -1006,8 +1005,7 @@ protected function send_plugin_theme_email( $type, $successful_updates, $failed_
$body[] = __( 'The following themes were successfully updated:' );
// List successful updates.
foreach ( $successful_updates['theme'] as $item ) {
/* translators: %s: Name of the related plugin. */
$body[] = ' ' . sprintf( __( '- %s' ), $item->name );
$body[] = "- {$item->name}";
}
$body[] = "\n";
}
Expand Down
28 changes: 16 additions & 12 deletions src/wp-admin/includes/class-wp-debug-data.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,14 @@ static function debug_data() {
}

// List all available plugins.
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
$auto_updates = array();
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
$auto_updates = array();

$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );
$auto_updates_enabled_str = __( 'Auto-updates enabled' );
$auto_updates_disabled_str = __( 'Auto-updates disabled' );

if ( $auto_updates_enabled ) {
$auto_updates = (array) get_site_option( 'auto_update_plugins', array() );
}
Expand Down Expand Up @@ -899,11 +903,11 @@ static function debug_data() {

if ( $auto_updates_enabled ) {
if ( in_array( $plugin_path, $auto_updates, true ) ) {
$plugin_version_string .= ' | ' . __( 'Auto-updates enabled' );
$plugin_version_string_debug .= ', ' . __( 'Auto-updates enabled' );
$plugin_version_string .= ' | ' . $auto_updates_enabled_str;
$plugin_version_string_debug .= ', ' . $auto_updates_enabled_str;
} else {
$plugin_version_string .= ' | ' . __( 'Auto-updates disabled' );
$plugin_version_string_debug .= ', ' . __( 'Auto-updates disabled' );
$plugin_version_string .= ' | ' . $auto_updates_disabled_str;
$plugin_version_string_debug .= ', ' . $auto_updates_disabled_str;
}
}

Expand Down Expand Up @@ -1123,11 +1127,11 @@ static function debug_data() {

if ( $auto_updates_enabled ) {
if ( in_array( $theme_slug, $auto_updates ) ) {
$theme_version_string .= ' | ' . __( 'Auto-updates enabled' );
$theme_version_string_debug .= ',' . __( 'Auto-updates enabled' );
$theme_version_string .= ' | ' . $auto_updates_enabled_str;
$theme_version_string_debug .= ',' . $auto_updates_enabled_str;
} else {
$theme_version_string .= ' | ' . __( 'Auto-updates disabled' );
$theme_version_string_debug .= ', ' . __( 'Auto-updates disabled' );
$theme_version_string .= ' | ' . $auto_updates_disabled_str;
$theme_version_string_debug .= ', ' . $auto_updates_disabled_str;
}
}

Expand Down
34 changes: 23 additions & 11 deletions src/wp-admin/includes/class-wp-ms-themes-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -718,27 +718,39 @@ function column_autoupdates( $theme ) {
$stylesheet = $theme->get_stylesheet();

if ( in_array( $stylesheet, $auto_updates, true ) ) {
$text = __( 'Disable auto-updates', 'wp-autoupdates' );
$auto_update_time_class = '';
$action = 'disable';
$text = __( 'Disable auto-updates' );
$action = 'disable';
$time_class = '';
} else {
$text = __( 'Enable auto-updates', 'wp-autoupdates' );
$action = 'enable';
$auto_update_time_class = ' hidden';
$text = __( 'Enable auto-updates' );
$action = 'enable';
$time_class = ' hidden';
}

$query_args = array(
'action' => "{$action}-auto-update",
'theme' => $stylesheet,
'paged' => $page,
'theme_status' => $status,
);

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

printf(
'<a href="%s" class="toggle-auto-update" data-wp-action="%s"><span class="dashicons dashicons-update spin hidden"></span><span class="label">%s</span></a>',
wp_nonce_url( 'themes.php?action=' . $action . '-auto-update&amp;theme=' . urlencode( $stylesheet ) . '&amp;paged=' . $page . '&amp;theme_status=' . $status, 'updates' ),
$action,
$text
'<a href="%s" class="toggle-auto-update" data-wp-action="%s">',
wp_nonce_url( $url, 'updates' ),
$action
);

echo '<span class="dashicons dashicons-update spin hidden"></span>';
echo '<span class="label">' . $text . '</span>';
echo '</a>';

$available_updates = get_site_transient( 'update_themes' );
if ( isset( $available_updates->response[ $stylesheet ] ) ) {
printf(
'<div class="auto-update-time%s">%s</div>',
$auto_update_time_class,
$time_class,
wp_get_auto_update_message()
);
}
Expand Down
34 changes: 23 additions & 11 deletions src/wp-admin/includes/class-wp-plugins-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1041,27 +1041,39 @@ public function single_row( $item ) {
echo "<td class='column-auto-updates{$extra_classes}'>";

if ( in_array( $plugin_file, $auto_updates, true ) ) {
$text = __( 'Disable auto-updates', 'wp-autoupdates' );
$action = 'disable';
$auto_update_time_class = '';
$text = __( 'Disable auto-updates' );
$action = 'disable';
$time_class = '';
} else {
$text = __( 'Enable auto-updates', 'wp-autoupdates' );
$action = 'enable';
$auto_update_time_class = ' hidden';
$text = __( 'Enable auto-updates' );
$action = 'enable';
$time_class = ' hidden';
}

$query_args = array(
'action' => "{$action}-auto-update",
'plugin' => $plugin_file,
'paged' => $page,
'plugin_status' => $status,
);

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

printf(
'<a href="%s" class="toggle-auto-update" data-wp-action="%s"><span class="dashicons dashicons-update spin hidden"></span><span class="label">%s</span></a>',
wp_nonce_url( 'plugins.php?action=' . $action . '-auto-update&amp;plugin=' . urlencode( $plugin_file ) . '&amp;paged=' . $page . '&amp;plugin_status=' . $status, 'updates' ),
$action,
$text
'<a href="%s" class="toggle-auto-update" data-wp-action="%s">',
wp_nonce_url( $url, 'updates' ),
$action
);

echo '<span class="dashicons dashicons-update spin hidden"></span>';
echo '<span class="label">' . $text . '</span>';
echo '</a>';

$available_updates = get_site_transient( 'update_plugins' );
if ( isset( $available_updates->response[ $plugin_file ] ) ) {
printf(
'<div class="auto-update-time%s">%s</div>',
$auto_update_time_class,
$time_class,
wp_get_auto_update_message()
);
}
Expand Down
Loading