WordPress:在“添加新页面”上从“用户角色”隐藏特定类别 [英] Wordpress: Hide specific categories from User Role on the Add New page

查看:73
本文介绍了WordPress:在“添加新页面”上从“用户角色”隐藏特定类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说的那样

如何在添加新帖子页面上的Wordpress中隐藏指定用户角色中的特定类别?这样,具有特定角色的用户就看不到隐藏的类别(因此也就不会在其中张贴内容。)

How can i hide specific categories from specified User Roles in Wordpress on the Add New Post page? So that users of a specific role cannot see the hidden categories (therefore, not post in them either).

我以前是通过插件执行此操作的,但是他们没有更新几年来,我似乎找不到替代品。

I used to do this via a plugin but they havnt been updated in years and i dont seem able to find a replacement. So any help would be appreciated.

干杯

推荐答案

已转换答案

将此代码应用于您自己的代码,应该可以使用。

Apply this code to your own and should work.

add_filter('list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2);

function yoursite_list_terms_exclusions( $exclusions, $args ) {

    global $pagenow;
    if (in_array($pagenow,array('post.php','post-new.php')) && !current_user_can('see_special_cats')) {
        $exclusions = " {$exclusions} AND t.slug NOT IN ('slug-one','slug-two')";
    }
    return $exclusions;
}

see_special_cats => WordPress管理员中的用户级别(管理员,作者等)。 ..)

see_special_cats => the level of user in WordPress admin (admin, author etc...)

有关WordPress中用户级别的更多信息

这篇关于WordPress:在“添加新页面”上从“用户角色”隐藏特定类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