From 1e453929d53d72bbf30a3d48ab996c2a79f6b404 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:15:13 -0600 Subject: [PATCH 01/24] Make the column slug what it will be in core. --- css/wp-autoupdates.css | 2 +- functions.php | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/css/wp-autoupdates.css b/css/wp-autoupdates.css index 189cf40..3769510 100755 --- a/css/wp-autoupdates.css +++ b/css/wp-autoupdates.css @@ -6,7 +6,7 @@ display: inline-block; } -#autoupdates_column { +.plugin .column-auto-updates { min-width: 200px; } diff --git a/functions.php b/functions.php index e187142..9daa608 100755 --- a/functions.php +++ b/functions.php @@ -226,7 +226,7 @@ function wp_autoupdates_selected_themes( $update, $item ) { /** - * Add autoupdate column to plugins screen. + * Add auto-updates column to plugins screen. * * @param string[] The column header labels keyed by column ID. * @return string[] @@ -236,14 +236,14 @@ function wp_autoupdates_add_plugins_autoupdates_column( $columns ) { return $columns; } if ( ! isset( $_GET['plugin_status'] ) || ( 'mustuse' !== $_GET['plugin_status'] && 'dropins' !== $_GET['plugin_status'] ) ) { - $columns['autoupdates_column'] = __( 'Automatic updates', 'wp-autoupdates' ); + $columns['auto-updates'] = __( 'Automatic updates', 'wp-autoupdates' ); } return $columns; } add_filter( is_multisite() ? 'manage_plugins-network_columns' : 'manage_plugins_columns', 'wp_autoupdates_add_plugins_autoupdates_column' ); /** - * Render autoupdate column's content. + * Render auto-updates column's content. * * @param string Name of the column. * @param string $plugin_file Path to the plugin file relative to the plugins directory. @@ -253,7 +253,7 @@ function wp_autoupdates_add_plugins_autoupdates_column_content( $column_name, $p if ( ! ( current_user_can( 'update_plugins' ) && wp_autoupdates_is_plugins_auto_update_enabled() ) ) { return; } - if ( 'autoupdates_column' !== $column_name ) { + if ( 'auto-updates' !== $column_name ) { return; } @@ -1153,7 +1153,7 @@ function wp_autoupdates_get_update_message() { /** - * Add autoupdate column to network themes screen. + * Add auto-updates column to network themes screen. * * @param string[] The column header labels keyed by column ID. * @return string[] @@ -1164,7 +1164,7 @@ function wp_autoupdates_add_themes_autoupdates_column( $columns ) { } if ( ! isset( $_GET['theme_status'] ) || 'broken' !== $_GET['theme_status'] ) { - $columns['autoupdates_column'] = __( 'Automatic updates', 'wp-autoupdates' ); + $columns['auto-updates'] = __( 'Automatic updates', 'wp-autoupdates' ); } return $columns; @@ -1173,7 +1173,7 @@ function wp_autoupdates_add_themes_autoupdates_column( $columns ) { /** - * Render autoupdate column's content. + * Render auto-updates column's content. * * @param string Name of the column. * @param string $stylesheet Directory name of the theme. @@ -1183,7 +1183,7 @@ function wp_autoupdates_add_themes_autoupdates_column_content( $column_name, $st if ( ! ( current_user_can( 'update_plugins' ) && wp_autoupdates_is_themes_auto_update_enabled() ) ) { return; } - if ( 'autoupdates_column' !== $column_name ) { + if ( 'auto-updates' !== $column_name ) { return; } From c0b68323334b1a2afa5a8b222dc028daa137c2aa Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:17:47 -0600 Subject: [PATCH 02/24] Make the plugin list table view slugs what they will be in core. --- functions.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/functions.php b/functions.php index 9daa608..b593f7e 100755 --- a/functions.php +++ b/functions.php @@ -621,8 +621,8 @@ function wp_autoupdates_plugins_status_links( $status_links ) { // when merged, these counts will need to be set in WP_Plugins_List_Table::prepare_items(). $counts = array( - 'autoupdate_enabled' => $enabled_count, - 'autoupdate_disabled' => $totals['all'] - $enabled_count, + 'auto-update-enabled' => $enabled_count, + 'auto-update-disabled' => $totals['all'] - $enabled_count, ); // we can't use the global $status set in WP_Plugin_List_Table::__construct() because @@ -635,7 +635,7 @@ function wp_autoupdates_plugins_status_links( $status_links ) { } switch ( $type ) { - case 'autoupdate_enabled': + case 'auto-update-enabled': /* translators: %s: Number of plugins. */ $text = _n( 'Auto-updates Enabled (%s)', @@ -645,7 +645,7 @@ function wp_autoupdates_plugins_status_links( $status_links ) { ); break; - case 'autoupdate_disabled': + case 'auto-update-disabled': /* translators: %s: Number of plugins. */ $text = _n( 'Auto-updates Disabled (%s)', @@ -690,8 +690,8 @@ function wp_autoupdates_plugins_filter_plugins_by_status( $plugins ) { global $wp_list_table, $page; $custom_statuses = array( - 'autoupdate_enabled', - 'autoupdate_disabled', + 'auto-update-enabled', + 'auto-update-disabled', ); if ( ! ( isset( $_REQUEST['plugin_status'] ) && @@ -706,12 +706,12 @@ function wp_autoupdates_plugins_filter_plugins_by_status( $plugins ) { foreach ( $plugins as $plugin_file => $plugin_data ) { switch ( $_REQUEST['plugin_status'] ) { - case 'autoupdate_enabled': + case 'auto-update-enabled': if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { $_plugins[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); } break; - case 'autoupdate_disabled': + case 'auto-update-disabled': if ( ! in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { $_plugins[ $plugin_file ] = _get_plugin_data_markup_translate( $plugin_file, $plugin_data, false, true ); } From 47a0d92add86e339eaf78b80e65f46b4e0297de7 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:19:54 -0600 Subject: [PATCH 03/24] Make the code for handling enable/disable links closer to what it will be in core. --- functions.php | 160 +++++++++++++++++++++++++++----------------------- 1 file changed, 86 insertions(+), 74 deletions(-) diff --git a/functions.php b/functions.php index b593f7e..b0ab2e7 100755 --- a/functions.php +++ b/functions.php @@ -320,116 +320,128 @@ function wp_autoupdates_plugins_bulk_actions( $actions ) { /** - * Handles auto-updates enabling for plugins. + * Handle enabling and disabling of plugin auto-updates. */ -function wp_autoupdates_plugins_enabler() { +function wp_autoupdates_handle_plugins_enable_disable() { if ( ! isset( $_GET['action'] ) ) { return; } - if ( ! ( 'enable-auto-update' === $_GET['action'] || 'disable-auto-update' === $_GET['action'] ) ) { - return; + + if ( 'enable-auto-update' === $_GET['action'] || 'disable-auto-update' === $_GET['action'] ) { + $plugin = isset( $_GET['plugin'] ) ? wp_unslash( $_GET['plugin'] ) : ''; + $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; + $status = isset( $_GET['plugin_status'] ) && ! empty( esc_html( $_GET['plugin_status'] ) ) ? wp_unslash( esc_html( $_GET['plugin_status'] ) ) : ''; + $s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : ''; } - check_admin_referer( 'updates' ); + if ( 'enable-auto-update' === $_GET['action'] ) { + if ( ! current_user_can( 'update_plugins' ) || ! wp_autoupdates_is_plugins_auto_update_enabled() ) { + wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.', 'wp-autoupdates' ) ); + } - if ( ! current_user_can( 'update_plugins' ) || ! wp_autoupdates_is_plugins_auto_update_enabled() ) { - wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.', 'wp-autoupdates' ) ); - } + if ( is_multisite() && ! is_network_admin() ) { + wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.', 'wp-autoupdates' ) ); + } - if ( is_multisite() && ! is_network_admin() ) { - wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.', 'wp-autoupdates' ) ); - } + check_admin_referer( 'updates' ); + + if ( empty( $plugin ) ) { + wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); + exit; + } + + $auto_updates = get_site_option( 'wp_auto_update_plugins', array() ); - $plugin = ! empty( esc_html( $_GET['plugin'] ) ) ? wp_unslash( esc_html( $_GET['plugin'] ) ) : ''; - $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; - $status = isset( $_GET['plugin_status'] ) && ! empty( esc_html( $_GET['plugin_status'] ) ) ? wp_unslash( esc_html( $_GET['plugin_status'] ) ) : ''; - $s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : ''; + $auto_updates[] = $plugin; + $auto_updates = array_unique( $auto_updates ); - if ( empty( $plugin ) ) { - wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); + update_site_option( 'wp_auto_update_plugins', $auto_updates ); + + wp_redirect( self_admin_url( "plugins.php?disable-auto-update=true&plugin_status=$status&paged=$page&s=$s" ) ); exit; - } + } elseif ( 'disable-auto-update' === $_GET['action'] ) { + if ( ! current_user_can( 'update_plugins' ) || ! wp_autoupdates_is_plugins_auto_update_enabled() ) { + wp_die( __( 'Sorry, you are not allowed to disable plugins automatic updates.', 'wp-autoupdates' ) ); + } - $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); + if ( is_multisite() && ! is_network_admin() ) { + wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.', 'wp-autoupdates' ) ); + } - if ( 'disable-auto-update' === $_GET['action'] ) { - $wp_auto_update_plugins = array_diff( $wp_auto_update_plugins, array( $plugin ) ); - $action_type = 'disable-auto-update=true'; - } else { - $wp_auto_update_plugins[] = $plugin; - $wp_auto_update_plugins = array_unique( $wp_auto_update_plugins ); - $action_type = 'enable-auto-update=true'; - } + check_admin_referer( 'updates' ); + + if ( empty( $plugin ) ) { + wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) ); + exit; + } + + $auto_updates = get_site_option( 'wp_auto_update_plugins', array() ); + + $auto_updates = array_diff( $auto_updates, array( $plugin ) ); + + update_site_option( 'wp_auto_update_plugins', $auto_updates ); - update_site_option( 'wp_auto_update_plugins', $wp_auto_update_plugins ); - wp_redirect( self_admin_url( "plugins.php?$action_type&plugin_status=$status&paged=$page&s=$s" ) ); - exit; + wp_redirect( self_admin_url( "plugins.php?disable-auto-update=true&plugin_status=$status&paged=$page&s=$s" ) ); + exit; + } } +add_action( 'load-plugins.php', 'wp_autoupdates_handle_plugins_enable_disable' ); /** - * Handles auto-updates enabling for themes. + * Handle enabling and disabling of theme auto-updates. */ -function wp_autoupdates_themes_enabler() { +function wp_autoupdates_handle_themes_enable_disable() { if ( ! isset( $_GET['action'] ) ) { return; } - if ( ! ( 'enable-auto-update' === $_GET['action'] || 'disable-auto-update' === $_GET['action'] ) ) { - return; - } - check_admin_referer( 'updates' ); + // in core, the referer is setup in wp-admin/themes.php or wp-admin/network/themes.php. + $temp_args = array( 'enabled-auto-update', 'disabled-auto-update' ); + $referer = remove_query_arg( $temp_args, wp_get_referer() ); - if ( ! current_user_can( 'update_themes' ) || ! wp_autoupdates_is_themes_auto_update_enabled() ) { - wp_die( __( 'Sorry, you are not allowed to enable themes automatic updates.', 'wp-autoupdates' ) ); - } + if ( 'enable-auto-update' === $_GET['action'] ) { + if ( ! ( current_user_can( 'update_themes' ) && wp_autoupdates_is_themes_auto_update_enabled() ) ) { + wp_die( __( 'Sorry, you are not allowed to enable themes automatic updates.' ) ); + } - if ( is_multisite() && ! is_network_admin() ) { - wp_die( __( 'Please connect to your network admin to manage themes automatic updates.', 'wp-autoupdates' ) ); - } + if ( is_multisite() && ! is_network_admin() ) { + wp_die( __( 'Please connect to your network admin to manage themes automatic updates.', 'wp-autoupdates' ) ); + } - $theme = ! empty( esc_html( $_GET['theme'] ) ) ? wp_unslash( esc_html( $_GET['theme'] ) ) : ''; - if ( empty( $theme ) ) { - wp_redirect( self_admin_url( 'themes.php' ) ); - exit; - } + check_admin_referer( 'updates' ); - $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); + $auto_updates = (array) get_site_option( 'wp_auto_update_themes', array() ); - if ( 'disable-auto-update' === $_GET['action'] ) { - $wp_auto_update_themes = array_diff( $wp_auto_update_themes, array( $theme ) ); - $action_type = 'disable-auto-update=true'; - } else { - $wp_auto_update_themes[] = $theme; - $wp_auto_update_themes = array_unique( $wp_auto_update_themes ); - $action_type = 'enable-auto-update=true'; - } + $auto_updates[] = $_GET['theme']; + $auto_updates = array_unique( $auto_updates ); - update_site_option( 'wp_auto_update_themes', $wp_auto_update_themes ); + update_site_option( 'wp_auto_update_themes', $auto_updates ); - $theme_status = ''; - if ( is_multisite() && is_network_admin() ) { - $theme_status = ! empty( $_GET['theme_status'] ) ? 'theme_status=' . $_GET['theme_status'] : ''; - } + wp_safe_redirect( add_query_arg( 'enabled-auto-update', 1, $referer ) ); + exit; + } elseif ( 'disable-auto-update' === $_GET['action'] ) { + if ( ! current_user_can( 'update_themes' ) || ! wp_autoupdates_is_themes_auto_update_enabled() ) { + wp_die( __( 'Sorry, you are not allowed to disable themes automatic updates.', 'wp-autoupdates' ) ); + } - wp_redirect( self_admin_url( "themes.php?$action_type&$theme_status" ) ); - exit; -} + if ( is_multisite() && ! is_network_admin() ) { + wp_die( __( 'Please connect to your network admin to manage themes automatic updates.', 'wp-autoupdates' ) ); + } + check_admin_referer( 'updates' ); -/** - * Handle autoupdates enabling. - */ -function wp_autoupdates_enabler() { - $pagenow = $GLOBALS['pagenow']; + $auto_updates = get_site_option( 'wp_auto_update_themes', array() ); - if ( 'plugins.php' === $pagenow ) { - wp_autoupdates_plugins_enabler(); - } elseif ( 'themes.php' === $pagenow ) { - wp_autoupdates_themes_enabler(); + $new_auto_updates = array_diff( $auto_updates, array( $_GET['theme'] ) ); + + update_site_option( 'wp_auto_update_themes', $new_auto_updates ); + + wp_safe_redirect( add_query_arg( 'disabled-auto-update', 1, $referer ) ); + exit; } } -add_action( 'admin_init', 'wp_autoupdates_enabler' ); +add_action( 'load-themes.php', 'wp_autoupdates_handle_themes_enable_disable' ); /** From 94530b9d4f9922c2cbd0d1deb2d66d08aee0df92 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:27:25 -0600 Subject: [PATCH 04/24] Make the code for handling bulk actions closer to what it will be in core. --- functions.php | 154 +++++++++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 90 deletions(-) diff --git a/functions.php b/functions.php index b0ab2e7..8f6d38f 100755 --- a/functions.php +++ b/functions.php @@ -298,7 +298,7 @@ function wp_autoupdates_add_plugins_autoupdates_column_content( $column_name, $p /** - * Add plugins autoupdates bulk actions. + * Add plugins auto-update bulk actions. * * @param string[] $actions An array of the available bulk actions. * @return string[] @@ -306,11 +306,11 @@ function wp_autoupdates_add_plugins_autoupdates_column_content( $column_name, $p function wp_autoupdates_plugins_bulk_actions( $actions ) { $plugin_status = ! empty( $_GET['plugin_status'] ) ? $_GET['plugin_status'] : ''; - if ( 'autoupdate_enabled' !== $plugin_status ) { - $actions['enable-autoupdate-selected'] = __( 'Enable Auto-updates' ); + if ( 'auto-update-enabled' !== $plugin_status ) { + $actions['enable-auto-update-selected'] = __( 'Enable Auto-updates' ); } - if ( 'autoupdate_disabled' !== $plugin_status ) { - $actions['disable-autoupdate-selected'] = __( 'Disable Auto-updates' ); + if ( 'auto-update-disabled' !== $plugin_status ) { + $actions['disable-auto-update-selected'] = __( 'Disable Auto-updates' ); } return $actions; @@ -445,7 +445,7 @@ function wp_autoupdates_handle_themes_enable_disable() { /** - * Handle plugins autoupdates bulk actions. + * Handle plugins auto-update bulk actions. * * @param string $redirect_to The redirect URL. * @param string $doaction The action being taken. @@ -453,9 +453,8 @@ function wp_autoupdates_handle_themes_enable_disable() { * @return string */ function wp_autoupdates_plugins_bulk_actions_handle( $redirect_to, $doaction, $items ) { - if ( 'enable-autoupdate-selected' === $doaction ) { - check_admin_referer( 'bulk-plugins' ); - + if ( 'enable-auto-update-selected' === $doaction ) { + // in core, this will be in a case statement in wp-admin/plugins.php for this $doaction. if ( ! current_user_can( 'update_plugins' ) || ! wp_autoupdates_is_plugins_auto_update_enabled() ) { wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.', 'wp-autoupdates' ) ); } @@ -464,34 +463,35 @@ function wp_autoupdates_plugins_bulk_actions_handle( $redirect_to, $doaction, $i wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.', 'wp-autoupdates' ) ); } + check_admin_referer( 'bulk-plugins' ); + + // in core, $items will be $_POST['checked']. $plugins = ! empty( $items ) ? (array) wp_unslash( $items ) : array(); + + // in core, these are variables in the scope of wp-admin/plugins.php. $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; $status = isset( $_GET['plugin_status'] ) && ! empty( esc_html( $_GET['plugin_status'] ) ) ? wp_unslash( esc_html( $_GET['plugin_status'] ) ) : ''; $s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : ''; if ( empty( $plugins ) ) { - $redirect_to = self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); - return $redirect_to; + return self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); } - $auto_update_plugins = (array) get_site_option( 'wp_auto_update_plugins', array() ); - $new_autoupdated_plugins = array_merge( $auto_update_plugins, $plugins ); - $new_autoupdated_plugins = array_unique( $new_autoupdated_plugins ); + $auto_updates = (array) get_site_option( 'wp_auto_update_plugins', array() ); + $new_auto_updates = array_merge( $auto_updates, $plugins ); + $new_auto_updates = array_unique( $new_auto_updates ); // return early if all selected plugins already have auto-updates enabled. // must use non-strict comparison, so that array order is not treated as significant. - if ( $new_autoupdated_plugins == $auto_update_plugins ) { - $redirect_to = self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); - return $redirect_to; + if ( $new_auto_updates == $auto_updates ) { + return self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); } - update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); - - $redirect_to = self_admin_url( "plugins.php?enable-auto-update=true&plugin_status=$status&paged=$page&s=$s" ); - return $redirect_to; - } elseif ( 'disable-autoupdate-selected' === $doaction ) { - check_admin_referer( 'bulk-plugins' ); + update_site_option( 'wp_auto_update_plugins', $new_auto_updates ); + return self_admin_url( "plugins.php?enable-auto-update-multi&plugin_status=$status&paged=$page&s=$s" ); + } elseif ( 'disable-auto-update-selected' === $doaction ) { + // in core, this will be in a case statement in wp-admin/plugins.php for this $doaction. if ( ! current_user_can( 'update_plugins' ) || ! wp_autoupdates_is_plugins_auto_update_enabled() ) { wp_die( __( 'Sorry, you are not allowed to enable plugins automatic updates.', 'wp-autoupdates' ) ); } @@ -500,30 +500,32 @@ function wp_autoupdates_plugins_bulk_actions_handle( $redirect_to, $doaction, $i wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.', 'wp-autoupdates' ) ); } + check_admin_referer( 'bulk-plugins' ); + + // in core, $items will be $_POST['checked']. $plugins = ! empty( $items ) ? (array) wp_unslash( $items ) : array(); + + // in core, these are variables in the scope of wp-admin/plugins.php. $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; $status = isset( $_GET['plugin_status'] ) && ! empty( esc_html( $_GET['plugin_status'] ) ) ? wp_unslash( esc_html( $_GET['plugin_status'] ) ) : ''; $s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : ''; if ( empty( $plugins ) ) { - $redirect_to = self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); - return $redirect_to; + return self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); } - $auto_update_plugins = (array) get_site_option( 'wp_auto_update_plugins', array() ); - $new_autoupdated_plugins = array_diff( $auto_update_plugins, $plugins ); + $auto_updates = (array) get_site_option( 'wp_auto_update_plugins', array() ); + $new_auto_updates = array_diff( $auto_updates, $plugins ); // return early if all selected plugins already have auto-updates disabled. // must use non-strict comparison, so that array order is not treated as significant. - if ( $new_autoupdated_plugins == $auto_update_plugins ) { - $redirect_to = self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); - return $redirect_to; + if ( $new_auto_updates == $auto_updates ) { + return self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ); } - update_site_option( 'wp_auto_update_plugins', $new_autoupdated_plugins ); + update_site_option( 'wp_auto_update_plugins', $new_auto_updates ); - $redirect_to = self_admin_url( "plugins.php?disable-auto-update=true&plugin_status=$status&paged=$page&s=$s" ); - return $redirect_to; + return self_admin_url( "plugins.php?disable-auto-update-multi=true&plugin_status=$status&paged=$page&s=$s" ); } return $redirect_to; @@ -1239,21 +1241,21 @@ function wp_autoupdates_add_themes_autoupdates_column_content( $column_name, $st /** - * Add themes autoupdates bulk actions. + * Add themes auto-update bulk actions. * * @param string[] $actions An array of the available bulk actions. * @return string[] */ function wp_autoupdates_themes_bulk_actions( $actions ) { - $actions['enable-autoupdate-selected'] = __( 'Enable auto-updates', 'wp-autoupdates' ); - $actions['disable-autoupdate-selected'] = __( 'Disable auto-updates', 'wp-autoupdates' ); + $actions['enable-auto-update-selected'] = __( 'Enable auto-updates', 'wp-autoupdates' ); + $actions['disable-auto-update-selected'] = __( 'Disable auto-updates', 'wp-autoupdates' ); return $actions; } add_filter( 'bulk_actions-themes-network', 'wp_autoupdates_themes_bulk_actions' ); /** - * Handle themes autoupdates bulk actions. + * Handle themes auto-update bulk actions. * * @param string $redirect_to The redirect URL. * @param string $doaction The action being taken. @@ -1261,85 +1263,57 @@ function wp_autoupdates_themes_bulk_actions( $actions ) { * @return string */ function wp_autoupdates_themes_bulk_actions_handle( $redirect_to, $doaction, $items ) { - if ( 'enable-autoupdate-selected' === $doaction ) { - check_admin_referer( 'bulk-themes' ); - + if ( 'enable-auto-update-selected' === $doaction ) { + // in core, this will be in a case statement in wp-admin/network/themes.php for this $doaction. if ( ! current_user_can( 'update_themes' ) || ! wp_autoupdates_is_themes_auto_update_enabled() ) { wp_die( __( 'Sorry, you are not allowed to enable themes automatic updates.', 'wp-autoupdates' ) ); } - if ( is_multisite() && ! is_network_admin() ) { - wp_die( __( 'Please connect to your network admin to manage themes automatic updates.', 'wp-autoupdates' ) ); - } + check_admin_referer( 'bulk-themes' ); + // in core, $items will be $_GET['checked']. $themes = ! empty( $items ) ? (array) wp_unslash( $items ) : array(); - $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; - $status = isset( $_GET['theme_status'] ) && ! empty( esc_html( $_GET['theme_status'] ) ) ? wp_unslash( esc_html( $_GET['theme_status'] ) ) : ''; - $s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : ''; - if ( empty( $themes ) ) { - $redirect_to = self_admin_url( "themes.php?theme_status=$status&paged=$page&s=$s" ); - return $redirect_to; - } + // in core, the referer is setup in wp-admin/themes.php or wp-admin/network/themes.php. + $temp_args = array( 'enabled-auto-update', 'disabled-auto-update', 'enabled-auto-update-selected', 'disabled-auto-update-selected' ); + $referer = remove_query_arg( $temp_args, wp_get_referer() ); - $themes = isset( $_POST['checked'] ) ? (array) wp_unslash( $_POST['checked'] ) : array(); + $auto_updates = (array) get_site_option( 'wp_auto_update_themes', array() ); + $new_auto_updates = array_merge( $auto_updates, $themes ); + $new_auto_updates = array_unique( $new_auto_updates ); - $auto_update_themes = (array) get_site_option( 'wp_auto_update_themes', array() ); - $new_auto_update_themes = array_merge( $auto_update_themes, $themes ); - $new_auto_update_themes = array_unique( $new_auto_update_themes ); - - // return early if all selected themes already have auto-updates enabled. - // must use non-strict comparison, so that array order is not treated as significant. - if ( $new_auto_update_themes == $auto_update_themes ) { - wp_redirect( self_admin_url( "themes.php?theme_status=$status&paged=$page&s=$s" ) ); - exit; - } - - update_site_option( 'wp_auto_update_themes', $new_auto_update_themes ); - - $redirect_to = self_admin_url( "themes.php?enable-auto-update=true&theme_status=$status&paged=$page&s=$s" ); - return $redirect_to; - } elseif ( 'disable-autoupdate-selected' === $doaction ) { - check_admin_referer( 'bulk-themes' ); + update_site_option( 'wp_auto_update_themes', $new_auto_updates ); + $redirect_to = add_query_arg( 'enabled-auto-update', count( $themes ), $referer ); + } elseif ( 'disable-auto-update-selected' === $doaction ) { + // in core, this will be in a case statement in wp-admin/network/themes.php for this $doaction. if ( ! current_user_can( 'update_themes' ) || ! wp_autoupdates_is_themes_auto_update_enabled() ) { - wp_die( __( 'Sorry, you are not allowed to enable themes automatic updates.', 'wp-autoupdates' ) ); + wp_die( __( 'Sorry, you are not allowed to disable themes automatic updates.', 'wp-autoupdates' ) ); } - if ( is_multisite() && ! is_network_admin() ) { - wp_die( __( 'Please connect to your network admin to manage themes automatic updates.', 'wp-autoupdates' ) ); - } + check_admin_referer( 'bulk-themes' ); + // in core, $items will be $_GET['checked']. $themes = ! empty( $items ) ? (array) wp_unslash( $items ) : array(); - $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; - $status = isset( $_GET['theme_status'] ) && ! empty( esc_html( $_GET['theme_status'] ) ) ? wp_unslash( esc_html( $_GET['theme_status'] ) ) : ''; - $s = isset( $_GET['s'] ) && ! empty( esc_html( $_GET['s'] ) ) ? wp_unslash( esc_html( $_GET['s'] ) ) : ''; - if ( empty( $themes ) ) { - $redirect_to = self_admin_url( "themes.php?theme_status=$status&paged=$page&s=$s" ); - return $redirect_to; - } + // in core, the referer is setup in wp-admin/themes.php or wp-admin/network/themes.php. + $temp_args = array( 'enabled-auto-update', 'disabled-auto-update', 'enabled-auto-update-selected', 'disabled-auto-update-selected' ); + $referer = remove_query_arg( $temp_args, wp_get_referer() ); - $auto_update_themes = (array) get_site_option( 'wp_auto_update_themes', array() ); - $new_auto_update_themes = array_diff( $auto_update_themes, $themes ); + $auto_updates = (array) get_site_option( 'wp_auto_update_themes', array() ); - // return early if all selected themes already have auto-updates disabled. - // must use non-strict comparison, so that array order is not treated as significant. - if ( $new_auto_update_themes == $auto_update_themes ) { - wp_redirect( self_admin_url( "themes.php?plugin_status=$status&paged=$page&s=$s" ) ); - exit; - } + $new_auto_updates = array_diff( $auto_updates, $themes ); - update_site_option( 'wp_auto_update_themes', $new_auto_update_themes ); + update_site_option( 'wp_auto_update_themes', $new_auto_updates ); - $redirect_to = self_admin_url( "themes.php?disable-auto-update=true&theme_status=$status&paged=$page&s=$s" ); - return $redirect_to; + $redirect_to = add_query_arg( 'disabled-auto-update', count( $themes ), $referer ); } return $redirect_to; } add_filter( 'handle_network_bulk_actions-themes-network', 'wp_autoupdates_themes_bulk_actions_handle', 10, 3 ); + /** * Toggle auto updates via Ajax. */ From d73e2e44d90fa01bea24cad465a72970dbec75e2 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:28:40 -0600 Subject: [PATCH 05/24] Make the code for outputting admin notices closer to what it will be in core. --- functions.php | 92 ++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/functions.php b/functions.php index 8f6d38f..33e5ccc 100755 --- a/functions.php +++ b/functions.php @@ -556,53 +556,63 @@ function wp_autoupdates_plugin_deleted( $plugin_file, $deleted ) { add_action( 'deleted_plugin', 'wp_autoupdates_plugin_deleted', 10, 2 ); -/** - * Auto-update notices for plugins. - */ -function wp_autoupdates_plugins_notices() { - if ( isset( $_GET['enable-auto-update'] ) ) { - echo '

