函数文档

wp_update_https_detection_errors()

💡 云策文档标注

概述

wp_update_https_detection_errors() 是一个已弃用的内部函数,用于通过远程 HTTPS 请求检测站点是否支持 HTTPS,并将潜在错误存储到 WordPress 选项中。该函数在 6.4.0 版本中被废弃,由 wp_get_https_detection_errors() 替代。

关键要点

  • 函数已弃用:自 WordPress 6.4.0 起,wp_update_https_detection_errors() 被标记为废弃,不再使用,推荐使用 wp_get_https_detection_errors()。
  • 功能作用:执行远程 HTTPS 请求来检测 HTTPS 支持,并将错误信息存储到 https_detection_errors 选项。
  • 钩子使用:包含 pre_wp_update_https_detection_errors 过滤器,可用于短路默认检测逻辑,直接返回 WP_Error 对象。
  • 相关函数:涉及 wp_get_https_detection_errors()、_deprecated_function()、apply_filters()、update_option() 和 is_wp_error() 等核心函数。

代码示例

function wp_update_https_detection_errors() {
	_deprecated_function( __FUNCTION__, '6.4.0' );

	$support_errors = apply_filters( 'pre_wp_update_https_detection_errors', null );
	if ( is_wp_error( $support_errors ) ) {
		update_option( 'https_detection_errors', $support_errors->errors, false );
		return;
	}

	$support_errors = wp_get_https_detection_errors();
	update_option( 'https_detection_errors', $support_errors );
}

注意事项

  • 该函数原由定期 Cron 钩子调用,用于更新 https_detection_errors 选项,但自 6.4.0 起,错误检测逻辑已移至 Site Health 中直接处理,不再需要此函数。
  • 开发者应避免在新代码中使用此函数,并更新现有代码以使用 wp_get_https_detection_errors() 替代。

📄 原文内容

Runs a remote HTTPS request to detect whether HTTPS supported, and stores potential errors.

Description

This internal function is called by a regular Cron hook to ensure HTTPS support is detected and maintained.

Source

function wp_update_https_detection_errors() {
	_deprecated_function( __FUNCTION__, '6.4.0' );

	/**
	 * 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 5.7.0
	 * @deprecated 6.4.0 The `wp_update_https_detection_errors` filter is no longer used and has been replaced by `pre_wp_get_https_detection_errors`.
	 *
	 * @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_update_https_detection_errors', null );
	if ( is_wp_error( $support_errors ) ) {
		update_option( 'https_detection_errors', $support_errors->errors, false );
		return;
	}

	$support_errors = wp_get_https_detection_errors();

	update_option( 'https_detection_errors', $support_errors );
}

Hooks

apply_filters( ‘pre_wp_update_https_detection_errors’, null|WP_Error $pre )

Short-circuits the process of detecting errors related to HTTPS support.

Changelog

Version Description
6.4.0 Deprecated. The wp_update_https_detection_errors() function is no longer used and has been replaced by wp_get_https_detection_errors(). Previously the function was called by a regular Cron hook to update the https_detection_errors option, but this is no longer necessary as the errors are retrieved directly in Site Health and no longer used outside of Site Health.
5.7.0 Introduced.