wp_get_https_detection_errors(): array
- Since
- 6.4.0
- Source
wp-includes/https-detection.php:94
Description
This function checks for HTTPS support by making an HTTP request. As this process can be resource-intensive, it should be used cautiously, especially in performance-sensitive environments.
It is called when HTTPS support needs to be validated.
Compatibility
- WordPress
- since 6.4.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Return value
array- An array containing potential detection errors related to HTTPS, or an empty array if no errors are found.
Performance profile
How much work a call to wp_get_https_detection_errors() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Expensive
- Scaling
- Constant
- Instructions
- 11–73
- Plugin surface
- 1 hook
- Called by
- 3
Reaches an outbound HTTP request via wp_remote_request().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 90.
Third-party callbacks on 'pre_wp_get_https_detection_errors' run inside this call, and their cost is not bounded by anything here.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - httpoutbound HTTP request
wp_remote_request()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 9 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_get_https_detection_errors() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
is_wp_error() | 11 | apply_filters(), is_wp_error() |
| always | 31 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), is_wp_error() |
!is_wp_error() | 44 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), wp_is_local_html_output() |
!is_wp_error() | 44 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_message(), ->add() |
!is_wp_error() | 51 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), wp_is_local_html_output(), __(), ->add() |
| always | 52–53 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), __(), ->add(), is_wp_error() |
| always | 65–66 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), __(), ->add(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), wp_is_local_html_output() |
| always | 65–66 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), __(), ->add(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_response_message(), ->add() |
| always | 72–73 | apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), __(), ->add(), is_wp_error(), wp_remote_retrieve_response_code(), wp_remote_retrieve_body(), wp_is_local_html_output(), __(), ->add() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 90 instructions, 11–73 executed per call, 6 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_get_https_detection_errors() runs, in this order:
- apply_filters( pre_wp_get_https_detection_errors )filterline 106 (+12 into the body)
Short-circuits the process of detecting errors related to HTTPS support.
Uses · 10
- apply_filters()Calls the callback functions that have been added to a filter hook.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- wp_remote_request()Performs an HTTP request and returns its response.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- __()Retrieves the translation of $text.
- wp_remote_retrieve_response_code()Retrieves only the response code from the raw response.
- wp_remote_retrieve_response_message()Retrieves only the response message from the raw response.
- wp_is_local_html_output()Checks whether a given HTML string is likely an output from this WordPress site.
- wp_remote_retrieve_body()Retrieves only the body from the raw response.
- WP_Error::__construct()Initializes the error.
Used by · 3
- WP_Site_Health::get_test_https_status()Tests if the site is serving content over HTTPS.
- wp_is_https_supported()Checks whether HTTPS is supported for the server and domain.
- wp_update_https_detection_errors()Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.
Source code
function wp_get_https_detection_errors() { /** * Short-circuits the process of detecting errors related to HTTPS support. * * Returning a `WP_Error` from the filter will effectively short-circuit the default logic of trying a remote * request to the site over HTTPS, storing the errors array from the returned `WP_Error` instead. * * @since 6.4.0 * * @param null|WP_Error $pre Error object to short-circuit detection, * or null to continue with the default behavior. */ $support_errors = apply_filters( 'pre_wp_get_https_detection_errors', null ); if ( is_wp_error( $support_errors ) ) { return $support_errors->errors; } $support_errors = new WP_Error(); $response = wp_remote_request( home_url( '/', 'https' ), array( 'headers' => array( 'Cache-Control' => 'no-cache', ), 'sslverify' => true, ) ); if ( is_wp_error( $response ) ) { $unverified_response = wp_remote_request( home_url( '/', 'https' ), array( 'headers' => array( 'Cache-Control' => 'no-cache', ), 'sslverify' => false, ) ); if ( is_wp_error( $unverified_response ) ) { $support_errors->add( 'https_request_failed', __( 'HTTPS request failed.' ) ); } else { $support_errors->add( 'ssl_verification_failed', __( 'SSL verification failed.' ) ); } $response = $unverified_response; } if ( ! is_wp_error( $response ) ) { if ( 200 !== wp_remote_retrieve_response_code( $response ) ) { $support_errors->add( 'bad_response_code', wp_remote_retrieve_response_message( $response ) ); } elseif ( false === wp_is_local_html_output( wp_remote_retrieve_body( $response ) ) ) { $support_errors->add( 'bad_response_source', __( 'It looks like the response did not come from this site.' ) ); } } return $support_errors->errors;}Changelog
Introduced in 6.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
none to array.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/https-detection.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.