Wordpress: Hide specific categories from User Role on the Add New page

你离开我真会死。 提交于 2019-12-11 07:35:51

问题


Just as title says really;

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.

Cheers


回答1:


Answer converted to comment.

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 => the level of user in WordPress admin (admin, author etc...)

More info about users levels in WordPress



来源:https://stackoverflow.com/questions/45405507/wordpress-hide-specific-categories-from-user-role-on-the-add-new-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!