Site Health: Display auto-update properly for plugins that don't support auto-updates.

Properly filter `auto_update_plugin` when displaying the table.

Fixes #50822.
Props Gwendydd, pbiron, audrasjb, SergeyBiryukov, whyisjake.


Built from https://develop.svn.wordpress.org/trunk@48731


git-svn-id: http://core.svn.wordpress.org/trunk@48493 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2020-08-04 17:37:02 +00:00
parent fa9b043313
commit b84d7f1fd3
2 changed files with 142 additions and 47 deletions

View File

@ -905,6 +905,8 @@ class WP_Debug_Data {
// List all available plugins. // List all available plugins.
$plugins = get_plugins(); $plugins = get_plugins();
$plugin_updates = get_plugin_updates(); $plugin_updates = get_plugin_updates();
$transient = get_site_transient( 'update_plugins' );
$auto_updates = array(); $auto_updates = array();
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' ); $auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );
@ -947,9 +949,42 @@ class WP_Debug_Data {
} }
if ( $auto_updates_enabled ) { if ( $auto_updates_enabled ) {
if ( in_array( $plugin_path, $auto_updates, true ) ) { if ( isset( $transient->response[ $plugin_path ] ) ) {
$item = $transient->response[ $plugin_path ];
} elseif ( isset( $transient->no_update[ $plugin_path ] ) ) {
$item = $transient->no_update[ $plugin_path ];
} else {
$item = array(
'id' => $plugin_path,
'slug' => '',
'plugin' => $plugin_path,
'new_version' => '',
'url' => '',
'package' => '',
'icons' => array(),
'banners' => array(),
'banners_rtl' => array(),
'tested' => '',
'requires_php' => '',
'compatibility' => new stdClass(),
);
$item = (object) array_merge( $item, array_intersect_key( $plugin, $item ) );
}
/** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
$auto_update_forced = apply_filters( 'auto_update_plugin', null, $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $plugin_path, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Auto-updates enabled' ); $auto_updates_string = __( 'Auto-updates enabled' );
$enabled = true; } else {
$auto_updates_string = __( 'Auto-updates disabled' );
}
/** /**
* Filters the text string of the auto-updates setting for each plugin in the Site Health debug data. * Filters the text string of the auto-updates setting for each plugin in the Site Health debug data.
@ -962,13 +997,6 @@ class WP_Debug_Data {
* @param bool $enabled Whether auto-updates are enabled for this item. * @param bool $enabled Whether auto-updates are enabled for this item.
*/ */
$auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled ); $auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled );
} else {
$auto_updates_string = __( 'Auto-updates disabled' );
$enabled = false;
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
$auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled );
}
$plugin_version_string .= ' | ' . $auto_updates_string; $plugin_version_string .= ' | ' . $auto_updates_string;
$plugin_version_string_debug .= ', ' . $auto_updates_string; $plugin_version_string_debug .= ', ' . $auto_updates_string;
@ -993,6 +1021,7 @@ class WP_Debug_Data {
$active_theme = wp_get_theme(); $active_theme = wp_get_theme();
$theme_updates = get_theme_updates(); $theme_updates = get_theme_updates();
$transient = get_site_transient( 'update_themes' );
$active_theme_version = $active_theme->version; $active_theme_version = $active_theme->version;
$active_theme_version_debug = $active_theme_version; $active_theme_version_debug = $active_theme_version;
@ -1070,27 +1099,38 @@ class WP_Debug_Data {
); );
if ( $auto_updates_enabled ) { if ( $auto_updates_enabled ) {
if ( in_array( $active_theme->stylesheet, $auto_updates, true ) ) { if ( isset( $transient->response[ $active_theme->stylesheet ] ) ) {
$auto_updates_string = __( 'Enabled' ); $item = $transient->response[ $active_theme->stylesheet ];
$enabled = true; } elseif ( isset( $transient->no_update[ $active_theme->stylesheet ] ) ) {
$item = $transient->no_update[ $active_theme->stylesheet ];
} else {
$item = (object) array(
'theme' => $active_theme->stylesheet,
'new_version' => $active_theme->version,
'url' => '',
'package' => '',
'requires' => '',
'requires_php' => '',
);
}
/** /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
* Filters the text string of the auto-updates setting for each theme in the Site Health debug data. $auto_update_forced = apply_filters( 'auto_update_theme', null, $item );
*
* @since 5.5.0 if ( ! is_null( $auto_update_forced ) ) {
* $enabled = $auto_update_forced;
* @param string $auto_updates_string The string output for the auto-updates column. } else {
* @param WP_Theme $theme An object of theme data. $enabled = in_array( $active_theme->stylesheet, $auto_updates, true );
* @param bool $enabled Whether auto-updates are enabled for this item. }
*/
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled ); if ( $enabled ) {
$auto_updates_string = __( 'Enabled' );
} else { } else {
$auto_updates_string = __( 'Disabled' ); $auto_updates_string = __( 'Disabled' );
$enabled = false; }
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */ /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled ); $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled );
}
$info['wp-active-theme']['fields']['auto_update'] = array( $info['wp-active-theme']['fields']['auto_update'] = array(
'label' => __( 'Auto-updates' ), 'label' => __( 'Auto-updates' ),
@ -1144,13 +1184,41 @@ class WP_Debug_Data {
'value' => get_template_directory(), 'value' => get_template_directory(),
), ),
); );
if ( $auto_updates_enabled ) { if ( $auto_updates_enabled ) {
if ( in_array( $parent_theme->stylesheet, $auto_updates, true ) ) { if ( isset( $transient->response[ $parent_theme->stylesheet ] ) ) {
$item = $transient->response[ $parent_theme->stylesheet ];
} elseif ( isset( $transient->no_update[ $parent_theme->stylesheet ] ) ) {
$item = $transient->no_update[ $parent_theme->stylesheet ];
} else {
$item = (object) array(
'theme' => $parent_theme->stylesheet,
'new_version' => $parent_theme->version,
'url' => '',
'package' => '',
'requires' => '',
'requires_php' => '',
);
}
/** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
$auto_update_forced = apply_filters( 'auto_update_theme', null, $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $parent_theme->stylesheet, $auto_updates, true );
}
if ( $enabled ) {
$parent_theme_auto_update_string = __( 'Enabled' ); $parent_theme_auto_update_string = __( 'Enabled' );
} else { } else {
$parent_theme_auto_update_string = __( 'Disabled' ); $parent_theme_auto_update_string = __( 'Disabled' );
} }
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
$parent_theme_auto_update_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $parent_theme, $enabled );
$info['wp-parent-theme']['fields']['auto_update'] = array( $info['wp-parent-theme']['fields']['auto_update'] = array(
'label' => __( 'Auto-update' ), 'label' => __( 'Auto-update' ),
'value' => $parent_theme_auto_update_string, 'value' => $parent_theme_auto_update_string,
@ -1207,20 +1275,47 @@ class WP_Debug_Data {
} }
if ( $auto_updates_enabled ) { if ( $auto_updates_enabled ) {
if ( in_array( $theme_slug, $auto_updates, true ) ) { if ( isset( $transient->response[ $theme_slug ] ) ) {
$auto_updates_string = __( 'Auto-updates enabled' ); $item = $transient->response[ $theme_slug ];
$enabled = true; } elseif ( isset( $transient->no_update[ $theme_slug ] ) ) {
$item = $transient->no_update[ $theme_slug ];
} else {
$item = (object) array(
'theme' => $theme_slug,
'new_version' => $theme->version,
'url' => '',
'package' => '',
'requires' => '',
'requires_php' => '',
);
}
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */ /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled ); $auto_update_forced = apply_filters( 'auto_update_theme', null, $item );
if ( ! is_null( $auto_update_forced ) ) {
$enabled = $auto_update_forced;
} else {
$enabled = in_array( $theme_slug, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Auto-updates enabled' );
} else { } else {
$auto_updates_string = __( 'Auto-updates disabled' ); $auto_updates_string = __( 'Auto-updates disabled' );
$enabled = false;
/** This filter is documented in wp-admin/includes/class-wp-debug-data.php */
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled );
} }
/**
* Filters the text string of the auto-updates setting for each theme in the Site Health debug data.
*
* @since 5.5.0
*
* @param string $auto_updates_string The string output for the auto-updates column.
* @param WP_Theme $theme An object of theme data.
* @param bool $enabled Whether auto-updates are enabled for this item.
*/
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled );
$theme_version_string .= ' | ' . $auto_updates_string; $theme_version_string .= ' | ' . $auto_updates_string;
$theme_version_string_debug .= ',' . $auto_updates_string; $theme_version_string_debug .= ',' . $auto_updates_string;
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.6-alpha-48730'; $wp_version = '5.6-alpha-48731';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.