函数文档

wp_is_https_supported()

💡 云策文档标注

概述

wp_is_https_supported() 函数用于检查服务器和域名是否支持 HTTPS。它通过 wp_get_https_detection_errors() 执行 HTTP 请求来检测,但需注意其资源消耗,避免在性能敏感环境中使用。

关键要点

  • 函数返回布尔值:true 表示支持 HTTPS,false 表示不支持。
  • 内部调用 wp_get_https_detection_errors() 进行远程 HTTPS 请求检测,并基于错误数组判断支持状态。
  • 由于检测过程可能消耗资源,建议谨慎使用,特别是在性能敏感场景中,以避免潜在延迟问题。
  • 该函数自 WordPress 5.7.0 版本引入。

代码示例

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 );
}

注意事项

  • 此函数依赖于 wp_get_https_detection_errors(),后者执行远程请求,可能影响性能。
  • 在需要频繁调用的环境中,应考虑缓存结果或优化使用方式。

📄 原文内容

Checks whether HTTPS is supported for the server and domain.

Description

This function makes an HTTP request through wp_get_https_detection_errors() to check for HTTPS support. As this process can be resource-intensive, it should be used cautiously, especially in performance-sensitive environments, to avoid potential latency issues.

Return

bool True if HTTPS is supported, false otherwise.

Source

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 );
}

Changelog

Version Description
5.7.0 Introduced.