Skip to content

Commit 0530261

Browse files
committed
Site Health: Remove use of deprecated function from wp_is_https_supported().
Follow up to [56664]. Props peter8nss, debarghyabanerjee, sebastienserre, geekofshire, swissspidy, desrosj. Fixes #62252. See #58494. git-svn-id: https://develop.svn.wordpress.org/trunk@59517 602fd350-edb4-49c9-b593-d223f7449a82
1 parent cdc2f25 commit 0530261

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/wp-includes/https-detection.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,31 +63,33 @@ function wp_is_site_url_using_https() {
6363
/**
6464
* Checks whether HTTPS is supported for the server and domain.
6565
*
66+
* This function makes an HTTP request through `wp_get_https_detection_errors()`
67+
* to check for HTTPS support. As this process can be resource-intensive,
68+
* it should be used cautiously, especially in performance-sensitive environments,
69+
* to avoid potential latency issues.
70+
*
6671
* @since 5.7.0
6772
*
6873
* @return bool True if HTTPS is supported, false otherwise.
6974
*/
7075
function wp_is_https_supported() {
71-
$https_detection_errors = get_option( 'https_detection_errors' );
72-
73-
// If option has never been set by the Cron hook before, run it on-the-fly as fallback.
74-
if ( false === $https_detection_errors ) {
75-
wp_update_https_detection_errors();
76+
$https_detection_errors = wp_get_https_detection_errors();
7677

77-
$https_detection_errors = get_option( 'https_detection_errors' );
78-
}
79-
80-
// If there are no detection errors, HTTPS is supported.
78+
// If there are errors, HTTPS is not supported.
8179
return empty( $https_detection_errors );
8280
}
8381

8482
/**
8583
* Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.
8684
*
87-
* This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained.
85+
* This function checks for HTTPS support by making an HTTP request. As this process can be resource-intensive,
86+
* it should be used cautiously, especially in performance-sensitive environments.
87+
* It is called when HTTPS support needs to be validated.
8888
*
8989
* @since 6.4.0
9090
* @access private
91+
*
92+
* @return array An array containing potential detection errors related to HTTPS, or an empty array if no errors are found.
9193
*/
9294
function wp_get_https_detection_errors() {
9395
/**

tests/phpunit/tests/https-detection.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,34 @@ public function test_wp_is_using_https() {
4141
* @ticket 47577
4242
*/
4343
public function test_wp_is_https_supported() {
44-
// The function works with cached errors, so only test that here.
45-
$wp_error = new WP_Error();
44+
// Simulate that HTTPS is supported by returning an empty error array.
45+
add_filter(
46+
'pre_wp_get_https_detection_errors',
47+
function () {
48+
return new WP_Error(); // No errors means HTTPS is supported.
49+
}
50+
);
4651

4752
// No errors, so HTTPS is supported.
48-
update_option( 'https_detection_errors', $wp_error->errors );
4953
$this->assertTrue( wp_is_https_supported() );
5054

51-
// Errors, so HTTPS is not supported.
52-
$wp_error->add( 'ssl_verification_failed', 'SSL verification failed.' );
53-
update_option( 'https_detection_errors', $wp_error->errors );
55+
// Now we simulate that HTTPS is not supported by returning errors.
56+
$support_errors = new WP_Error();
57+
$support_errors->add( 'ssl_verification_failed', 'SSL verification failed.' );
58+
59+
// Short-circuit the detection logic to return our simulated errors.
60+
add_filter(
61+
'pre_wp_get_https_detection_errors',
62+
function () use ( $support_errors ) {
63+
return $support_errors;
64+
}
65+
);
66+
67+
// Test that HTTPS is not supported due to the simulated errors.
5468
$this->assertFalse( wp_is_https_supported() );
69+
70+
// Remove the filter to avoid affecting other tests.
71+
remove_filter( 'pre_wp_get_https_detection_errors', '__return_null' );
5572
}
5673

5774
/**

0 commit comments

Comments
 (0)