'; - _e( 'Selected plugins will be auto-updated.', 'wp-autoupdates' ); - echo '

'; - } - - if ( isset( $_GET['disable-auto-update'] ) ) { - echo '

'; - _e( 'Selected plugins will no longer be auto-updated.', 'wp-autoupdates' ); - echo '

'; - } -} - - -/** - * Auto-update notices for themes. - */ -function wp_autoupdates_themes_notices() { - if ( isset( $_GET['enable-auto-update'] ) ) { - echo '

'; - _e( 'Selected themes will be auto-updated.', 'wp-autoupdates' ); - echo '

'; - } - - if ( isset( $_GET['disable-auto-update'] ) ) { - echo '

'; - _e( 'Selected themes will no longer be auto-updated.', 'wp-autoupdates' ); - echo '

'; - } -} - - /** * Auto-update notices. + * + * Note: the struture of this function may seem more complicated than it needs to + * be, but it is done this way to make it easier to copy into the relevant files + * in the core merge patch (each of which uses a different way to output the notices). */ function wp_autoupdates_notices() { - // Plugins screen. $pagenow = $GLOBALS['pagenow']; - if ( 'plugins.php' === $pagenow ) { - wp_autoupdates_plugins_notices(); - } elseif ( 'themes.php' === $pagenow ) { - wp_autoupdates_themes_notices(); + switch ( $pagenow ) { + case 'plugins.php': + if ( isset( $_GET['enable-auto-update'] ) ) { + ?>

