Wordpress:如果用户角色 = CSS-Class THEN 显示:无

标签 wordpress

对于具有用户特定内容的客户项目,我有一个(希望是小的)问题。我需要一个将 ".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/

相关文章:

html - 子菜单中的三 Angular 形与主菜单项重叠

php - 在 WordPress 中有多个获奖者的奖励

mysql - ORDER BY date ASC 将没有日期的记录放在有日期的记录之前?

php - 删除 protected wordpress 页面标题 h1 中的 "Protected"文本

mysql - Wordpress 用户和用户元 - 将一个表中的多行连接到另一个表中的一行

php - wordpress 视频不适用于移动设备

html - Wordpress CSS主题修改

phpMyAdmin 删除影响多个数据库的查询

jquery - 如何将加载微调器添加到 WooCommerce 结帐页面

css - 显示的是 CSS 代码,而不是标题框。我如何解决它?