【发布时间】:2019-06-11 20:41:30
【问题描述】:
我正在尝试在 WordPress 的后台管理区域中为某个用户更改某些元素。
我发现以下代码适用于特定角色,但如何更改它以针对特定用户?
function wpa66834_role_admin_body_class( $classes ) {
global $current_user;
foreach( $current_user->roles as $role )
$classes .= ' role-' . $role;
return trim( $classes );
}
add_filter( 'admin_body_class', 'wpa66834_role_admin_body_class' );
澄清一下:而不是在foreach 部分中识别角色,然后将角色添加到类名中,我希望它通过用户的特定名称或 ID 来识别用户,然后将该名称或 ID 添加到类名。
【问题讨论】:
-
你是什么意思
how do I change it to target a specific user你如何通过 ID 识别所述用户? -
是的,对不起。我不想在“foreach”部分中识别角色,然后将角色添加到类名中,而是希望它通过用户的特定名称或 ID 来识别用户,然后将该名称或 ID 添加到类名中。