From 04373e6772d55e73474503407fcdeaacea290297 Mon Sep 17 00:00:00 2001
From: Paul Biron <paul@sparrowhawkcomputing.com>
Date: Fri, 31 Jul 2020 13:05:39 -0600
Subject: [PATCH] Site Health: Apply `auto_update_{plugin,theme}` when
constructing the strings for displaying whether auto-updates are
enabled/disabled.
---
src/wp-admin/includes/class-wp-debug-data.php | 189 +++++++++++++-----
1 file changed, 144 insertions(+), 45 deletions(-)
diff --git a/src/wp-admin/includes/class-wp-debug-data.php b/src/wp-admin/includes/class-wp-debug-data.php
index 24ca2bdfd2..eb5977bc0f 100644
|
a
|
b
|
class WP_Debug_Data { |
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | if ( $auto_updates_enabled ) { |
| 950 | | if ( in_array( $plugin_path, $auto_updates, true ) ) { |
| | 950 | if ( isset( $plugin_updates[ $plugin_path ]->update ) ) { |
| | 951 | $item = $plugin_updates[ $plugin_path ]->update; |
| | 952 | } else { |
| | 953 | $item = (object) array( |
| | 954 | 'id' => $plugin_path, |
| | 955 | 'slug' => ! empty( basename( $plugin_path ) ) ? basename( $plugin_path ) : $plugin_path, |
| | 956 | 'plugin' => $plugin_path, |
| | 957 | 'new_version' => $plugin['Version'], |
| | 958 | 'url' => '', |
| | 959 | 'package' => '', |
| | 960 | 'icons' => array(), |
| | 961 | 'banners' => array(), |
| | 962 | 'banners_rtl' => array(), |
| | 963 | 'tested' => '', |
| | 964 | 'requires_php' => '', |
| | 965 | 'compatibility' => new stdClass(), |
| | 966 | ); |
| | 967 | } |
| | 968 | |
| | 969 | /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */ |
| | 970 | $auto_update_forced = apply_filters( 'auto_update_plugin', null, $item ); |
| | 971 | |
| | 972 | if ( ! is_null( $auto_update_forced ) ) { |
| | 973 | $enabled = $auto_update_forced; |
| | 974 | } else { |
| | 975 | $enabled = in_array( $plugin_path, $auto_updates, true ); |
| | 976 | } |
| | 977 | |
| | 978 | if ( $enabled ) { |
| 951 | 979 | $auto_updates_string = __( 'Auto-updates enabled' ); |
| 952 | | $enabled = true; |
| 953 | | |
| 954 | | /** |
| 955 | | * Filters the text string of the auto-updates setting for each plugin in the Site Health debug data. |
| 956 | | * |
| 957 | | * @since 5.5.0 |
| 958 | | * |
| 959 | | * @param string $auto_updates_string The string output for the auto-updates column. |
| 960 | | * @param string $plugin_path The path to the plugin file. |
| 961 | | * @param array $plugin An array of plugin data. |
| 962 | | * @param bool $enabled Whether auto-updates are enabled for this item. |
| 963 | | */ |
| 964 | | $auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled ); |
| 965 | 980 | } else { |
| 966 | 981 | $auto_updates_string = __( 'Auto-updates disabled' ); |
| 967 | | $enabled = false; |
| 968 | | |
| 969 | | /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */ |
| 970 | | $auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled ); |
| 971 | 982 | } |
| 972 | 983 | |
| | 984 | /** |
| | 985 | * Filters the text string of the auto-updates setting for each plugin in the Site Health debug data. |
| | 986 | * |
| | 987 | * @since 5.5.0 |
| | 988 | * |
| | 989 | * @param string $auto_updates_string The string output for the auto-updates column. |
| | 990 | * @param string $plugin_path The path to the plugin file. |
| | 991 | * @param array $plugin An array of plugin data. |
| | 992 | * @param bool $enabled Whether auto-updates are enabled for this item. |
| | 993 | */ |
| | 994 | $auto_updates_string = apply_filters( 'plugin_auto_update_debug_string', $auto_updates_string, $plugin_path, $plugin, $enabled ); |
| | 995 | |
| 973 | 996 | $plugin_version_string .= ' | ' . $auto_updates_string; |
| 974 | 997 | $plugin_version_string_debug .= ', ' . $auto_updates_string; |
| 975 | 998 | } |
| … |
… |
class WP_Debug_Data { |
| 1070 | 1093 | ); |
| 1071 | 1094 | |
| 1072 | 1095 | if ( $auto_updates_enabled ) { |
| 1073 | | if ( in_array( $active_theme->stylesheet, $auto_updates, true ) ) { |
| 1074 | | $auto_updates_string = __( 'Enabled' ); |
| 1075 | | $enabled = true; |
| | 1096 | if ( isset( $theme_updates[ $active_theme->stylesheet ]->update ) ) { |
| | 1097 | $item = $theme_updates[ $active_theme->stylesheet ]->update; |
| | 1098 | } else { |
| | 1099 | $item = (object) array( |
| | 1100 | 'theme' => $active_theme->stylesheet, |
| | 1101 | 'new_version' => $active_theme->version, |
| | 1102 | 'url' => '', |
| | 1103 | 'package' => '', |
| | 1104 | 'requires' => '', |
| | 1105 | 'requires_php' => '', |
| | 1106 | ); |
| | 1107 | } |
| 1076 | 1108 | |
| 1077 | | /** |
| 1078 | | * Filters the text string of the auto-updates setting for each theme in the Site Health debug data. |
| 1079 | | * |
| 1080 | | * @since 5.5.0 |
| 1081 | | * |
| 1082 | | * @param string $auto_updates_string The string output for the auto-updates column. |
| 1083 | | * @param WP_Theme $theme An object of theme data. |
| 1084 | | * @param bool $enabled Whether auto-updates are enabled for this item. |
| 1085 | | */ |
| 1086 | | $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled ); |
| | 1109 | /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */ |
| | 1110 | $auto_update_forced = apply_filters( 'auto_update_theme', null, $item ); |
| | 1111 | |
| | 1112 | if ( ! is_null( $auto_update_forced ) ) { |
| | 1113 | $enabled = $auto_update_forced; |
| 1087 | 1114 | } else { |
| 1088 | | $auto_updates_string = __( 'Disabled' ); |
| 1089 | | $enabled = false; |
| | 1115 | $enabled = in_array( $active_theme->stylesheet, $auto_updates, true ); |
| | 1116 | } |
| 1090 | 1117 | |
| 1091 | | /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */ |
| 1092 | | $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled ); |
| | 1118 | if ( $enabled ) { |
| | 1119 | $auto_updates_string = __( 'Enabled' ); |
| | 1120 | } else { |
| | 1121 | $auto_updates_string = __( 'Disabled' ); |
| 1093 | 1122 | } |
| 1094 | 1123 | |
| | 1124 | /** |
| | 1125 | * Filters the text string of the auto-updates setting for each theme in the Site Health debug data. |
| | 1126 | * |
| | 1127 | * @since 5.5.0 |
| | 1128 | * |
| | 1129 | * @param string $auto_updates_string The string output for the auto-updates column. |
| | 1130 | * @param WP_Theme $theme An object of theme data. |
| | 1131 | * @param bool $enabled Whether auto-updates are enabled for this item. |
| | 1132 | */ |
| | 1133 | $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $active_theme, $enabled ); |
| | 1134 | |
| 1095 | 1135 | $info['wp-active-theme']['fields']['auto_update'] = array( |
| 1096 | 1136 | 'label' => __( 'Auto-updates' ), |
| 1097 | 1137 | 'value' => $auto_updates_string, |
| … |
… |
class WP_Debug_Data { |
| 1144 | 1184 | 'value' => get_template_directory(), |
| 1145 | 1185 | ), |
| 1146 | 1186 | ); |
| | 1187 | |
| 1147 | 1188 | if ( $auto_updates_enabled ) { |
| 1148 | | if ( in_array( $parent_theme->stylesheet, $auto_updates, true ) ) { |
| | 1189 | if ( isset( $theme_updates[ $parent_theme->stylesheet ]->update ) ) { |
| | 1190 | $item = $theme_updates[ $parent_theme->stylesheet ]->update; |
| | 1191 | } else { |
| | 1192 | $item = (object) array( |
| | 1193 | 'theme' => $parent_theme->stylesheet, |
| | 1194 | 'new_version' => $parent_theme->version, |
| | 1195 | 'url' => '', |
| | 1196 | 'package' => '', |
| | 1197 | 'requires' => '', |
| | 1198 | 'requires_php' => '', |
| | 1199 | ); |
| | 1200 | } |
| | 1201 | |
| | 1202 | /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */ |
| | 1203 | $auto_update_forced = apply_filters( 'auto_update_theme', null, $item ); |
| | 1204 | |
| | 1205 | if ( ! is_null( $auto_update_forced ) ) { |
| | 1206 | $enabled = $auto_update_forced; |
| | 1207 | } else { |
| | 1208 | $enabled = in_array( $parent_theme->stylesheet, $auto_updates, true ); |
| | 1209 | } |
| | 1210 | |
| | 1211 | if ( $enabled ) { |
| 1149 | 1212 | $parent_theme_auto_update_string = __( 'Enabled' ); |
| 1150 | 1213 | } else { |
| 1151 | 1214 | $parent_theme_auto_update_string = __( 'Disabled' ); |
| 1152 | 1215 | } |
| 1153 | 1216 | |
| | 1217 | /** |
| | 1218 | * Filters the text string of the auto-updates setting for each theme in the Site Health debug data. |
| | 1219 | * |
| | 1220 | * @since 5.5.0 |
| | 1221 | * |
| | 1222 | * @param string $auto_updates_string The string output for the auto-updates column. |
| | 1223 | * @param WP_Theme $theme An object of theme data. |
| | 1224 | * @param bool $enabled Whether auto-updates are enabled for this item. |
| | 1225 | */ |
| | 1226 | $parent_theme_auto_update_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $parent_theme, $enabled ); |
| | 1227 | |
| 1154 | 1228 | $info['wp-parent-theme']['fields']['auto_update'] = array( |
| 1155 | 1229 | 'label' => __( 'Auto-update' ), |
| 1156 | 1230 | 'value' => $parent_theme_auto_update_string, |
| … |
… |
class WP_Debug_Data { |
| 1207 | 1281 | } |
| 1208 | 1282 | |
| 1209 | 1283 | if ( $auto_updates_enabled ) { |
| 1210 | | if ( in_array( $theme_slug, $auto_updates, true ) ) { |
| 1211 | | $auto_updates_string = __( 'Auto-updates enabled' ); |
| 1212 | | $enabled = true; |
| | 1284 | if ( isset( $theme_updates[ $theme_slug ]->update ) ) { |
| | 1285 | $item = $theme_updates[ $theme_slug ]->update; |
| | 1286 | } else { |
| | 1287 | $item = (object) array( |
| | 1288 | 'theme' => $theme_slug, |
| | 1289 | 'new_version' => $theme->version, |
| | 1290 | 'url' => '', |
| | 1291 | 'package' => '', |
| | 1292 | 'requires' => '', |
| | 1293 | 'requires_php' => '', |
| | 1294 | ); |
| | 1295 | } |
| | 1296 | |
| | 1297 | /** This action is documented in wp-admin/includes/class-wp-automatic-updater.php */ |
| | 1298 | $auto_update_forced = apply_filters( 'auto_update_theme', null, $item ); |
| 1213 | 1299 | |
| 1214 | | /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */ |
| 1215 | | $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled ); |
| | 1300 | if ( ! is_null( $auto_update_forced ) ) { |
| | 1301 | $enabled = $auto_update_forced; |
| 1216 | 1302 | } else { |
| 1217 | | $auto_updates_string = __( 'Auto-updates disabled' ); |
| 1218 | | $enabled = false; |
| | 1303 | $enabled = in_array( $theme_slug, $auto_updates, true ); |
| | 1304 | } |
| 1219 | 1305 | |
| 1220 | | /** This filter is documented in wp-admin/includes/class-wp-debug-data.php */ |
| 1221 | | $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled ); |
| | 1306 | if ( $enabled ) { |
| | 1307 | $auto_updates_string = __( 'Auto-updates enabled' ); |
| | 1308 | } else { |
| | 1309 | $auto_updates_string = __( 'Auto-updates disabled' ); |
| 1222 | 1310 | } |
| 1223 | 1311 | |
| | 1312 | /** |
| | 1313 | * Filters the text string of the auto-updates setting for each theme in the Site Health debug data. |
| | 1314 | * |
| | 1315 | * @since 5.5.0 |
| | 1316 | * |
| | 1317 | * @param string $auto_updates_string The string output for the auto-updates column. |
| | 1318 | * @param WP_Theme $theme An object of theme data. |
| | 1319 | * @param bool $enabled Whether auto-updates are enabled for this item. |
| | 1320 | */ |
| | 1321 | $auto_updates_string = apply_filters( 'theme_auto_update_debug_string', $auto_updates_string, $theme, $enabled ); |
| | 1322 | |
| 1224 | 1323 | $theme_version_string .= ' | ' . $auto_updates_string; |
| 1225 | 1324 | $theme_version_string_debug .= ',' . $auto_updates_string; |
| 1226 | 1325 | } |