filter_SSL()
云策文档标注
概述
filter_SSL() 是一个 WordPress 函数,用于将 URL 格式化为使用 https 协议。它通常用作过滤器,根据 SSL 强制设置和当前连接状态调整 URL 方案。
关键要点
- 函数接受一个字符串参数 $url,返回使用 https 方案的 URL。
- 如果 $url 不是字符串,则返回带正确方案的站点首页 URL。
- 当 force_ssl_content() 返回 true 且当前连接为 SSL 时,使用 set_url_scheme() 将 URL 方案设置为 https。
- 函数在 WordPress 2.8.5 版本中引入。
代码示例
function filter_SSL( $url ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! is_string( $url ) ) {
return get_bloginfo( 'url' ); // Return home site URL with proper scheme.
}
if ( force_ssl_content() && is_ssl() ) {
$url = set_url_scheme( $url, 'https' );
}
return $url;
}注意事项
- 函数名 filter_SSL 不符合 WordPress 命名规范,但被忽略。
- 相关函数包括 is_ssl()、set_url_scheme()、force_ssl_content() 和 get_bloginfo(),用于 SSL 检测和 URL 处理。
原文内容
Formats a URL to use https.
Description
Useful as a filter.
Parameters
$urlstringrequired-
URL.
Source
function filter_SSL( $url ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
if ( ! is_string( $url ) ) {
return get_bloginfo( 'url' ); // Return home site URL with proper scheme.
}
if ( force_ssl_content() && is_ssl() ) {
$url = set_url_scheme( $url, 'https' );
}
return $url;
}
Changelog
| Version | Description |
|---|---|
| 2.8.5 | Introduced. |