Skip to content

Commit ad0cf43

Browse files
1 parent 9b9049c commit ad0cf43

19 files changed

+200
-24
lines changed

src/wp-admin/admin-ajax.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
'wp-privacy-erase-personal-data',
137137
'health-check-site-status-result',
138138
'health-check-dotorg-communication',
139+
'health-check-alt-update-api-communication',
139140
'health-check-is-in-debug-mode',
140141
'health-check-background-updates',
141142
'health-check-loopback-requests',

src/wp-admin/includes/class-wp-community-events.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function get_events( $location_search = '', $timezone = '' ) {
9898
// Include an unmodified $wp_version.
9999
require ABSPATH . WPINC . '/version.php';
100100

101-
$api_url = 'http://api.wordpress.org/events/1.0/';
101+
$api_url = WP_UPDATE_API_DEFAULT . '/events/1.0/';
102102
$request_args = $this->get_request_args( $location_search, $timezone );
103103
$request_args['user-agent'] = 'WordPress/' . $wp_version . '; ' . home_url( '/' );
104104

src/wp-admin/includes/class-wp-debug-data.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ private static function get_wp_core(): array {
155155
$core_version = wp_get_wp_version();
156156
$core_updates = get_core_updates();
157157
$core_update_needed = '';
158+
$update_api_base = wp_get_update_api_base();
158159

159160
if ( is_array( $core_updates ) ) {
160161
foreach ( $core_updates as $core => $update ) {
@@ -294,6 +295,36 @@ private static function get_wp_core(): array {
294295
);
295296
}
296297

298+
$fields['update_api_base'] = array(
299+
'label' => 'Update API URL',
300+
'value' => $update_api_base,
301+
'debug' => true
302+
);
303+
304+
if ( WP_UPDATE_API_DEFAULT !== wp_get_update_api_base()) {
305+
$wp_update_api = wp_remote_get( wp_get_update_api_base(), array( 'timeout' => 10 ) );
306+
307+
if ( ! is_wp_error( $wp_update_api ) ) {
308+
$fields['alt_update_api_communication'] = array(
309+
'label' => __( 'Communication with update API' ),
310+
'value' => __( 'Update API is reachable.' ),
311+
'debug' => 'true',
312+
);
313+
} else {
314+
$fields['alt_update_api_communication'] = array(
315+
'label' => __( 'Communication with update API' ),
316+
'value' => sprintf(
317+
/* Translators: 1: hostname of update API, 2: IP address the update API hostname resolves to. 3: The error returned by the lookup */
318+
__('Unable to reach %1$s (%2$s): %3$s' ),
319+
parse_url( $update_api_base, PHP_URL_HOST ),
320+
gethostbyname( parse_url( $update_api_base, PHP_URL_HOST ) ),
321+
$wp_update_api->get_error_message(),
322+
),
323+
'debug' => $wp_update_api->get_error_message(),
324+
);
325+
}
326+
}
327+
297328
return array(
298329
'label' => __( 'WordPress' ),
299330
'fields' => $fields,

src/wp-admin/includes/class-wp-site-health.php

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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(

src/wp-admin/includes/credits.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function wp_credits( $version = '', $locale = '' ) {
3232
|| str_contains( $version, '-' )
3333
|| ( isset( $results['data']['version'] ) && ! str_starts_with( $version, $results['data']['version'] ) )
3434
) {
35-
$url = "http://api.wordpress.org/core/credits/1.1/?version={$version}&locale={$locale}";
35+
$url = WP_UPDATE_API_DEFAULT . "/core/credits/1.1/?version={$version}&locale={$locale}";
3636
$options = array( 'user-agent' => 'WordPress/' . $version . '; ' . home_url( '/' ) );
3737

3838
if ( wp_http_supports( array( 'ssl' ) ) ) {

src/wp-admin/includes/dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ function wp_check_browser_version() {
18141814
$response = get_site_transient( 'browser_' . $key );
18151815

18161816
if ( false === $response ) {
1817-
$url = 'http://api.wordpress.org/core/browse-happy/1.1/';
1817+
$url = wp_get_update_api_base( $https = false ) . '/core/browse-happy/1.1/';
18181818
$options = array(
18191819
'body' => array( 'useragent' => $_SERVER['HTTP_USER_AGENT'] ),
18201820
'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ),

src/wp-admin/includes/import.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function wp_get_popular_importers() {
146146
'locale' => $locale,
147147
'version' => wp_get_wp_version(),
148148
),
149-
'http://api.wordpress.org/core/importers/1.1/'
149+
wp_get_update_api_base( $https = false ) . '/core/importers/1.1/'
150150
);
151151
$options = array( 'user-agent' => 'WordPress/' . wp_get_wp_version() . '; ' . home_url( '/' ) );
152152

src/wp-admin/includes/misc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ function wp_check_php_version() {
15791579
$response = get_site_transient( 'php_check_' . $key );
15801580

15811581
if ( false === $response ) {
1582-
$url = 'http://api.wordpress.org/core/serve-happy/1.0/';
1582+
$url = wp_get_update_api_base( $https = false ) . '/core/serve-happy/1.0/';
15831583

15841584
if ( wp_http_supports( array( 'ssl' ) ) ) {
15851585
$url = set_url_scheme( $url, 'https' );

src/wp-admin/includes/network.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ function network_step2( $errors = false ) {
554554

555555
if ( ! empty( $keys_salts ) ) {
556556
$keys_salts_str = '';
557-
$from_api = wp_remote_get( 'https://api.wordpress.org/secret-key/1.1/salt/' );
557+
$from_api = wp_remote_get( wp_get_update_api_base() . '/secret-key/1.1/salt/' );
558558
if ( is_wp_error( $from_api ) ) {
559559
foreach ( $keys_salts as $c => $v ) {
560560
$keys_salts_str .= "\ndefine( '$c', '" . wp_generate_password( 64, true, true ) . "' );";

src/wp-admin/includes/plugin-install.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function plugins_api( $action, $args = array() ) {
146146

147147
if ( false === $res ) {
148148

149-
$url = 'http://api.wordpress.org/plugins/info/1.2/';
149+
$url = wp_get_update_api_base( $https = false ) . '/plugins/info/1.2/';
150150
$url = add_query_arg(
151151
array(
152152
'action' => $action,

0 commit comments

Comments
 (0)