Ticket #58494: 58494.diff
File 58494.diff, 7.2 KB (added by , 20 months ago) |
---|
-
src/wp-admin/includes/class-wp-site-health.php
diff --git src/wp-admin/includes/class-wp-site-health.php src/wp-admin/includes/class-wp-site-health.php index a0e1de586b..481328808b 100644
class WP_Site_Health { 1560 1560 */ 1561 1561 public function get_test_https_status() { 1562 1562 /* 1563 * Enforce fresh HTTPS detection results. This is normally invoked by using cron, 1564 * but for Site Health it should always rely on the latest results. 1563 * Check HTTPS detection results. 1565 1564 */ 1566 wp_update_https_detection_errors();1565 $errors = wp_get_https_detection_errors(); 1567 1566 1568 1567 $default_update_url = wp_get_default_update_https_url(); 1569 1568 -
src/wp-includes/default-filters.php
diff --git src/wp-includes/default-filters.php src/wp-includes/default-filters.php index bf39f29b4d..160774d29f 100644
if ( ! defined( 'DOING_CRON' ) ) { 388 388 add_action( 'init', 'wp_cron' ); 389 389 } 390 390 391 // HTTPS detection.392 add_action( 'init', 'wp_schedule_https_detection' );393 add_action( 'wp_https_detection', 'wp_update_https_detection_errors' );394 add_filter( 'cron_request', 'wp_cron_conditionally_prevent_sslverify', 9999 );395 396 391 // HTTPS migration. 397 392 add_action( 'update_option_home', 'wp_update_https_migration_required', 10, 2 ); 398 393 -
src/wp-includes/deprecated.php
diff --git src/wp-includes/deprecated.php src/wp-includes/deprecated.php index 72bf98d832..e53b677df6 100644
function block_core_navigation_submenu_build_css_colors( $context, $attributes, 5367 5367 5368 5368 return $colors; 5369 5369 } 5370 5371 5372 /** 5373 * Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors. 5374 * 5375 * This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained. 5376 * 5377 * @since 5.7.0 5378 * @deprecated 6.4.0 The `wp_update_https_detection_errors()` function is no longer used and has been replaced by 5379 * `wp_get_https_detection_errors()`. Previously the function was called by a regular Cron hook to 5380 * update the `https_detection_errors` option, but this is no longer necessary as the errors are 5381 * retrieved directly in Site Health and no longer used outside of Site Health. 5382 * @access private 5383 */ 5384 function wp_update_https_detection_errors() { 5385 _deprecated_function( __FUNCTION__, '6.4.0' ); 5386 5387 /** 5388 * Short-circuits the process of detecting errors related to HTTPS support. 5389 * 5390 * Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote 5391 * request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead. 5392 * 5393 * @since 5.7.0 5394 * 5395 * @param null|WP_Error $pre Error object to short-circuit detection, 5396 * or null to continue with the default behavior. 5397 */ 5398 $support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null ); 5399 if ( is_wp_error( $support_errors ) ) { 5400 update_option( 'https_detection_errors', $support_errors->errors ); 5401 return; 5402 } 5403 5404 $support_errors = wp_get_https_detection_errors(); 5405 5406 update_option( 'https_detection_errors', $support_errors ); 5407 } 5408 No newline at end of file -
src/wp-includes/https-detection.php
diff --git src/wp-includes/https-detection.php src/wp-includes/https-detection.php index 878dd1aa38..0250f75a03 100644
function wp_is_https_supported() { 86 86 * 87 87 * This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained. 88 88 * 89 * @since 5.7.089 * @since 6.4.0 90 90 * @access private 91 91 */ 92 function wp_ update_https_detection_errors() {92 function wp_get_https_detection_errors() { 93 93 /** 94 94 * Short-circuits the process of detecting errors related to HTTPS support. 95 95 * 96 96 * Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote 97 97 * request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead. 98 98 * 99 * @since 5.7.099 * @since 6.4.0 100 100 * 101 101 * @param null|WP_Error $pre Error object to short-circuit detection, 102 102 * or null to continue with the default behavior. 103 * @return null|WP_Error Error object if HTTPS detection errors are found, null otherwise. 103 104 */ 104 $support_errors = apply_filters( 'pre_wp_ update_https_detection_errors', null );105 $support_errors = apply_filters( 'pre_wp_get_https_detection_errors', null ); 105 106 if ( is_wp_error( $support_errors ) ) { 106 update_option( 'https_detection_errors', $support_errors->errors ); 107 return; 107 return $support_errors->errors; 108 108 } 109 109 110 110 $support_errors = new WP_Error(); … … function wp_update_https_detection_errors() { 153 153 } 154 154 } 155 155 156 update_option( 'https_detection_errors', $support_errors->errors ); 157 } 158 159 /** 160 * Schedules the Cron hook for detecting HTTPS support. 161 * 162 * @since 5.7.0 163 * @access private 164 */ 165 function wp_schedule_https_detection() { 166 if ( wp_installing() ) { 167 return; 156 // Remove the previously cron scheduled https check (since version 6.4). 157 $scheduled = wp_get_scheduled_event( 'wp_https_detection' ); 158 if ( $scheduled && false !== $scheduled->schedule ) { 159 wp_unschedule_event( $scheduled->timestamp, $scheduled->schedule, 'wp_https_detection' ); 168 160 } 169 161 170 if ( ! wp_next_scheduled( 'wp_https_detection' ) ) { 171 wp_schedule_event( time(), 'twicedaily', 'wp_https_detection' ); 172 } 173 } 174 175 /** 176 * Disables SSL verification if the 'cron_request' arguments include an HTTPS URL. 177 * 178 * This prevents an issue if HTTPS breaks, where there would be a failed attempt to verify HTTPS. 179 * 180 * @since 5.7.0 181 * @access private 182 * 183 * @param array $request The cron request arguments. 184 * @return array The filtered cron request arguments. 185 */ 186 function wp_cron_conditionally_prevent_sslverify( $request ) { 187 if ( 'https' === wp_parse_url( $request['url'], PHP_URL_SCHEME ) ) { 188 $request['args']['sslverify'] = false; 189 } 190 return $request; 162 return $support_errors->errors; 191 163 } 192 164 193 165 /** -
tests/phpunit/tests/https-detection.php
diff --git tests/phpunit/tests/https-detection.php tests/phpunit/tests/https-detection.php index 820f39fc6e..6b9a4b41b5 100644
class Tests_HTTPS_Detection extends WP_UnitTestCase { 141 141 ); 142 142 } 143 143 144 /**145 * @ticket 47577146 */147 public function test_wp_schedule_https_detection() {148 wp_schedule_https_detection();149 $this->assertSame( 'twicedaily', wp_get_schedule( 'wp_https_detection' ) );150 }151 152 /**153 * @ticket 47577154 */155 public function test_wp_cron_conditionally_prevent_sslverify() {156 // If URL is not using HTTPS, don't set 'sslverify' to false.157 $request = array(158 'url' => 'http://example.com/',159 'args' => array( 'sslverify' => true ),160 );161 $this->assertSame( $request, wp_cron_conditionally_prevent_sslverify( $request ) );162 163 // If URL is using HTTPS, set 'sslverify' to false.164 $request = array(165 'url' => 'https://example.com/',166 'args' => array( 'sslverify' => true ),167 );168 $expected = $request;169 $expected['args']['sslverify'] = false;170 $this->assertSame( $expected, wp_cron_conditionally_prevent_sslverify( $request ) );171 }172 173 144 /** 174 145 * @ticket 47577 175 146 * @ticket 52542