wp_is_https_supported()WP 5.7.0

Checks if the domain and server support the HTTPS protocol.

The function makes an HTTP request (cached in the option https_detection_errors) to the main page of the site via the HTTPS protocol and checks if an error was returned. If there is no error, it means the site is working correctly with HTTPS.

1 time — 0.002646 sec (very slow) | 50000 times — 2.42 sec (fast)

No Hooks.

Returns

true|false. true, if HTTPS is supported and false, if not.

Usage

wp_is_https_supported();

Examples

0

#1 Check if our site works over HTTPS

if ( wp_is_https_supported() ) {
	// Site works correctly via secure HTTPS protocol
} 
else {
	// Site is not accessible via secure HTTPS protocol
}

Changelog

Since 5.7.0 Introduced.

wp_is_https_supported() code WP 6.9.1

function wp_is_https_supported() {
	$https_detection_errors = wp_get_https_detection_errors();

	// If there are errors, HTTPS is not supported.
	return empty( $https_detection_errors );
}