WordPress自定义帖子类型功能,管理员无法编辑帖子类型 [英] Wordpress custom post type capabilities, admin can't edit post type

查看:96
本文介绍了WordPress自定义帖子类型功能,管理员无法编辑帖子类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WordPress中遇到有线问题。下面是我的事件发布类型的代码,它没有功能就可以工作,但是添加功能后,所有默认角色(管理员,编辑者等)都不能使用发布类型。管理员角色只能看到自定义分类法。

I'm having a wired problem with WordPress. Below is my code for an events post type, it works without the capabilities but when the capabilities are added all the default roles (admin, editor, etc...) cant use the post type. The admin role is only able to see the custom taxonomies.

我有一个自定义用户角色,其 edit_events => true表示可以提交事件的用户角色进行审查。这就是我想要的,但是内置角色看不到帖子类型!

I have a custom user role with "edit_events => true" for the user role that is able to submit events for review. This is what I want, but the built in roles can't see the post type!

我已经尝试了几乎所有可以找到的功能教程,它们似乎都几乎是相同的,我无法理解它们与我的代码有何不同。

I've tried just about every capabilities tutorial I could find, they all seem to be pretty much the same and I can't how any of them differ from my code.

function register_custom_event_type() {
$labels = array(
    'name' => _x('Events', 'event'),
    'singular_name' => _x('Event', 'event'),
    'add_new' => _x('Add New', 'event'),
    'add_new_item' => _x('Add New Event', 'event'),
    'edit_item' => _x('Edit Event', 'event'),
    'new_item' => _x('New Event', 'event'),
    'view_item' => _x('View Event', 'event'),
    'search_items' => _x('Search Events', 'event'),
    'not_found' => _x('No events found', 'event'),
    'not_found_in_trash' => _x('No events found in Trash', 'event'),
    'parent_item_colon' => _x('Parent Event:', 'event'),
    'menu_name' => _x('Events', 'event'),
);

$args = array(
    'labels' => $labels,
    'hierarchical' => false,
    'supports' => array('title', 'editor', 'thumbnail', 'author'),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_in_nav_menus' => true,
    'publicly_queryable' => true,
    'exclude_from_search' => false,
    'has_archive' => true,
    'query_var' => true,
    'can_export' => true,
    'rewrite' => true,
    'capability_type' => 'event',
    'capabilities' => array(
            'read_post' => 'read_event',
            'publish_posts' => 'publish_events',
            'edit_posts' => 'edit_events',
            'edit_others_posts' => 'edit_others_events',
            'delete_posts' => 'delete_events',
            'delete_others_posts' => 'delete_others_events',
            'read_private_posts' => 'read_private_events',
            'edit_post' => 'edit_event',
            'delete_post' => 'delete_event',

        ),
    'map_meta_cap' => true
);
register_post_type('event', $args);
}
add_action('init', 'register_custom_event_type');


推荐答案

最后我找到了解决方法。

I found a work around in the end.

我认为默认的WordPress角色具有与普通帖子相同的帖子类型功能,但由于某些原因,它们却没有。

I thought the default WordPress Roles would have the same capabilities for the post type as a normal post, but for some reason they don't.

手动添加功能似乎可行。

Adding the capabilities manually seems to work.

function add_event_caps() {
  $role = get_role( 'administrator' );
  $role->add_cap( 'edit_event' ); 
  $role->add_cap( 'edit_events' ); 
  $role->add_cap( 'edit_others_events' ); 
  $role->add_cap( 'publish_events' ); 
  $role->add_cap( 'read_event' ); 
  $role->add_cap( 'read_private_events' ); 
  $role->add_cap( 'delete_event' ); 
  $role->add_cap( 'edit_published_events' );   //added
  $role->add_cap( 'delete_published_events' ); //added
}
add_action( 'admin_init', 'add_event_caps');

这篇关于WordPress自定义帖子类型功能,管理员无法编辑帖子类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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