Skip to content

Commit a9f4f33

Browse files
Refactor all the things (first untested draft)
1 parent acfdc22 commit a9f4f33

15 files changed

+42
-49
lines changed

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 = WP_UPDATE_API_DEFAULT . '/events/1.0/';
101+
$api_url = wp_get_api_request_url( '/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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +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();
158+
$update_api_base = wp_get_api_request_url();
159159

160160
if ( is_array( $core_updates ) ) {
161161
foreach ( $core_updates as $core => $update ) {
@@ -301,7 +301,8 @@ private static function get_wp_core(): array {
301301
'debug' => true
302302
);
303303

304-
if ( WP_UPDATE_API_DEFAULT !== wp_get_update_api_base()) {
304+
$update_dom = parse_url( wp_get_update_api_base(), PHP_URL_HOST );
305+
if ( WP_UPDATE_API_DEFAULT !== $update_dom ) {
305306
$wp_update_api = wp_remote_get( wp_get_update_api_base(), array( 'timeout' => 10 ) );
306307

307308
if ( ! is_wp_error( $wp_update_api ) ) {
@@ -316,8 +317,8 @@ private static function get_wp_core(): array {
316317
'value' => sprintf(
317318
/* Translators: 1: hostname of update API, 2: IP address the update API hostname resolves to. 3: The error returned by the lookup */
318319
__('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 ) ),
320+
$update_dom;
321+
gethostbyname( $update_dom ),
321322
$wp_update_api->get_error_message(),
322323
),
323324
'debug' => $wp_update_api->get_error_message(),

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

Lines changed: 7 additions & 7 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-
WP_UPDATE_API_DEFAULT,
1310+
'http://' . WP_UPDATE_API_DEFAULT . '/',
13111311
array(
13121312
'timeout' => 10,
13131313
)
@@ -1350,7 +1350,7 @@ public function get_test_dotorg_communication() {
13501350
/**
13511351
* Tests if the site can communicate with a non-default update API endpoint.
13521352
*
1353-
* @since 6.9.0
1353+
* @since 7.0.0
13541354
*
13551355
* @return array The test results.
13561356
*/
@@ -1371,7 +1371,7 @@ public function get_test_alt_update_api_communication() {
13711371
);
13721372

13731373
$wp_update_api = wp_remote_get(
1374-
wp_get_update_api_base(),
1374+
wp_get_api_request_url(),
13751375
array(
13761376
'timeout' => 10,
13771377
)
@@ -1392,8 +1392,8 @@ public function get_test_alt_update_api_communication() {
13921392
sprintf(
13931393
/* translators: 1: update API URL. 2: The IP address the update API endpoint resolves to. 3: The error returned by the lookup. */
13941394
__( '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 ) ),
1395+
wp_get_api_request_url(),
1396+
gethostbyname( parse_url( wp_get_api_request_url(), PHP_URL_HOST ) ),
13971397
$wp_update_api->get_error_message()
13981398
)
13991399
)
@@ -1402,7 +1402,7 @@ public function get_test_alt_update_api_communication() {
14021402
$result['actions'] = sprintf(
14031403
/* translators: URL of update API */
14041404
__('Contact the owners of %s for support.'),
1405-
wp_get_update_api_base()
1405+
wp_get_api_request_url()
14061406
);
14071407
}
14081408

@@ -2929,7 +2929,7 @@ public static function get_tests() {
29292929
}
29302930

29312931
// Only check alternate update API endpoint if one has been configured.
2932-
if ( WP_UPDATE_API_DEFAULT !== wp_get_update_api_base() ) {
2932+
if ( WP_UPDATE_API_DEFAULT !== parse_url( wp_get_api_request_url(), PHP_URL_HOST ) ) {
29332933
$tests['async']['alt_update_api_communication'] = array(
29342934
'label' => __( 'Communication with update API' ),
29352935
'test' => rest_url( 'wp-site-health/v1/tests/alt-update-api-communication' ),

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 = WP_UPDATE_API_DEFAULT . "/core/credits/1.1/?version={$version}&locale={$locale}";
35+
$url = wp_get_api_request_url( "/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 = wp_get_update_api_base( $https = false ) . '/core/browse-happy/1.1/';
1817+
$url = wp_get_api_request_url( '/core/browse-happy/1.1/', 'http' );
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-
wp_get_update_api_base( $https = false ) . '/core/importers/1.1/'
149+
wp_get_api_request_url( '/core/importers/1.1/', 'http' )
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 = wp_get_update_api_base( $https = false ) . '/core/serve-happy/1.0/';
1582+
$url = wp_get_api_request_url( '/core/serve-happy/1.0/', 'http' );
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( wp_get_update_api_base() . '/secret-key/1.1/salt/' );
557+
$from_api = wp_remote_get( wp_get_api_request_url( '/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 = wp_get_update_api_base( $https = false ) . '/plugins/info/1.2/';
149+
$url = wp_get_api_request_url( '/plugins/info/1.2/' );
150150
$url = add_query_arg(
151151
array(
152152
'action' => $action,

src/wp-admin/includes/theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ function themes_api( $action, $args = array() ) {
542542
$res = apply_filters( 'themes_api', false, $action, $args );
543543

544544
if ( ! $res ) {
545-
$url = wp_get_update_api_base( $https = false ) . '/themes/info/1.2/';
545+
$url = wp_get_api_request_url( '/themes/info/1.2/', 'http' );
546546
$url = add_query_arg(
547547
array(
548548
'action' => $action,

0 commit comments

Comments
 (0)