categories - How to restrict category creation to admins only while allowing editors to still pick category

Is there a hook which would enable an admin to disallow editors and authors from creating new categories for posts?Onl

Is there a hook which would enable an admin to disallow editors and authors from creating new categories for posts? Only admins should be able to create new categories. Editors & authors need to pick from what they're given.

Is there a hook which would enable an admin to disallow editors and authors from creating new categories for posts? Only admins should be able to create new categories. Editors & authors need to pick from what they're given.

Share Improve this question edited Jul 24, 2019 at 16:15 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Jul 24, 2019 at 15:54 CDToadCDToad 511 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This has to do with the capabilities tied to the current user role.

In your case you are looking for manage_categories capability.

Option 1) Install a Plugin, which enables you to edit the capabilites (Just "Members", best plugin for that in my opinion, or "user role editor".)

Option 2) WordPress has this separation already build in.

"Editors" can manage categories. "Authors" can not!

So, you only would have to give the users the "Author" role that should be enough to restrict it.

Option 3) Do it via code in your functions.php with something like:

<?php

    global $pagenow, $typenow;

    if(($pagenow === 'edit-tags.php') && $typenow === 'taxonomy') {
        if(!current_user_can('manage_categories')) {
            // Do whatever you want them to see.. redirect to home or whatever
            return false;
        }
    }

I havent' tested the code above, but that should be the direction to go.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745298411a4621284.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信