对于具有用户特定内容的客户项目,我有一个(希望是小的)问题。我需要一个将 ".user-role { display: none !important; }"
添加到 inline-css 中的函数,以确保特定的用户角色无法看到特定的 html 对象。因此,如果用户角色是“abc-user”,则必须有 ".abc-user { display: none !important; }"
这是否可能或者是否有更好的解决方案来解决这个问题?由于该网站使用 visual composer(不幸的是),因此几乎不可能使用短代码,因为用户看不到完整的行。
期待您的回答! :)
来自德国的问候, 最大
最佳答案
尝试将此代码用于 functions.php
add_action('wp_head', 'hidingCss');
function hidingCss() {
if (is_user_logged_in()) {
$user = wp_get_current_user();
$role = (array) $user->roles;
//csss-class means user roles
if($role[0] == 'CSS-Class'){
//.abc-user is a class which you are targeting for hide any element
echo '<style>.abc-user { display: none !important; }</style>';
}
} else {
return true;
}
}
关于Wordpress:如果用户角色 = CSS-Class THEN 显示:无,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907170/