wp_is_https_supported()WP 5.7.0

Checks whether HTTPS is supported for the server and domain.

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

No Hooks.

Return

true|false. True if HTTPS is supported, false otherwise.

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

function wp_is_https_supported() {
	$https_detection_errors = get_option( 'https_detection_errors' );

	// If option has never been set by the Cron hook before, run it on-the-fly as fallback.
	if ( false === $https_detection_errors ) {
		wp_update_https_detection_errors();

		$https_detection_errors = get_option( 'https_detection_errors' );
	}

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