Make WordPress Core

Ticket #58494: 58494.diff

File 58494.diff, 7.2 KB (added by adamsilverstein, 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 { 
    15601560         */
    15611561        public function get_test_https_status() {
    15621562                /*
    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.
    15651564                 */
    1566                 wp_update_https_detection_errors();
     1565                $errors = wp_get_https_detection_errors();
    15671566
    15681567                $default_update_url = wp_get_default_update_https_url();
    15691568
  • 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' ) ) { 
    388388        add_action( 'init', 'wp_cron' );
    389389}
    390390
    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 
    396391// HTTPS migration.
    397392add_action( 'update_option_home', 'wp_update_https_migration_required', 10, 2 );
    398393
  • 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, 
    53675367
    53685368        return $colors;
    53695369}
     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 */
     5384function 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() { 
    8686 *
    8787 * This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained.
    8888 *
    89  * @since 5.7.0
     89 * @since 6.4.0
    9090 * @access private
    9191 */
    92 function wp_update_https_detection_errors() {
     92function wp_get_https_detection_errors() {
    9393        /**
    9494         * Short-circuits the process of detecting errors related to HTTPS support.
    9595         *
    9696         * Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote
    9797         * request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead.
    9898         *
    99          * @since 5.7.0
     99         * @since 6.4.0
    100100         *
    101101         * @param null|WP_Error $pre Error object to short-circuit detection,
    102102         *                           or null to continue with the default behavior.
     103         * @return null|WP_Error Error object if HTTPS detection errors are found, null otherwise.
    103104         */
    104         $support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null );
     105        $support_errors = apply_filters( 'pre_wp_get_https_detection_errors', null );
    105106        if ( is_wp_error( $support_errors ) ) {
    106                 update_option( 'https_detection_errors', $support_errors->errors );
    107                 return;
     107                return $support_errors->errors;
    108108        }
    109109
    110110        $support_errors = new WP_Error();
    function wp_update_https_detection_errors() { 
    153153                }
    154154        }
    155155
    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' );
    168160        }
    169161
    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;
    191163}
    192164
    193165/**
  • 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 { 
    141141                );
    142142        }
    143143
    144         /**
    145          * @ticket 47577
    146          */
    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 47577
    154          */
    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 
    173144        /**
    174145         * @ticket 47577
    175146         * @ticket 52542