函数文档

wp_get_direct_update_https_url()

💡 云策文档标注

概述

wp_get_direct_update_https_url() 函数用于获取直接更新站点以使用 HTTPS 的 URL。该 URL 仅在特定条件下返回,允许主机引导用户到更新页面。

关键要点

  • 函数返回直接更新到 HTTPS 的 URL 字符串,若无则返回空字符串。
  • URL 的获取依赖于环境变量 WP_DIRECT_UPDATE_HTTPS_URL 或通过 'wp_direct_update_https_url' 过滤器进行自定义。
  • 此功能主要用于主机环境,便于用户快速切换到 HTTPS。

代码示例

function wp_get_direct_update_https_url() {
    $direct_update_url = '';

    if ( false !== getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' ) ) {
        $direct_update_url = getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' );
    }

    /**
     * Filters the URL for directly updating the PHP version the site is running on from the host.
     *
     * @since 5.7.0
     *
     * @param string $direct_update_url URL for directly updating PHP.
     */
    $direct_update_url = apply_filters( 'wp_direct_update_https_url', $direct_update_url );

    return $direct_update_url;
}

注意事项

  • 函数自 WordPress 5.7.0 版本引入。
  • 过滤器 'wp_direct_update_https_url' 允许开发者修改返回的 URL,但文档中描述可能不准确,实际用于 HTTPS 更新而非 PHP 版本更新。
  • 在 WP_Site_Health::get_test_https_status() 中使用,用于检查站点是否通过 HTTPS 提供内容。

📄 原文内容

Gets the URL for directly updating the site to use HTTPS.

Description

A URL will only be returned if the WP_DIRECT_UPDATE_HTTPS_URL environment variable is specified or by using the ‘wp_direct_update_https_url’ filter. This allows hosts to send users directly to the page where they can update their site to use HTTPS.

Return

string URL for directly updating to HTTPS or empty string.

Source

function wp_get_direct_update_https_url() {
	$direct_update_url = '';

	if ( false !== getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' ) ) {
		$direct_update_url = getenv( 'WP_DIRECT_UPDATE_HTTPS_URL' );
	}

	/**
	 * Filters the URL for directly updating the PHP version the site is running on from the host.
	 *
	 * @since 5.7.0
	 *
	 * @param string $direct_update_url URL for directly updating PHP.
	 */
	$direct_update_url = apply_filters( 'wp_direct_update_https_url', $direct_update_url );

	return $direct_update_url;
}

Hooks

apply_filters( ‘wp_direct_update_https_url’, string $direct_update_url )

Filters the URL for directly updating the PHP version the site is running on from the host.

Changelog

Version Description
5.7.0 Introduced.