[英]Hide fields based on user role
How can I hide fields using CSS for specific users?如何使用 CSS 为特定用户隐藏字段?
Something like this:像这样的东西:
if( $role == 'subscriber' ) { ?>
<style type="text/css">
.user-area .user-profile-dropdown{
display: none !important;
}
</style>
I used this code and it did not work:我使用了这段代码,但它不起作用:
function hide_fields_nonusers(){
if( $role == 'subscriber' ) { ?>
<style type="text/css">
.user-area .user-profile-dropdown{
display: none !important;
}
</style>
}
add_action('admin_head', 'hide_fields_nonusers');
You are missing closing the HTML output:您缺少关闭 HTML 输出:
function hide_fields_nonusers(){
if( $role == 'subscriber' ) { ?>
<style type="text/css">
.user-area .user-profile-dropdown{
display: none !important;
}
</style>
<?php }
Figured it out:弄清楚了:
if( current_user_can('subscriber')) {
?>
<style type="text/css">
.user-area .user-profile-dropdown{
display: none !important;
}
</style>
<?php
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.