最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

user roles - allow edit of custom post type but not regular posts?

programmeradmin2浏览0评论

Is it possible to set the capabilities of a role to allow editing of a custom content type but not editing of the regular post types? If so, how would I go about doing that? Thanks!

Is it possible to set the capabilities of a role to allow editing of a custom content type but not editing of the regular post types? If so, how would I go about doing that? Thanks!

Share Improve this question asked Jan 3, 2014 at 18:22 Trey EckelsTrey Eckels 1311 silver badge5 bronze badges 2
  • For all users or for a specific user or role? – Brad Dalton Commented Jan 3, 2014 at 18:25
  • Hi Brad, for a role. – Trey Eckels Commented Jan 3, 2014 at 18:32
Add a comment  | 

2 Answers 2

Reset to default 0

You could install one of many plugins like this to restrict access for different user roles http://wordpress/plugins/advanced-access-manager/

Or you could remove the admin menu links to any items you want for a specific user using PHP code.

This worked for me - with no plugins. User that is allowed to edit/add only posts from custom type 'job':

add_action( 'current_screen', 'jobs_block_edit' );
function jobs_block_edit() {
    global $current_screen;

    $restricted = current_user_can('job_user') && (
            ($current_screen->base=='edit' && $current_screen->id!='edit-job') || 
            ($current_screen->base=='post' && $current_screen->id!='job')
        );

    if ($restricted) {
        exit( wp_redirect( home_url( '/' ) ) );
    }
}
发布评论

评论列表(0)

  1. 暂无评论