wp_get_update_https_url()
云策文档标注
概述
wp_get_update_https_url() 函数用于获取一个 URL,该 URL 提供关于如何将站点更新为使用 HTTPS 的更多信息。此 URL 可通过环境变量或过滤器进行自定义,但空字符串不被允许,将回退到默认 URL。
关键要点
- 函数返回一个字符串 URL,用于学习如何更新站点以使用 HTTPS。
- URL 可通过环境变量 WP_UPDATE_HTTPS_URL 或 'wp_update_https_url' 过滤器进行覆盖。
- 如果提供的 URL 为空字符串,函数将使用默认 URL。
- 建议链接页面本地化为站点语言。
- 函数在 WordPress 5.7.0 版本中引入。
代码示例
function wp_get_update_https_url() {
$default_url = wp_get_default_update_https_url();
$update_url = $default_url;
if ( false !== getenv( 'WP_UPDATE_HTTPS_URL' ) ) {
$update_url = getenv( 'WP_UPDATE_HTTPS_URL' );
}
/**
* Filters the URL to learn more about updating the HTTPS version the site is running on.
*
* Providing an empty string is not allowed and will result in the default URL being used. Furthermore
* the page the URL links to should preferably be localized in the site language.
*
* @since 5.7.0
*
* @param string $update_url URL to learn more about updating HTTPS.
*/
$update_url = apply_filters( 'wp_update_https_url', $update_url );
if ( empty( $update_url ) ) {
$update_url = $default_url;
}
return $update_url;
}注意事项
- 使用 'wp_update_https_url' 过滤器时,确保不返回空字符串,否则将使用默认 URL。
- 此函数主要用于站点健康检查等场景,如 WP_Site_Health::get_test_https_status()。
原文内容
Gets the URL to learn more about updating the site to use HTTPS.
Description
This URL can be overridden by specifying an environment variable WP_UPDATE_HTTPS_URL or by using the ‘wp_update_https_url’ filter. Providing an empty string is not allowed and will result in the default URL being used. Furthermore the page the URL links to should preferably be localized in the site language.
Source
function wp_get_update_https_url() {
$default_url = wp_get_default_update_https_url();
$update_url = $default_url;
if ( false !== getenv( 'WP_UPDATE_HTTPS_URL' ) ) {
$update_url = getenv( 'WP_UPDATE_HTTPS_URL' );
}
/**
* Filters the URL to learn more about updating the HTTPS version the site is running on.
*
* Providing an empty string is not allowed and will result in the default URL being used. Furthermore
* the page the URL links to should preferably be localized in the site language.
*
* @since 5.7.0
*
* @param string $update_url URL to learn more about updating HTTPS.
*/
$update_url = apply_filters( 'wp_update_https_url', $update_url );
if ( empty( $update_url ) ) {
$update_url = $default_url;
}
return $update_url;
}
Hooks
- apply_filters( ‘wp_update_https_url’, string $update_url )
-
Filters the URL to learn more about updating the HTTPS version the site is running on.
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |