Changeset 50072
- Timestamp:
- 01/29/2021 07:09:49 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-wp-site-health.php
r50041 r50072 109 109 // Don't run https test on development environments. 110 110 if ( $this->is_development_environment() ) { 111 unset( $tests[' direct']['https_status'] );111 unset( $tests['async']['https_status'] ); 112 112 } 113 113 … … 1499 1499 */ 1500 1500 public function get_test_https_status() { 1501 // Enforce fresh HTTPS detection results. This is normally invoked by using cron, but for Site Health it should 1502 // always rely on the latest results. 1503 wp_update_https_detection_errors(); 1504 1501 1505 $result = array( 1502 1506 'label' => __( 'Your website is using an active HTTPS connection' ), … … 1522 1526 1523 1527 if ( ! wp_is_using_https() ) { 1528 // If the website is not using HTTPS, provide more information about whether it is supported and how it can 1529 // be enabled. 1524 1530 $result['status'] = 'critical'; 1525 1531 $result['label'] = __( 'Your website does not use HTTPS' ); 1526 1532 1527 if ( is_ssl() ) { 1528 $result['description'] = sprintf( 1529 '<p>%s</p>', 1530 sprintf( 1531 /* translators: %s: URL to General Settings screen. */ 1532 __( 'You are accessing this website using HTTPS, but your <a href="%s">WordPress Address</a> is not set up to use HTTPS by default.' ), 1533 esc_url( admin_url( 'options-general.php' ) ) 1534 ) 1535 ); 1533 if ( wp_is_site_url_using_https() ) { 1534 if ( is_ssl() ) { 1535 $result['description'] = sprintf( 1536 '<p>%s</p>', 1537 sprintf( 1538 /* translators: %s: URL to Settings > General > Site Address. */ 1539 __( 'You are accessing this website using HTTPS, but your <a href="%s">Site Address</a> is not set up to use HTTPS by default.' ), 1540 esc_url( admin_url( 'options-general.php' ) . '#home' ) 1541 ) 1542 ); 1543 } else { 1544 $result['description'] = sprintf( 1545 '<p>%s</p>', 1546 sprintf( 1547 /* translators: %s: URL to Settings > General > Site Address. */ 1548 __( 'Your <a href="%s">Site Address</a> is not set up to use HTTPS.' ), 1549 esc_url( admin_url( 'options-general.php' ) . '#home' ) 1550 ) 1551 ); 1552 } 1536 1553 } else { 1537 $result['description'] = sprintf( 1538 '<p>%s</p>', 1539 sprintf( 1540 /* translators: %s: URL to General Settings screen. */ 1541 __( 'Your <a href="%s">WordPress Address</a> is not set up to use HTTPS.' ), 1542 esc_url( admin_url( 'options-general.php' ) ) 1543 ) 1544 ); 1554 if ( is_ssl() ) { 1555 $result['description'] = sprintf( 1556 '<p>%s</p>', 1557 sprintf( 1558 /* translators: 1: URL to Settings > General > WordPress Address, 2: URL to Settings > General > Site Address. */ 1559 __( 'You are accessing this website using HTTPS, but your <a href="%1$s">WordPress Address</a> and <a href="%2$s">Site Address</a> are not set up to use HTTPS by default.' ), 1560 esc_url( admin_url( 'options-general.php' ) . '#siteurl' ), 1561 esc_url( admin_url( 'options-general.php' ) . '#home' ) 1562 ) 1563 ); 1564 } else { 1565 $result['description'] = sprintf( 1566 '<p>%s</p>', 1567 sprintf( 1568 /* translators: 1: URL to Settings > General > WordPress Address, 2: URL to Settings > General > Site Address. */ 1569 __( 'Your <a href="%1$s">WordPress Address</a> and <a href="%2$s">Site Address</a> are not set up to use HTTPS.' ), 1570 esc_url( admin_url( 'options-general.php' ) . '#siteurl' ), 1571 esc_url( admin_url( 'options-general.php' ) . '#home' ) 1572 ) 1573 ); 1574 } 1545 1575 } 1546 1576 … … 1562 1592 ); 1563 1593 } 1594 } elseif ( ! wp_is_https_supported() ) { 1595 // If the website is using HTTPS, but HTTPS is actually not supported, inform the user about the potential 1596 // problems. 1597 $result['status'] = 'critical'; 1598 $result['label'] = __( 'There are problems with the HTTPS connection of your website' ); 1599 1600 $https_detection_errors = get_option( 'https_detection_errors' ); 1601 if ( ! empty( $https_detection_errors['ssl_verification_failed'] ) ) { 1602 $result['description'] = sprintf( 1603 '<p>%s</p>', 1604 sprintf( 1605 /* translators: %s: URL to Settings > General > WordPress Address. */ 1606 __( 'Your <a href="%s">WordPress Address</a> is set up to use HTTPS, but the SSL certificate appears to be invalid.' ), 1607 esc_url( admin_url( 'options-general.php' ) . '#siteurl' ) 1608 ) 1609 ); 1610 } else { 1611 $result['description'] = sprintf( 1612 '<p>%s</p>', 1613 sprintf( 1614 /* translators: %s: URL to Settings > General > WordPress Address. */ 1615 __( 'Your <a href="%s">WordPress Address</a> is set up to use HTTPS, but your website appears to be unavailable when using an HTTPS connection.' ), 1616 esc_url( admin_url( 'options-general.php' ) . '#siteurl' ) 1617 ) 1618 ); 1619 } 1620 $result['description'] .= sprintf( 1621 '<p>%s</p>', 1622 __( 'Talk to your web host about resolving this HTTPS issue for your website.' ) 1623 ); 1564 1624 } 1565 1625 … … 2201 2261 'test' => 'utf8mb4_support', 2202 2262 ), 2203 'https_status' => array(2204 'label' => __( 'HTTPS status' ),2205 'test' => 'https_status',2206 ),2207 2263 'ssl_support' => array( 2208 2264 'label' => __( 'Secure communication' ), … … 2248 2304 'has_rest' => true, 2249 2305 'async_direct_test' => array( WP_Site_Health::get_instance(), 'get_test_loopback_requests' ), 2306 ), 2307 'https_status' => array( 2308 'label' => __( 'HTTPS status' ), 2309 'test' => rest_url( 'wp-site-health/v1/tests/https-status' ), 2310 'has_rest' => true, 2311 'async_direct_test' => array( WP_Site_Health::get_instance(), 'get_test_https_status' ), 2250 2312 ), 2251 2313 'authorization_header' => array( … … 2615 2677 // Don't run https test on development environments. 2616 2678 if ( $this->is_development_environment() ) { 2617 unset( $tests[' direct']['https_status'] );2679 unset( $tests['async']['https_status'] ); 2618 2680 } 2619 2681 -
trunk/src/wp-includes/https-detection.php
r49909 r50072 10 10 * Checks whether the website is using HTTPS. 11 11 * 12 * This is based on whether the home and site URL are using HTTPS. 13 * 14 * @since 5.7.0 12 * This is based on whether both the home and site URL are using HTTPS. 13 * 14 * @since 5.7.0 15 * @see wp_is_home_url_using_https() 16 * @see wp_is_site_url_using_https() 15 17 * 16 18 * @return bool True if using HTTPS, false otherwise. 17 19 */ 18 20 function wp_is_using_https() { 19 if ( 'https' !== wp_parse_url( home_url(), PHP_URL_SCHEME) ) {21 if ( ! wp_is_home_url_using_https() ) { 20 22 return false; 21 23 } 22 24 25 return wp_is_site_url_using_https(); 26 } 27 28 /** 29 * Checks whether the current site URL is using HTTPS. 30 * 31 * @since 5.7.0 32 * @see home_url() 33 * 34 * @return bool True if using HTTPS, false otherwise. 35 */ 36 function wp_is_home_url_using_https() { 37 return 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ); 38 } 39 40 /** 41 * Checks whether the current site's URL where WordPress is stored is using HTTPS. 42 * 43 * This checks the URL where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are 44 * accessible. 45 * 46 * @since 5.7.0 47 * @see site_url() 48 * 49 * @return bool True if using HTTPS, false otherwise. 50 */ 51 function wp_is_site_url_using_https() { 23 52 // Use direct option access for 'siteurl' and manually run the 'site_url' 24 // filter because site_url()will adjust the scheme based on what the53 // filter because `site_url()` will adjust the scheme based on what the 25 54 // current request is using. 26 55 /** This filter is documented in wp-includes/link-template.php */ 27 56 $site_url = apply_filters( 'site_url', get_option( 'siteurl' ), '', null, null ); 28 57 29 if ( 'https' !== wp_parse_url( $site_url, PHP_URL_SCHEME ) ) { 30 return false; 31 } 32 33 return true; 58 return 'https' === wp_parse_url( $site_url, PHP_URL_SCHEME ); 34 59 } 35 60 … … 105 130 if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { 106 131 $support_errors->add( 'bad_response_code', wp_remote_retrieve_response_message( $response ) ); 107 } elseif ( false === wp_is_ owned_html_output( wp_remote_retrieve_body( $response ) ) ) {132 } elseif ( false === wp_is_local_html_output( wp_remote_retrieve_body( $response ) ) ) { 108 133 $support_errors->add( 'bad_response_source', __( 'It looks like the response did not come from this site.' ) ); 109 134 } … … 160 185 * @return bool|null True/false for whether HTML was generated by this site, null if unable to determine. 161 186 */ 162 function wp_is_ owned_html_output( $html ) {187 function wp_is_local_html_output( $html ) { 163 188 // 1. Check if HTML includes the site's Really Simple Discovery link. 164 189 if ( has_action( 'wp_head', 'rsd_link' ) ) { -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php
r49716 r50072 80 80 'permission_callback' => function () { 81 81 return $this->validate_request_permission( 'loopback_requests' ); 82 }, 83 ), 84 'schema' => array( $this, 'get_public_item_schema' ), 85 ) 86 ); 87 88 register_rest_route( 89 $this->namespace, 90 sprintf( 91 '/%s/%s', 92 $this->rest_base, 93 'https-status' 94 ), 95 array( 96 array( 97 'methods' => 'GET', 98 'callback' => array( $this, 'test_https_status' ), 99 'permission_callback' => function () { 100 return $this->validate_request_permission( 'https_status' ); 82 101 }, 83 102 ), … … 198 217 $this->load_admin_textdomain(); 199 218 return $this->site_health->get_test_loopback_requests(); 219 } 220 221 /** 222 * Checks that the site's frontend can be accessed over HTTPS. 223 * 224 * @since 5.7.0 225 * 226 * @return array 227 */ 228 public function test_https_status() { 229 $this->load_admin_textdomain(); 230 return $this->site_health->get_test_https_status(); 200 231 } 201 232 -
trunk/tests/phpunit/tests/https-detection.php
r49904 r50072 142 142 * @ticket 47577 143 143 */ 144 public function test_wp_is_ owned_html_output_via_rsd_link() {144 public function test_wp_is_local_html_output_via_rsd_link() { 145 145 // HTML includes RSD link. 146 146 $head_tag = get_echo( 'rsd_link' ); 147 147 $html = $this->get_sample_html_string( $head_tag ); 148 $this->assertTrue( wp_is_ owned_html_output( $html ) );148 $this->assertTrue( wp_is_local_html_output( $html ) ); 149 149 150 150 // HTML includes modified RSD link but same URL. 151 151 $head_tag = str_replace( ' />', '>', get_echo( 'rsd_link' ) ); 152 152 $html = $this->get_sample_html_string( $head_tag ); 153 $this->assertTrue( wp_is_ owned_html_output( $html ) );153 $this->assertTrue( wp_is_local_html_output( $html ) ); 154 154 155 155 // HTML does not include RSD link. 156 156 $html = $this->get_sample_html_string(); 157 $this->assertFalse( wp_is_ owned_html_output( $html ) );158 } 159 160 /** 161 * @ticket 47577 162 */ 163 public function test_wp_is_ owned_html_output_via_wlwmanifest_link() {157 $this->assertFalse( wp_is_local_html_output( $html ) ); 158 } 159 160 /** 161 * @ticket 47577 162 */ 163 public function test_wp_is_local_html_output_via_wlwmanifest_link() { 164 164 remove_action( 'wp_head', 'rsd_link' ); 165 165 … … 167 167 $head_tag = get_echo( 'wlwmanifest_link' ); 168 168 $html = $this->get_sample_html_string( $head_tag ); 169 $this->assertTrue( wp_is_ owned_html_output( $html ) );169 $this->assertTrue( wp_is_local_html_output( $html ) ); 170 170 171 171 // HTML includes modified WLW manifest link but same URL. 172 172 $head_tag = str_replace( ' />', '>', get_echo( 'wlwmanifest_link' ) ); 173 173 $html = $this->get_sample_html_string( $head_tag ); 174 $this->assertTrue( wp_is_ owned_html_output( $html ) );174 $this->assertTrue( wp_is_local_html_output( $html ) ); 175 175 176 176 // HTML includes WLW manifest link with alternative URL scheme. … … 178 178 $head_tag = false !== strpos( $head_tag, 'https://' ) ? str_replace( 'https://', 'http://', $head_tag ) : str_replace( 'http://', 'https://', $head_tag ); 179 179 $html = $this->get_sample_html_string( $head_tag ); 180 $this->assertTrue( wp_is_ owned_html_output( $html ) );180 $this->assertTrue( wp_is_local_html_output( $html ) ); 181 181 182 182 // HTML does not include WLW manifest link. 183 183 $html = $this->get_sample_html_string(); 184 $this->assertFalse( wp_is_ owned_html_output( $html ) );185 } 186 187 /** 188 * @ticket 47577 189 */ 190 public function test_wp_is_ owned_html_output_via_rest_link() {184 $this->assertFalse( wp_is_local_html_output( $html ) ); 185 } 186 187 /** 188 * @ticket 47577 189 */ 190 public function test_wp_is_local_html_output_via_rest_link() { 191 191 remove_action( 'wp_head', 'rsd_link' ); 192 192 remove_action( 'wp_head', 'wlwmanifest_link' ); … … 195 195 $head_tag = get_echo( 'rest_output_link_wp_head' ); 196 196 $html = $this->get_sample_html_string( $head_tag ); 197 $this->assertTrue( wp_is_ owned_html_output( $html ) );197 $this->assertTrue( wp_is_local_html_output( $html ) ); 198 198 199 199 // HTML includes modified REST API link but same URL. 200 200 $head_tag = str_replace( ' />', '>', get_echo( 'rest_output_link_wp_head' ) ); 201 201 $html = $this->get_sample_html_string( $head_tag ); 202 $this->assertTrue( wp_is_ owned_html_output( $html ) );202 $this->assertTrue( wp_is_local_html_output( $html ) ); 203 203 204 204 // HTML includes REST API link with alternative URL scheme. … … 206 206 $head_tag = false !== strpos( $head_tag, 'https://' ) ? str_replace( 'https://', 'http://', $head_tag ) : str_replace( 'http://', 'https://', $head_tag ); 207 207 $html = $this->get_sample_html_string( $head_tag ); 208 $this->assertTrue( wp_is_ owned_html_output( $html ) );208 $this->assertTrue( wp_is_local_html_output( $html ) ); 209 209 210 210 // HTML does not include REST API link. 211 211 $html = $this->get_sample_html_string(); 212 $this->assertFalse( wp_is_ owned_html_output( $html ) );213 } 214 215 /** 216 * @ticket 47577 217 */ 218 public function test_wp_is_ owned_html_output_cannot_determine() {212 $this->assertFalse( wp_is_local_html_output( $html ) ); 213 } 214 215 /** 216 * @ticket 47577 217 */ 218 public function test_wp_is_local_html_output_cannot_determine() { 219 219 remove_action( 'wp_head', 'rsd_link' ); 220 220 remove_action( 'wp_head', 'wlwmanifest_link' ); … … 223 223 // The HTML here doesn't matter because all hooks are removed. 224 224 $html = $this->get_sample_html_string(); 225 $this->assertNull( wp_is_ owned_html_output( $html ) );225 $this->assertNull( wp_is_local_html_output( $html ) ); 226 226 } 227 227 -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r50065 r50072 138 138 '/wp-site-health/v1/tests/background-updates', 139 139 '/wp-site-health/v1/tests/loopback-requests', 140 '/wp-site-health/v1/tests/https-status', 140 141 '/wp-site-health/v1/tests/dotorg-communication', 141 142 '/wp-site-health/v1/tests/authorization-header', -
trunk/tests/qunit/fixtures/wp-api-generated.js
r50065 r50072 6188 6188 { 6189 6189 "href": "http://example.org/index.php?rest_route=/wp-site-health/v1/tests/loopback-requests" 6190 } 6191 ] 6192 } 6193 }, 6194 "/wp-site-health/v1/tests/https-status": { 6195 "namespace": "wp-site-health/v1", 6196 "methods": [ 6197 "GET" 6198 ], 6199 "endpoints": [ 6200 { 6201 "methods": [ 6202 "GET" 6203 ], 6204 "args": [] 6205 } 6206 ], 6207 "_links": { 6208 "self": [ 6209 { 6210 "href": "http://example.org/index.php?rest_route=/wp-site-health/v1/tests/https-status" 6190 6211 } 6191 6212 ]
Note: See TracChangeset
for help on using the changeset viewer.