force_ssl_admin()
云策文档标注
概述
force_ssl_admin() 函数用于确定是否强制在 WordPress 管理界面使用 SSL。它依赖于 wp-config.php 中定义的 FORCE_SSL_ADMIN 常量,并可通过参数临时改变返回值。
关键要点
- 函数功能:检查或设置是否强制在管理屏幕使用 SSL,基于 FORCE_SSL_ADMIN 常量。
- 参数:$force 可选,为布尔值或 null,用于临时改变返回值,默认 null 表示不改变。
- 返回值:布尔值,true 表示强制 SSL,false 表示不强制。
- 依赖关系:主要依赖于 wp-config.php 中的 FORCE_SSL_ADMIN 常量定义。
- 相关函数:与 force_ssl_login()、wp_ssl_constants() 等 SSL 相关函数关联。
代码示例
function force_ssl_admin( $force = null ) {
static $forced = false;
if ( ! is_null( $force ) ) {
$old_forced = $forced;
$forced = (bool) $force;
return $old_forced;
}
return $forced;
}注意事项
- 参数 $force 可以临时改变函数返回值,直到重置;默认行为基于 FORCE_SSL_ADMIN 常量。
- 此函数自 WordPress 2.6.0 版本引入,用于管理界面 SSL 强制控制。
原文内容
Determines whether to force SSL used for the Administration Screens.
Parameters
$forcestring|bool|nulloptional-
Whether to force SSL in admin screens.
Default:
null
Source
function force_ssl_admin( $force = null ) {
static $forced = false;
if ( ! is_null( $force ) ) {
$old_forced = $forced;
$forced = (bool) $force;
return $old_forced;
}
return $forced;
}
Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |
Skip to note 4 content
Codex
Default Usage
Skip to note 5 content
Codex
Changing the Return Value
Skip to note 6 content
Codex
Resetting the Return Value