_get_admin_bar_pref()
云策文档标注
概述
_get_admin_bar_pref() 函数用于获取用户的管理栏显示偏好设置,返回布尔值指示是否应显示管理栏。
关键要点
- 函数参数:$context(必需,默认为 'front','admin' 偏好已不再使用),$user(可选,默认为 0 表示当前用户)
- 返回值:布尔值,表示管理栏是否应显示给该用户
- 内部实现:通过 get_user_option() 获取用户选项,若未设置则默认返回 true
- 相关函数:被 is_admin_bar_showing() 调用以确定管理栏显示状态
- 版本历史:自 WordPress 3.1.0 引入
代码示例
function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
$pref = get_user_option( "show_admin_bar_{$context}", $user );
if ( false === $pref ) {
return true;
}
return 'true' === $pref;
}
原文内容
Retrieves the admin bar display preference of a user.
Parameters
$contextstringrequired-
Context of this preference check. Defaults to
'front'. The'admin'preference is no longer used. $userintoptional-
ID of the user to check, defaults to 0 for current user.
Source
function _get_admin_bar_pref( $context = 'front', $user = 0 ) {
$pref = get_user_option( "show_admin_bar_{$context}", $user );
if ( false === $pref ) {
return true;
}
return 'true' === $pref;
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |