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,7 +905,9 @@ class WP_Debug_Data {
// List all available plugins.
$plugins = get_plugins();
$plugin_updates = get_plugin_updates();
$auto_updates = array();
$transient = get_site_transient( 'update_plugins' );
$auto_updates = array();
$auto_updates_enabled = wp_is_auto_update_enabled_for_type( 'plugin' );
@ -947,29 +949,55 @@ class WP_Debug_Data {
}
if ( $auto_updates_enabled ) {
if ( in_array( $plugin_path, $auto_updates, true ) ) {
$auto_updates_string = __( 'Auto-updates enabled' );
$enabled = 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 ) );
}
/**
* Filters the text string of the auto-updates setting for each plugin in the Site Health debug data.
*
* @since 5.5.0
*
* @param string $auto_updates_string The string output for the auto-updates column.
* @param string $plugin_path The path to the plugin file.
* @param array $plugin An array of plugin data.
* @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 );
/** 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' );
} 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 );
}
/**
* Filters the text string of the auto-updates setting for each plugin in the Site Health debug data.
*
* @since 5.5.0
*
* @param string $auto_updates_string The string output for the auto-updates column.
* @param string $plugin_path The path to the plugin file.
* @param array $plugin An array of plugin data.
* @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 );
$plugin_version_string .= ' | ' . $auto_updates_string;
$plugin_version_string_debug .= ', ' . $auto_updates_string;
}
@ -993,6 +1021,7 @@ class WP_Debug_Data {
$active_theme = wp_get_theme();
$theme_updates = get_theme_updates();
$transient = get_site_transient( 'update_themes' );
$active_theme_version = $active_theme->version;
$active_theme_version_debug = $active_theme_version;
@ -1070,28 +1099,39 @@ class WP_Debug_Data {
);
if ( $auto_updates_enabled ) {
if ( in_array( $active_theme->stylesheet, $auto_updates, true ) ) {
$auto_updates_string = __( 'Enabled' );
$enabled = true;
if ( isset( $transient->response[ $active_theme->stylesheet ] ) ) {
$item = $transient->response[ $active_theme->stylesheet ];
} 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' => '',
);
}
/**
* 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, $active_theme, $enabled );
/** 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( $active_theme->stylesheet, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Enabled' );
} else {
$auto_updates_string = __( '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, $active_theme, $enabled );
}
/** 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 );
$info['wp-active-theme']['fields']['auto_update'] = array(
'label' => __( 'Auto-updates' ),
'value' => $auto_updates_string,
@ -1144,13 +1184,41 @@ class WP_Debug_Data {
'value' => get_template_directory(),
),
);
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' );
} else {
$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(
'label' => __( 'Auto-update' ),
'value' => $parent_theme_auto_update_string,
@ -1207,20 +1275,47 @@ class WP_Debug_Data {
}
if ( $auto_updates_enabled ) {
if ( in_array( $theme_slug, $auto_updates, true ) ) {
$auto_updates_string = __( 'Auto-updates enabled' );
$enabled = true;
if ( isset( $transient->response[ $theme_slug ] ) ) {
$item = $transient->response[ $theme_slug ];
} 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 */
$auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled );
/** 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( $theme_slug, $auto_updates, true );
}
if ( $enabled ) {
$auto_updates_string = __( 'Auto-updates 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( '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_debug .= ',' . $auto_updates_string;
}

View File

@ -13,7 +13,7 @@
*
* @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.