wppaste
WordPress

wp_get_https_detection_errors(): array

Since
6.4.0
Source
wp-includes/https-detection.php:94
Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.

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

Reaches an outbound HTTP request via wp_remote_request().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
11–73

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 90.

Plugin surface
1 hook

Third-party callbacks on 'pre_wp_get_https_detection_errors' run inside this call, and their cost is not bounded by anything here.

Called by
3

3 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksapply_filters()called directly
  • httpoutbound HTTP requestwp_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.

WhenInstructionsCalls it makes
is_wp_error()11apply_filters(), is_wp_error()
always31apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), is_wp_error()
!is_wp_error()44apply_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()44apply_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()51apply_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()
always52–53apply_filters(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), home_url(), wp_remote_request(), is_wp_error(), __(), ->add(), is_wp_error()
always65–66apply_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()
always65–66apply_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()
always72–73apply_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:

  1. 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

Used by · 3

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.8
Return type changed from none to array.verified against source
6.4.0
Introduced.from the docblock

About 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.