' . sprintf( $message, number_format_i18n( $enabled ) ) . '

'; + } elseif ( isset( $_GET['disabled-auto-update'] ) ) { + $disabled = absint( $_GET['disabled-auto-update'] ); + if ( 1 == $disabled ) { + $message = __( 'Theme will no longer be auto-updated.' ); + } else { + /* translators: %s: Number of themes. */ + $message = _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled ); + } + echo '

' . sprintf( $message, number_format_i18n( $disabled ) ) . '

'; + } + } else { + if ( isset( $_GET['enabled-auto-update'] ) ) { + ?> +

+ +

+ Date: Mon, 11 May 2020 12:30:06 -0600 Subject: [PATCH 06/24] Make the code for preparing themes for JS closer to what it will be in core. --- functions.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/functions.php b/functions.php index 33e5ccc..b08b528 100755 --- a/functions.php +++ b/functions.php @@ -144,14 +144,16 @@ function wp_autoupdates_prepare_themes_for_js( $prepared_themes ) { return $prepared_themes; } - $wp_auto_update_themes = get_option( 'wp_auto_update_themes', array() ); + $auto_updates = get_option( 'wp_auto_update_themes', array() ); foreach ( $prepared_themes as &$theme ) { // Set extra data for use in the template. $slug = $theme['id']; - $encoded_slug = urlencode( $slug ); + $auto_update = in_array( $slug, $auto_updates, true ); - $theme['autoupdate'] = in_array( $slug, $wp_auto_update_themes, true ); - $theme['actions']['autoupdate'] = current_user_can( 'update_themes' ) ? wp_nonce_url( admin_url( 'themes.php?action=autoupdate&theme=' . $encoded_slug ), 'updates' ) : null; + $theme['autoupdate'] = $auto_update; + $theme['actions']['autoupdate'] = current_user_can( 'update_themes' ) + ? wp_nonce_url( admin_url( sprintf( 'themes.php?action=%s&theme=%s', $auto_update ? 'disable-auto-update' : 'enable-auto-update', urlencode( $slug ) ) ), 'updates' ) + : null; } return $prepared_themes; From bc3fb0c49b1d7792240924c0ad25c1f43dd4f96e Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:33:50 -0600 Subject: [PATCH 07/24] Make the code for adding site health info closer to what it will be in core. Also adds auto-update info to the parent theme (if any) and adds a comma before the debug strings. --- functions.php | 176 +++++++++++++++++++------------------------------- 1 file changed, 66 insertions(+), 110 deletions(-) diff --git a/functions.php b/functions.php index b08b528..24e309f 100755 --- a/functions.php +++ b/functions.php @@ -772,9 +772,9 @@ function wp_autoupdates_plugins_filter_plugins_by_status( $plugins ) { /** - * Populate site health informations. + * Populate site health auto-update informations. * - * @param array $args { + * @param array $info { * The debug information to be added to the core information page. * * This is an associative multi-dimensional array, up to three levels deep. The topmost array holds the sections. @@ -804,137 +804,93 @@ function wp_autoupdates_plugins_filter_plugins_by_status( $plugins ) { * @return array */ function wp_autoupdates_debug_information( $info ) { - // Plugins + $enabled_string = __( 'Auto-updates enabled', 'wp-autoupdates' ); + $disabled_string = __( 'Auto-updates disabled', 'wp-autoupdates' ); + if ( wp_autoupdates_is_plugins_auto_update_enabled() ) { // Populate plugins informations. - $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); - - $plugins = get_plugins(); - $plugin_updates = get_plugin_updates(); - - foreach ( $plugins as $plugin_path => $plugin ) { - $plugin_part = ( is_plugin_active( $plugin_path ) ) ? 'wp-plugins-active' : 'wp-plugins-inactive'; - - $plugin_version = $plugin['Version']; - $plugin_author = $plugin['Author']; + $plugins = get_plugins(); + $auto_updates = (array) get_site_option( 'wp_auto_update_plugins', array() ); - $plugin_version_string = __( 'No version or author information is available.', 'wp-autoupdates' ); - $plugin_version_string_debug = __( 'author: (undefined), version: (undefined)', 'wp-autoupdates' ); + foreach ( $info['wp-plugins-active']['fields'] as &$field ) { + $plugin_path = key( wp_list_filter( $plugins, array( 'Name' => $field['label'] ) ) ); - if ( ! empty( $plugin_version ) && ! empty( $plugin_author ) ) { - /* translators: 1: Plugin version number. 2: Plugin author name. */ - $plugin_version_string = sprintf( __( 'Version %1$s by %2$s', 'wp-autoupdates' ), $plugin_version, $plugin_author ); - /* translators: 1: Plugin version number. 2: Plugin author name. */ - $plugin_version_string_debug = sprintf( __( 'version: %1$s, author: %2$s', 'wp-autoupdates' ), $plugin_version, $plugin_author ); + if ( in_array( $plugin_path, $auto_updates, true ) ) { + $field['value'] .= ' | ' . $enabled_string; + $field['debug'] .= ', ' . $enabled_string; } else { - if ( ! empty( $plugin_author ) ) { - /* translators: %s: Plugin author name. */ - $plugin_version_string = sprintf( __( 'By %s', 'wp-autoupdates' ), $plugin_author ); - /* translators: %s: Plugin author name. */ - $plugin_version_string_debug = sprintf( __( 'author: %s, version: (undefined)', 'wp-autoupdates' ), $plugin_author ); - } - - if ( ! empty( $plugin_version ) ) { - /* translators: %s: Plugin version number. */ - $plugin_version_string = sprintf( __( 'Version %s', 'wp-autoupdates' ), $plugin_version ); - /* translators: %s: Plugin version number. */ - $plugin_version_string_debug = sprintf( __( 'author: (undefined), version: %s', 'wp-autoupdates' ), $plugin_version ); - } - } - - if ( array_key_exists( $plugin_path, $plugin_updates ) ) { - /* translators: %s: Latest plugin version number. */ - $plugin_version_string .= ' ' . sprintf( __( '(latest version: %s)', 'wp-autoupdates' ), $plugin_updates[ $plugin_path ]->update->new_version ); - /* translators: %s: Latest plugin version number. */ - $plugin_version_string_debug .= ' ' . sprintf( __( '(latest version: %s)', 'wp-autoupdates' ), $plugin_updates[ $plugin_path ]->update->new_version ); + $field['value'] .= ' | ' . $disabled_string; + $field['debug'] .= ', ' . $disabled_string; } + } + foreach ( $info['wp-plugins-inactive']['fields'] as &$field ) { + $plugin_path = key( wp_list_filter( $plugins, array( 'Name' => $field['label'] ) ) ); - if ( in_array( $plugin_path, $wp_auto_update_plugins, true ) ) { - $plugin_version_string .= ' | ' . sprintf( __( 'Auto-updates enabled', 'wp-autoupdates' ) ); - $plugin_version_string_debug .= sprintf( __( 'Auto-updates enabled', 'wp-autoupdates' ) ); + if ( in_array( $plugin_path, $auto_updates, true ) ) { + $field['value'] .= ' | ' . $enabled_string; + $field['debug'] .= ', ' . $enabled_string; } else { - $plugin_version_string .= ' | ' . sprintf( __( 'Auto-updates disabled', 'wp-autoupdates' ) ); - $plugin_version_string_debug .= sprintf( __( 'Auto-updates disabled', 'wp-autoupdates' ) ); + $field['value'] .= ' | ' . $disabled_string; + $field['debug'] .= ', ' . $disabled_string; } - - $info[ $plugin_part ]['fields'][ sanitize_text_field( $plugin['Name'] ) ] = array( - 'label' => $plugin['Name'], - 'value' => $plugin_version_string, - 'debug' => $plugin_version_string_debug, - ); } } if ( wp_autoupdates_is_themes_auto_update_enabled() ) { // Populate themes informations. - $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); - $themes = wp_get_themes(); + // set up the themes array so we can filter it the same way we do with the plugins array above, + // this is necessary only because of the way site health sets up $info. + $themes = array(); + foreach ( wp_get_themes() as $theme ) { + $theme_slug = $theme->get_stylesheet(); + $themes[ $theme_slug ] = array( + 'Name' => sprintf( + /* translators: 1: Theme name. 2: Theme slug. */ + __( '%1$s (%2$s)', 'wp-autoupdates' ), + $theme->name, + $theme_slug + ) + ); + } $active_theme = wp_get_theme(); + $auto_updates = get_site_option( 'wp_auto_update_themes', array() ); - foreach ( $themes as $theme_path => $theme ) { - $theme_version = sanitize_text_field( $theme['Version'] ); - $theme_author = sanitize_text_field( $theme['Author'] ); - - $is_active_theme = $theme->name === $active_theme->name; - - if ( $is_active_theme ) { - $theme_part = 'wp-active-theme'; + if ( in_array( $active_theme->get_stylesheet(), $auto_updates, true ) ) { + $auto_update_string = __( 'Enabled', 'wp-autoupdates' ); + } else { + $auto_update_string = __( 'Disabled', 'wp-autoupdates' ); + } - if ( in_array( $theme_path, $wp_auto_update_themes, true ) ) { - $theme_auto_update_string = sprintf( __( 'Enabled', 'wp-autoupdates' ) ); - } else { - $theme_auto_update_string = sprintf( __( 'Disabled', 'wp-autoupdates' ) ); - } + $info['wp-active-theme']['fields']['auto_update'] = array( + 'label' => __( 'Auto-update', 'wp-autoupdates' ), + 'value' => $auto_update_string, + 'debug' => $auto_update_string, + ); - $info[ $theme_part ]['fields']['Auto-update'] = array( - 'label' => __( 'Auto-update', 'wp-autoupdates' ), - 'value' => $theme_auto_update_string, - 'debug' => $theme_auto_update_string, - ); + if ( $active_theme->parent_theme ) { + if ( in_array( $active_theme->get_template(), $auto_updates, true ) ) { + $auto_update_string = __( 'Enabled', 'wp-autoupdates' ); } else { - $theme_part = 'wp-themes-inactive'; - - $theme_version_string = __( 'No version or author information is available.', 'wp-autoupdates' ); - $theme_version_string_debug = __( 'author: (undefined), version: (undefined)', 'wp-autoupdates' ); - - if ( ! empty( $theme_version ) && ! empty( $theme_author ) ) { - /* translators: 1: Theme version number. 2: Theme author name. */ - $theme_version_string = sprintf( __( 'Version %1$s by %2$s', 'wp-autoupdates' ), $theme_version, $theme_author ); - /* translators: 1: Theme version number. 2: Theme author name. */ - $theme_version_string_debug = sprintf( __( 'version: %1$s, author: %2$s', 'wp-autoupdates' ), $theme_version, $theme_author ); - } else { - if ( ! empty( $theme_author ) ) { - /* translators: %s: Theme author name. */ - $theme_version_string = sprintf( __( 'By %s', 'wp-autoupdates' ), $theme_author ); - /* translators: %s: Theme author name. */ - $theme_version_string_debug = sprintf( __( 'author: %s, version: (undefined)', 'wp-autoupdates' ), $theme_author ); - } - - if ( ! empty( $theme_version ) ) { - /* translators: %s: Theme version number. */ - $theme_version_string = sprintf( __( 'Version %s', 'wp-autoupdates' ), $theme_version ); - /* translators: %s: Theme version number. */ - $theme_version_string_debug = sprintf( __( 'author: (undefined), version: %s', 'wp-autoupdates' ), $theme_version ); - } - } + $auto_update_string = __( 'Disabled', 'wp-autoupdates' ); + } - if ( in_array( $theme_path, $wp_auto_update_themes, true ) ) { - $theme_version_string .= ' | ' . sprintf( __( 'Auto-updates enabled', 'wp-autoupdates' ) ); - $theme_version_string_debug .= sprintf( __( 'Auto-updates enabled', 'wp-autoupdates' ) ); - } else { - $theme_version_string .= ' | ' . sprintf( __( 'Auto-updates disabled', 'wp-autoupdates' ) ); - $theme_version_string_debug .= sprintf( __( 'Auto-updates disabled', 'wp-autoupdates' ) ); - } + $info['wp-parent-theme']['fields']['auto_update'] = array( + 'label' => __( 'Auto-update', 'wp-autoupdates' ), + 'value' => $auto_update_string, + 'debug' => $auto_update_string, + ); + } - $theme_name = sanitize_text_field( $theme['Name'] ); - $label_name = sprintf( __( '%1$s (%2$s)', 'wp-autoupdates' ), $theme_name, $theme_path ); + foreach ( $info['wp-themes-inactive']['fields'] as &$field ) { + $theme_slug = key( wp_list_filter( $themes, array( 'Name' => $field['label'] ) ) ); - $info[ $theme_part ]['fields'][ $theme_name ] = array( - 'label' => $label_name, - 'value' => $theme_version_string, - 'debug' => $theme_version_string_debug, - ); + if ( in_array( $theme_slug, $auto_updates, true ) ) { + $field['value'] .= ' | ' . $enabled_string; + $field['debug'] .= ', ' . $enabled_string; + } else { + $field['value'] .= ' | ' . $disabled_string; + $field['debug'] .= ', ' . $disabled_string; } } } From 117b0b2d21f5c5aa30ac4ab9e0cf964af2c18a9e Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 12:55:19 -0600 Subject: [PATCH 08/24] Make the email filter names what they will be in core. Also applies the filters inline, rather than in function calls. --- functions.php | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/functions.php b/functions.php index 24e309f..3cfd6ba 100755 --- a/functions.php +++ b/functions.php @@ -900,36 +900,6 @@ function wp_autoupdates_debug_information( $info ) { add_filter( 'debug_information', 'wp_autoupdates_debug_information' ); -/** - * Checks whether plugins auto-update email notifications are enabled. - * - * @return bool True if plugins notifications are enabled, false otherwise. - */ -function wp_autoupdates_is_plugins_auto_update_email_enabled() { - /** - * Filters whether plugins auto-update email notifications are enabled. - * - * @param bool $enabled True if plugins notifications are enabled, false otherwise. - */ - return apply_filters( 'send_plugins_auto_update_email', true ); -} - - -/** - * Checks whether themes auto-update email notifications are enabled. - * - * @return bool True if themes notifications are enabled, false otherwise. - */ -function wp_autoupdates_is_themes_auto_update_email_enabled() { - /** - * Filters whether themes auto-update email notifications are enabled. - * - * @param bool $enabled True if themes notifications are enabled, false otherwise. - */ - return apply_filters( 'send_themes_auto_update_email', true ); -} - - /** * If we tried to perform plugin or theme updates, check if we should send an email. * @@ -939,7 +909,14 @@ function wp_autoupdates_automatic_updates_complete_notification( $results ) { $successful_updates = array(); $failed_updates = array(); - if ( isset( $results['plugin'] ) && wp_autoupdates_is_plugins_auto_update_email_enabled() ) { + /** + * Filters whether to send an email following an automatic background plugin update. + * + * @param bool $enabled True if plugins notifications are enabled, false otherwise. + */ + $notifications_enabled = apply_filters( 'auto_plugin_update_send_email', true ); + + if ( isset( $results['plugin'] ) && $notifications_enabled ) { foreach ( $results['plugin'] as $update_result ) { if ( true === $update_result->result ) { $successful_updates['plugin'][] = $update_result; @@ -949,7 +926,14 @@ function wp_autoupdates_automatic_updates_complete_notification( $results ) { } } - if ( isset( $results['theme'] ) && wp_autoupdates_is_themes_auto_update_enabled() ) { + /** + * Filters whether to send an email following an automatic background theme update. + * + * @param bool $enabled True if notifications are enabled, false otherwise. + */ + $notifications_enabled = apply_filters( 'send_theme_auto_update_email', true ); + + if ( isset( $results['theme'] ) && $notifications_enabled ) { foreach ( $results['theme'] as $update_result ) { if ( true === $update_result->result ) { $successful_updates['theme'][] = $update_result; @@ -1090,7 +1074,7 @@ function wp_autoupdates_send_email_notification( $type, $successful_updates, $fa * @param object $successful_updates The updates that succeeded. * @param object $failed_updates The updates that failed. */ - $email = apply_filters( 'wp_autoupdates_notifications_email', $email, $type, $successful_updates, $failed_updates ); + $email = apply_filters( 'auto_plugin_theme_update_email', $email, $type, $successful_updates, $failed_updates ); wp_mail( $email['to'], wp_specialchars_decode( $email['subject'] ), $email['body'], $email['headers'] ); } From b94d11fbeb94aaf0966c5e372366649639d5b03e Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 13:31:53 -0600 Subject: [PATCH 09/24] Change the column slug in the JS click handler. --- js/wp-autoupdates.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index e55feae..620318a 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -7,7 +7,7 @@ $( document ).ready( function() { - $( '.autoupdates_column, .theme-overlay' ).on( + $( '.column-auto-updates, .theme-overlay' ).on( 'click', '.toggle-auto-update', function( event ) { From 320d621dfc1d3ee017e3313728c927d1d621798a Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 13:52:29 -0600 Subject: [PATCH 10/24] Fix typo in in CSS selector. --- css/wp-autoupdates.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/wp-autoupdates.css b/css/wp-autoupdates.css index 3769510..1922bda 100755 --- a/css/wp-autoupdates.css +++ b/css/wp-autoupdates.css @@ -6,7 +6,7 @@ display: inline-block; } -.plugin .column-auto-updates { +.plugins .column-auto-updates { min-width: 200px; } From 0db3ab32670d0f7e7efa65902034bdbf5c733033 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 16:35:37 -0600 Subject: [PATCH 11/24] Use the new column and list table view slugs in the JS. --- js/wp-autoupdates.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index efaaf57..c427be8 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -16,7 +16,7 @@ $label = $anchor.find( '.label' ), $parent = $anchor.parents( 'themes' !== pagenow - ? '.autoupdates_column' + ? '.column-auto-updates' : '.theme-autoupdate' ); @@ -69,8 +69,8 @@ // TODO: If either count started out 0 the appropriate span won't // be there and hence won't be updated. if ( 'themes' !== pagenow ) { - $enabled = $( '.autoupdate_enabled span' ); - $disabled = $( '.autoupdate_disabled span' ); + $enabled = $( '.auto-update-enabled span' ); + $disabled = $( '.auto-update-disabled span' ); enabledNumber = parseInt( $enabled.text().replace( /[^\d]+/g, '' ) From ce3b746584dfc0c219b27377ebb625e2bd79eabd Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 16:43:06 -0600 Subject: [PATCH 12/24] Make the property names for localized strings for the JS what they will be in core. --- functions.php | 14 +++++++------- js/wp-autoupdates.js | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/functions.php b/functions.php index 3cfd6ba..d337cff 100755 --- a/functions.php +++ b/functions.php @@ -119,13 +119,13 @@ function wp_autoupdates_enqueues( $hook ) { 'wp-autoupdates', 'wp_autoupdates', array( - 'enable' => __( 'Enable auto-updates', 'wp-autoupdates' ), - 'enabling' => __( 'Enabling...', 'wp-autoupdates' ), - 'enabled' => __( 'Auto-updates enabled', 'wp-autoupdates' ), - 'disable' => __( 'Disable auto-updates', 'wp-autoupdates' ), - 'disabling' => __( 'Disabling...', 'wp-autoupdates' ), - 'disabled' => __( 'Auto-updates disabled', 'wp-autoupdates' ), - 'auto_update_error' => __( 'The request could not be completed.', 'wp-autoupdates' ), + 'autoUpdatesEnable' => __( 'Enable auto-updates', 'wp-autoupdates' ), + 'autoUpdatesEnabling' => __( 'Enabling...', 'wp-autoupdates' ), + 'autoUpdatesEnabled' => __( 'Auto-updates enabled', 'wp-autoupdates' ), + 'autoUpdatesDisable' => __( 'Disable auto-updates', 'wp-autoupdates' ), + 'autoUpdatesDisabling' => __( 'Disabling...', 'wp-autoupdates' ), + 'autoUpdatesDisabled' => __( 'Auto-updates disabled', 'wp-autoupdates' ), + 'autoUpdatesError' => __( 'The request could not be completed.', 'wp-autoupdates' ), ) ); } diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index c427be8..f9971ed 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -46,7 +46,7 @@ // Show loading status. $label.text( - 'enable' === action ? l10n.enabling : l10n.disabling + 'enable' === action ? l10n.autoUpdatesEnabling : l10n.autoUpdatesDisabling ); $anchor.find( '.dashicons-update' ).removeClass( 'hidden' ); @@ -103,13 +103,13 @@ if ( 'enable' === action ) { $anchor.attr( 'data-wp-action', 'disable' ); - $label.text( l10n.disable ); + $label.text( l10n.autoUpdatesDisable ); $parent .find( '.auto-update-time' ) .removeClass( 'hidden' ); } else { $anchor.attr( 'data-wp-action', 'enable' ); - $label.text( l10n.enable ); + $label.text( l10n.autoUpdatesEnable ); $parent .find( '.auto-update-time' ) .addClass( 'hidden' ); @@ -117,8 +117,8 @@ wp.a11y.speak( 'enable' === action - ? l10n.enabled - : l10n.disabled, + ? l10n.autoUpdatesEnabled + : l10n.autoUpdatesDisabled, 'polite' ); } else { @@ -137,8 +137,8 @@ .removeClass( 'hidden' ) .addClass( 'notice error' ) .find( 'p' ) - .text( l10n.auto_update_error ); - wp.a11y.speak( l10n.auto_update_error, 'polite' ); + .text( l10n.autoUpdatesError ); + wp.a11y.speak( l10n.autoUpdatesError, 'polite' ); } ) .always( function() { $anchor From 2cc3b83b57a33987824fc0fd61f26111559f2366 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 16:58:30 -0600 Subject: [PATCH 13/24] Make the check for whether a specific plugin/theme should be auto-updated closer to what it will be in core. --- functions.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/functions.php b/functions.php index d337cff..8c87328 100755 --- a/functions.php +++ b/functions.php @@ -199,12 +199,12 @@ function wp_autoupdates_is_themes_auto_update_enabled() { * @return bool */ function wp_autoupdates_selected_plugins( $update, $item ) { - $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); - if ( in_array( $item->plugin, $wp_auto_update_plugins, true ) && wp_autoupdates_is_plugins_auto_update_enabled() ) { - return true; - } else { - return $update; + if ( wp_autoupdates_is_plugins_auto_update_enabled() ) { + $auto_updates = (array) get_site_option( 'wp_auto_update_plugins', array() ); + return in_array( $item->plugin, $auto_updates, true ); } + + return $update; } add_filter( 'auto_update_plugin', 'wp_autoupdates_selected_plugins', 10, 2 ); @@ -217,12 +217,12 @@ function wp_autoupdates_selected_plugins( $update, $item ) { * @return bool */ function wp_autoupdates_selected_themes( $update, $item ) { - $wp_auto_update_themes = get_site_option( 'wp_auto_update_themes', array() ); - if ( in_array( $item->theme, $wp_auto_update_themes, true ) && wp_autoupdates_is_themes_auto_update_enabled() ) { - return true; - } else { - return $update; + if ( wp_autoupdates_is_themes_auto_update_enabled() ) { + $auto_updates = (array) get_site_option( 'wp_auto_update_themes', array() ); + return in_array( $item->theme, $auto_updates, true ); } + + return $update; } add_filter( 'auto_update_theme', 'wp_autoupdates_selected_themes', 10, 2 ); From debdd94bae7ab4b9cb72ceaec956886d4b7b7ba0 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 17:35:44 -0600 Subject: [PATCH 14/24] Avoid nested ternary when adding the autoupdate link when preparing themes for JS. --- functions.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/functions.php b/functions.php index 8c87328..59ada42 100755 --- a/functions.php +++ b/functions.php @@ -147,12 +147,15 @@ function wp_autoupdates_prepare_themes_for_js( $prepared_themes ) { $auto_updates = get_option( 'wp_auto_update_themes', array() ); foreach ( $prepared_themes as &$theme ) { // Set extra data for use in the template. - $slug = $theme['id']; - $auto_update = in_array( $slug, $auto_updates, true ); + $slug = $theme['id']; + $encoded_slug = urlencode( $slug ); + + $auto_update = in_array( $slug, $auto_updates, true ); + $auto_update_action = $auto_update ? 'disable-auto-update' : 'enable-auto-update'; $theme['autoupdate'] = $auto_update; $theme['actions']['autoupdate'] = current_user_can( 'update_themes' ) - ? wp_nonce_url( admin_url( sprintf( 'themes.php?action=%s&theme=%s', $auto_update ? 'disable-auto-update' : 'enable-auto-update', urlencode( $slug ) ) ), 'updates' ) + ? wp_nonce_url( admin_url( 'themes.php?action=' . $auto_update_action . '&theme=' . $encoded_slug ), 'updates' ) : null; } From 35bc1098afe1fe05c9775105c81450b20f95651f Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 17:52:34 -0600 Subject: [PATCH 15/24] Bug fix: when Ajax succeeds, update the @href on the link as well as @data-wp-action. --- js/wp-autoupdates.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index f9971ed..a84682b 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -103,12 +103,30 @@ if ( 'enable' === action ) { $anchor.attr( 'data-wp-action', 'disable' ); + $anchor.attr( + 'href', + $anchor + .attr( 'href' ) + .replace( + 'action=enable-auto-update', + 'action=disable-auto-update' + ) + ); $label.text( l10n.autoUpdatesDisable ); $parent .find( '.auto-update-time' ) .removeClass( 'hidden' ); } else { $anchor.attr( 'data-wp-action', 'enable' ); + $anchor.attr( + 'href', + $anchor + .attr( 'href' ) + .replace( + 'action=disable-auto-update', + 'action=enable-auto-update' + ) + ); $label.text( l10n.autoUpdatesEnable ); $parent .find( '.auto-update-time' ) From 077ed51ba987bed457ec1123fdbd690213c4a2a0 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 17:54:20 -0600 Subject: [PATCH 16/24] Prettier format the JS. --- js/wp-autoupdates.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index a84682b..f9c2ef5 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -46,7 +46,9 @@ // Show loading status. $label.text( - 'enable' === action ? l10n.autoUpdatesEnabling : l10n.autoUpdatesDisabling + 'enable' === action + ? l10n.autoUpdatesEnabling + : l10n.autoUpdatesDisabling ); $anchor.find( '.dashicons-update' ).removeClass( 'hidden' ); From 3e7e5fe1b1ce39d3f16c2eb86a09001e49433b82 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Mon, 11 May 2020 19:43:33 -0600 Subject: [PATCH 17/24] Use em instead of px for the width of the auto-update column. Also adds comments of where each rule is be in core. --- css/wp-autoupdates.css | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/css/wp-autoupdates.css b/css/wp-autoupdates.css index 1922bda..af4cc80 100755 --- a/css/wp-autoupdates.css +++ b/css/wp-autoupdates.css @@ -1,15 +1,19 @@ -.dashicons-update.spin { - animation: rotation 2s infinite linear; +/* in core, this rule will go with similar rules in wp-admin/css/list-tables.css */ +.plugins .column-auto-updates { + min-width: 14.2em; } -.auto-updates-error { +/* in core, this rule will go with the above in wp-admin/css/list-tables.css */ +.plugins .column-auto-updates .auto-updates-error { display: inline-block; } -.plugins .column-auto-updates { - min-width: 200px; +/* in core, this rule will go with similar rules in wp-admin/css/common.css */ +.plugins .column-auto-updates .dashicons-update.spin { + animation: rotation 2s infinite linear; } +/* in core, this rule will go with the equivalent for ".theme-overlay .theme-author a" in wp-admin/css/themes.css */ .theme-overlay .theme-autoupdate a { text-decoration: none; } From a17ffdf2889104a6d971d8ec0eb6e521b8f14486 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 12:28:58 -0600 Subject: [PATCH 18/24] When constructing the nonce_urls for enable/disable links, make the $action explicit, instead of with string concatenation. --- functions.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/functions.php b/functions.php index 59ada42..6374b5e 100755 --- a/functions.php +++ b/functions.php @@ -271,20 +271,21 @@ function wp_autoupdates_add_plugins_autoupdates_column_content( $column_name, $p $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; $plugin_status = ! empty( $_GET['plugin_status'] ) ? wp_unslash( esc_html( $_GET['plugin_status'] ) ) : ''; - $wp_auto_update_plugins = get_site_option( 'wp_auto_update_plugins', array() ); - $auto_update_time_class = ' hidden'; - if ( in_array( $plugin_file, $wp_auto_update_plugins, true ) ) { + $auto_updates = (array) get_site_option( 'wp_auto_update_plugins', array() ); + + if ( in_array( $plugin_file, $auto_updates, true ) ) { $text = __( 'Disable auto-updates', 'wp-autoupdates' ); + $action = 'disable-auto-update'; $auto_update_time_class = ''; - $action = 'disable'; } else { - $text = __( 'Enable auto-updates', 'wp-autoupdates' ); - $action = 'enable'; + $text = __( 'Enable auto-updates', 'wp-autoupdates' ); + $action = 'enable-auto-update'; + $auto_update_time_class = ' hidden'; } printf( '%s', - wp_nonce_url( 'plugins.php?action=' . $action . '-auto-update&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page . '&plugin_status=' . $plugin_status, 'updates' ), + wp_nonce_url( 'plugins.php?action=' . $action . '&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page . '&plugin_status=' . $plugin_status, 'updates' ), $action, $text ); @@ -1164,24 +1165,26 @@ function wp_autoupdates_add_themes_autoupdates_column_content( $column_name, $st $page = ! empty( $_GET['paged'] ) ? absint( $_GET['paged'] ) : ''; $theme_status = ! empty( $_GET['theme_status'] ) ? wp_unslash( esc_html( $_GET['theme_status'] ) ) : ''; - $wp_auto_update_themes = (array) get_site_option( 'wp_auto_update_themes', array() ); - $auto_update_time_class = ' hidden'; - if ( in_array( $stylesheet, $wp_auto_update_themes, true ) ) { + $auto_updates = (array) get_site_option( 'wp_auto_update_themes', array() ); + + if ( in_array( $stylesheet, $auto_updates, true ) ) { $text = __( 'Disable auto-updates', 'wp-autoupdates' ); $auto_update_time_class = ''; - $action = 'disable'; + $action = 'disable-auto-update'; } else { - $text = __( 'Enable auto-updates', 'wp-autoupdates' ); - $action = 'enable'; + $text = __( 'Enable auto-updates', 'wp-autoupdates' ); + $action = 'enable-auto-update'; + $auto_update_time_class = ' hidden'; } printf( '%s', - wp_nonce_url( 'themes.php?action=' . $action . '-auto-update&theme=' . urlencode( $stylesheet ) . '&paged=' . $page . '&theme_status=' . $theme_status, 'updates' ), + wp_nonce_url( 'themes.php?action=' . $action . '&theme=' . urlencode( $stylesheet ) . '&paged=' . $page . '&theme_status=' . $theme_status, 'updates' ), $action, $text ); + $available_updates = get_site_transient( 'update_themes' ); if ( isset( $available_updates->response[ $stylesheet ] ) ) { printf( From 4a5334f9370d7db574cc9ca641d0ae8c11461a3a Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 13:10:01 -0600 Subject: [PATCH 19/24] Be consistent in the variable name used when retrieving the site options. --- functions.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions.php b/functions.php index 6374b5e..3ac060c 100755 --- a/functions.php +++ b/functions.php @@ -1323,16 +1323,16 @@ function wp_autoupdates_toggle_auto_updates() { wp_send_json_error( array( 'error' => $error_message ) ); } - $wp_autoupdates = (array) get_site_option( $option, array() ); + $auto_updates = (array) get_site_option( $option, array() ); if ( 'disable' === $state ) { - $wp_autoupdates = array_diff( $wp_autoupdates, array( $asset ) ); + $auto_updates = array_diff( $auto_updates, array( $asset ) ); } else { - $wp_autoupdates[] = $asset; - $wp_autoupdates = array_unique( $wp_autoupdates ); + $auto_updates[] = $asset; + $auto_updates = array_unique( $auto_updates ); } - update_site_option( $option, $wp_autoupdates ); + update_site_option( $option, $auto_updates ); wp_send_json_success(); } From deb3d4caf5aebf6d5a3f8bfb00ec25e01b472ad1 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 15:19:50 -0600 Subject: [PATCH 20/24] Mostly revertd https://github.com/WordPress/wp-autoupdates/pull/124/commits/a17ffdf2889104a6d971d8ec0eb6e521b8f14486 --- functions.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/functions.php b/functions.php index 3ac060c..c6aeb05 100755 --- a/functions.php +++ b/functions.php @@ -275,17 +275,17 @@ function wp_autoupdates_add_plugins_autoupdates_column_content( $column_name, $p if ( in_array( $plugin_file, $auto_updates, true ) ) { $text = __( 'Disable auto-updates', 'wp-autoupdates' ); - $action = 'disable-auto-update'; + $action = 'disable'; $auto_update_time_class = ''; } else { $text = __( 'Enable auto-updates', 'wp-autoupdates' ); - $action = 'enable-auto-update'; + $action = 'enable'; $auto_update_time_class = ' hidden'; } printf( '%s', - wp_nonce_url( 'plugins.php?action=' . $action . '&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page . '&plugin_status=' . $plugin_status, 'updates' ), + wp_nonce_url( 'plugins.php?action=' . $action . '-auto-update&plugin=' . urlencode( $plugin_file ) . '&paged=' . $page . '&plugin_status=' . $plugin_status, 'updates' ), $action, $text ); @@ -1170,16 +1170,16 @@ function wp_autoupdates_add_themes_autoupdates_column_content( $column_name, $st if ( in_array( $stylesheet, $auto_updates, true ) ) { $text = __( 'Disable auto-updates', 'wp-autoupdates' ); $auto_update_time_class = ''; - $action = 'disable-auto-update'; + $action = 'disable'; } else { $text = __( 'Enable auto-updates', 'wp-autoupdates' ); - $action = 'enable-auto-update'; + $action = 'enable'; $auto_update_time_class = ' hidden'; } printf( '%s', - wp_nonce_url( 'themes.php?action=' . $action . '&theme=' . urlencode( $stylesheet ) . '&paged=' . $page . '&theme_status=' . $theme_status, 'updates' ), + wp_nonce_url( 'themes.php?action=' . $action . '-auto-update&theme=' . urlencode( $stylesheet ) . '&paged=' . $page . '&theme_status=' . $theme_status, 'updates' ), $action, $text ); From e19bf2927457ecbb3a630a2bc7598bf5fef8df6c Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 15:25:09 -0600 Subject: [PATCH 21/24] Simplify the display of Ajax errors. --- functions.php | 4 ++-- js/wp-autoupdates.js | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/functions.php b/functions.php index c6aeb05..80ac215 100755 --- a/functions.php +++ b/functions.php @@ -298,7 +298,7 @@ function wp_autoupdates_add_plugins_autoupdates_column_content( $column_name, $p wp_autoupdates_get_update_message() ); } - echo ''; + echo ''; } add_action( 'manage_plugins_custom_column', 'wp_autoupdates_add_plugins_autoupdates_column_content', 10, 3 ); @@ -1193,7 +1193,7 @@ function wp_autoupdates_add_themes_autoupdates_column_content( $column_name, $st wp_autoupdates_get_update_message() ); } - echo ''; + echo ''; } add_action( 'manage_themes_custom_column', 'wp_autoupdates_add_themes_autoupdates_column_content', 10, 3 ); diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index f9c2ef5..e70c4c8 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -40,8 +40,7 @@ // Clear any previous errors. $parent - .find( '.auto-updates-error' ) - .removeClass( 'notice error' ) + .find( '.notice.error' ) .addClass( 'hidden' ); // Show loading status. @@ -143,9 +142,8 @@ ); } else { $parent - .find( '.auto-updates-error' ) + .find( '.notice.error' ) .removeClass( 'hidden' ) - .addClass( 'notice error' ) .find( 'p' ) .text( response.data.error ); wp.a11y.speak( response.data.error, 'polite' ); @@ -153,9 +151,8 @@ } ) .fail( function() { $parent - .find( '.auto-updates-error' ) + .find( '.notice.error' ) .removeClass( 'hidden' ) - .addClass( 'notice error' ) .find( 'p' ) .text( l10n.autoUpdatesError ); wp.a11y.speak( l10n.autoUpdatesError, 'polite' ); From 750d36ef8dc4fe0a9cc37290096f23a6a90c01ae Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 15:29:47 -0600 Subject: [PATCH 22/24] Handle an edge case in Ajax, when WP returns "0" in the response for certain "failures". --- js/wp-autoupdates.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/js/wp-autoupdates.js b/js/wp-autoupdates.js index e70c4c8..8f7af37 100644 --- a/js/wp-autoupdates.js +++ b/js/wp-autoupdates.js @@ -62,7 +62,7 @@ $.post( window.ajaxurl, data ) .done( function( response ) { - let $enabled, $disabled, enabledNumber, disabledNumber; + let $enabled, $disabled, enabledNumber, disabledNumber, errorMessage; if ( response.success ) { // Update the counts in the enabled/disabled views if on on @@ -141,12 +141,18 @@ 'polite' ); } else { + // 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. + errorMessage = response.data && response.data.error + ? response.data.error + : wp.updates.l10n.autoUpdatesError; $parent .find( '.notice.error' ) .removeClass( 'hidden' ) .find( 'p' ) - .text( response.data.error ); - wp.a11y.speak( response.data.error, 'polite' ); + .text( errorMessage ); + wp.a11y.speak( errorMessage, 'polite' ); } } ) .fail( function() { From e9c362d1f03f87270f99cdb224a7c57fed4cff7c Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 15:35:55 -0600 Subject: [PATCH 23/24] No longer need this CSS rule for the error div. --- css/wp-autoupdates.css | 5 ----- 1 file changed, 5 deletions(-) diff --git a/css/wp-autoupdates.css b/css/wp-autoupdates.css index af4cc80..54db26a 100755 --- a/css/wp-autoupdates.css +++ b/css/wp-autoupdates.css @@ -3,11 +3,6 @@ min-width: 14.2em; } -/* in core, this rule will go with the above in wp-admin/css/list-tables.css */ -.plugins .column-auto-updates .auto-updates-error { - display: inline-block; -} - /* in core, this rule will go with similar rules in wp-admin/css/common.css */ .plugins .column-auto-updates .dashicons-update.spin { animation: rotation 2s infinite linear; From 3fd9db3153f9dcf98ea307470f3c7b1e35b66928 Mon Sep 17 00:00:00 2001 From: Paul Biron Date: Tue, 12 May 2020 15:43:38 -0600 Subject: [PATCH 24/24] Add correct CSS selector so the dashicon animates on the non-multisite themes screen. And that's the last commit. I promise. --- css/wp-autoupdates.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/css/wp-autoupdates.css b/css/wp-autoupdates.css index 54db26a..47899ae 100755 --- a/css/wp-autoupdates.css +++ b/css/wp-autoupdates.css @@ -4,7 +4,8 @@ } /* in core, this rule will go with similar rules in wp-admin/css/common.css */ -.plugins .column-auto-updates .dashicons-update.spin { +.plugins .column-auto-updates .dashicons-update.spin, +.theme-overlay .theme-autoupdate .dashicons-update.spin { animation: rotation 2s infinite linear; }