WordPress自定义文章类型的能力,管理员不能编辑文章类型

yws3nbqq  于 2023-01-01  发布在  WordPress
关注(0)|答案(6)|浏览(145)

我有一个与WordPress的有线问题。下面是我的代码事件后类型,它的工作没有能力,但当能力被添加所有默认角色(管理员,编辑等...)不能使用后类型。管理员角色只能看到自定义分类。
我有一个自定义的用户角色,“edit_events =〉true”的用户角色,能够提交事件进行审查。这是我想要的,但内置的角色不能看到文章类型!
我已经尝试了几乎每一个我能找到的功能教程,他们似乎都是几乎相同的,我不知道他们中的任何一个与我的代码有什么不同。

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');
anauzrmj

anauzrmj1#

最后我在附近找到了一份工作。
我以为默认的WordPress角色会有相同的能力为文章类型作为一个正常的职位,但由于某种原因,他们没有。
手动添加这些功能似乎是可行的。

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');
yyyllmsg

yyyllmsg2#

请确保包括'map_meta_cap' => true,当注册您的自定义后类型也设置正确的能力类型例如. 'capability_type' => array('event', 'events'),然后使用User Role Editor Plugin和点击权限,因为你认为适合的个人角色-完成!

cu6pst1q

cu6pst1q3#

设置'map_meta_cap' => true'capability_type' => array('event', 'events')后,您可能还需要添加以下功能:
除map_ meta_cap外,还有八个其他基本功能未在core中直接引用(),它接受前面提到的三个 meta功能,并将它们转换为一个或多个基本功能,然后必须根据上下文针对用户或角色检查这些基本功能。()。因此,仅当帖子类型在“map_ meta_cap”参数设置为true(默认值为false)的情况下注册时,才默认地分配它们。

read - Controls whether objects of this post type can be read.
delete_posts - Controls whether objects of this post type can be deleted.
delete_private_posts - Controls whether private objects can be deleted.
delete_published_posts - Controls whether published objects can be deleted.
delete_others_posts - Controls whether objects owned by other users can be can be deleted. If the post type does not support an author, then this will behave like delete_posts.
edit_private_posts - Controls whether private objects can be edited.
edit_published_posts - Controls whether published objects can be edited.
create_posts - Controls whether new objects can be created

register_post_type() Wordpress Codex

vlf7wbxs

vlf7wbxs4#

这是一个奇怪的问题。它应该工作。以下将为您工作(注意,我只是复制粘贴我的代码,所以我的一些代码爬进来)

add_action('init', 'register_custom_event_type');
function register_custom_event_type() {
  register_post_type('event',
    array(
    'labels' => array(
      'name' => _x('Event', 'Event'),
      'singular_name' => _x('Event Custom Post', 'domain'),
      'add_new' => _x('Add New', 'domain'),
      'add_new_item' => _x('Add New Event Custom Post', 'domain'),
      'edit' => _x('Edit', 'domain'),
      'edit_item' => _x('Edit Event Custom Post', 'domain'),
      'new_item' => _x('New Event Custom Post', 'domain'),
      'view' => _x('View Event Custom Post', 'domain'),
      'view_item' => _x('View Event Custom Post', 'domain'),
      'search_items' => _x('Search Event Custom Post', 'domain'),
      'not_found' => _x('No Event Custom Posts found', 'domain'),
      'not_found_in_trash' => _x('No Event Custom Posts found in Trash', 'domain')
    ),
    'public' => true,
    'hierarchical' => true,
    'has_archive' => true,
    'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
    'can_export' => true,
    'taxonomies' => array( 'category' ),
    'register_meta_box_cb' => '',
    'map_meta_cap' => 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',
     ),
  ));
}

和你的称呼有关。不知道在哪里。有时重新开始会更容易:)
祝你好运

pepwfjgg

pepwfjgg5#

有同样的问题。自定义帖子类型中的自定义capability_type,以新用户角色的用户身份登录没有问题,但管理员没有看到CPT中的文章。
安装了“用户角色编辑器”,激活,重新加载,取消激活,删除,仍然有效。

bbuxkriu

bbuxkriu6#

注册文章类型时,添加supports标记以启用如下编辑器:第一个月

相关问题