@@ -1307,7 +1307,7 @@ public function get_test_dotorg_communication() {
13071307 );
13081308
13091309 $ wp_dotorg = wp_remote_get (
1310- ' https://api.wordpress.org ' ,
1310+ WP_UPDATE_API_DEFAULT ,
13111311 array (
13121312 'timeout ' => 10 ,
13131313 )
@@ -1328,7 +1328,7 @@ public function get_test_dotorg_communication() {
13281328 sprintf (
13291329 /* translators: 1: The IP address WordPress.org resolves to. 2: The error returned by the lookup. */
13301330 __ ( 'Your site is unable to reach WordPress.org at %1$s, and returned the error: %2$s ' ),
1331- gethostbyname ( ' api.wordpress.org ' ),
1331+ gethostbyname ( parse_url ( WP_UPDATE_API_DEFAULT , PHP_URL_HOST ) ),
13321332 $ wp_dotorg ->get_error_message ()
13331333 )
13341334 )
@@ -1347,6 +1347,68 @@ public function get_test_dotorg_communication() {
13471347 return $ result ;
13481348 }
13491349
1350+ /**
1351+ * Tests if the site can communicate with a non-default update API endpoint.
1352+ *
1353+ * @since 6.9.0
1354+ *
1355+ * @return array The test results.
1356+ */
1357+ public function get_test_alt_update_api_communication () {
1358+ $ result = array (
1359+ 'label ' => __ ( 'Can communicate with update API ' ),
1360+ 'status ' => '' ,
1361+ 'badge ' => array (
1362+ 'label ' => __ ( 'Security ' ),
1363+ 'color ' => 'blue ' ,
1364+ ),
1365+ 'description ' => sprintf (
1366+ '<p>%s</p> ' ,
1367+ __ ( 'Communicating with the update API is used to check for new versions, and to both install and update WordPress core, themes or plugins. ' )
1368+ ),
1369+ 'actions ' => '' ,
1370+ 'test ' => 'alt_update_api_communication ' ,
1371+ );
1372+
1373+ $ wp_update_api = wp_remote_get (
1374+ wp_get_update_api_base (),
1375+ array (
1376+ 'timeout ' => 10 ,
1377+ )
1378+ );
1379+ if ( ! is_wp_error ( $ wp_update_api ) ) {
1380+ $ result ['status ' ] = 'good ' ;
1381+ } else {
1382+ $ result ['status ' ] = 'critical ' ;
1383+
1384+ $ result ['label ' ] = __ ( 'Could not reach update API ' );
1385+
1386+ $ result ['description ' ] .= sprintf (
1387+ '<p>%s</p> ' ,
1388+ sprintf (
1389+ '<span class="error"><span class="screen-reader-text">%s</span></span> %s ' ,
1390+ /* translators: Hidden accessibility text. */
1391+ __ ( 'Error ' ),
1392+ sprintf (
1393+ /* translators: 1: update API URL. 2: The IP address the update API endpoint resolves to. 3: The error returned by the lookup. */
1394+ __ ( 'Your site is unable to reach the specified update API endpoint (%s) at %s, and returned the error: %s ' ),
1395+ wp_get_update_api_base (),
1396+ gethostbyname ( parse_url ( wp_get_update_api_base (), PHP_URL_HOST ) ),
1397+ $ wp_update_api ->get_error_message ()
1398+ )
1399+ )
1400+ );
1401+
1402+ $ result ['actions ' ] = sprintf (
1403+ /* translators: URL of update API */
1404+ __ ('Contact the owners of %s for support. ' ),
1405+ wp_get_update_api_base ()
1406+ );
1407+ }
1408+
1409+ return $ result ;
1410+ }
1411+
13501412 /**
13511413 * Tests if debug information is enabled.
13521414 *
@@ -2814,6 +2876,10 @@ public static function get_tests() {
28142876 'label ' => __ ( 'Available disk space ' ),
28152877 'test ' => 'available_updates_disk_space ' ,
28162878 ),
2879+ 'update_api_info ' => array (
2880+ 'label ' => __ ( 'Update API Info ' ),
2881+ 'test ' => 'update_api_info ' ,
2882+ ),
28172883 'autoloaded_options ' => array (
28182884 'label ' => __ ( 'Autoloaded options ' ),
28192885 'test ' => 'autoloaded_options ' ,
@@ -2862,6 +2928,16 @@ public static function get_tests() {
28622928 );
28632929 }
28642930
2931+ // Only check alternate update API endpoint if one has been configured.
2932+ if ( WP_UPDATE_API_DEFAULT !== wp_get_update_api_base () ) {
2933+ $ tests ['async ' ]['alt_update_api_communication ' ] = array (
2934+ 'label ' => __ ( 'Communication with update API ' ),
2935+ 'test ' => rest_url ( 'wp-site-health/v1/tests/alt-update-api-communication ' ),
2936+ 'has_rest ' => true ,
2937+ 'async_direct_test ' => array ( WP_Site_Health::get_instance (), 'get_test_alt_update_api_communication ' ),
2938+ );
2939+ }
2940+
28652941 // Only check for caches in production environments.
28662942 if ( 'production ' === wp_get_environment_type () ) {
28672943 $ tests ['async ' ]['page_cache ' ] = array (
0 commit comments