Remove Custom Capability

时间:2016-03-14 作者:subhashuyadav

我已经创建了一个自定义帖子类型“book”。所有书籍帖子类型都是公共的,因此我想删除一些功能,如“delete\\u private\\u books”、“read\\u private\\u books”等。我如何实现这一点,因为当我激活成员插件时,它会显示所有默认功能,包括上述与我的自定义帖子类型无关的功能。

我已经注册了我的post type book并为其添加了功能。

$labels = array(
  \'name\'               => _x( \'Books\', \'post type general name\' ),
  \'singular_name\'      => _x( \'Book\', \'post type singular name\' ),
  \'menu_name\'          => _x( \'Book\', \'admin menu\' ),
  \'name_admin_bar\'     => _x( \'Book\', \'add new on admin bar\' ),
  \'add_new\'            => _x( \'Add New\', \'Book\' ),
  \'add_new_item\'       => __( \'Add New Book\' ),
  \'new_item\'           => __( \'New Books\' ),
  \'edit_item\'          => __( \'Edit Books\' ),
  \'view_item\'          => __( \'View Books\' ),
  \'all_items\'          => __( \'Books\' ),
  \'search_items\'       => __( \'Search Books\' ),
  \'parent_item_colon\'  => __( \'Parent text:\' ),
  \'not_found\'          => __( \'No Books found.\' ),
  \'not_found_in_trash\' => __( \'No Books found in Trash.\' )
);

$capabilities = array(
  \'edit_post\'              => \'edit_books\',
  \'read_post\'              => \'read_books\',
  \'delete_post\'            => \'delete_books\',
  \'edit_posts\'             => \'edit_books\',
  \'edit_others_posts\'      => \'edit_others_books\',
  \'publish_posts\'          => \'publish_books\',
  \'read_private_posts\'     => \'read_private_books\',
  \'create_posts\'           => \'edit_books\',
  \'delete_posts\'           => \'delete_books\',
  \'delete_private_posts\'   => \'delete_private_books\',
  \'delete_published_posts\' => \'delete_published_books\',
  \'delete_others_posts\'    => \'delete_others_books\',
  \'edit_private_posts\'     => \'edit_private_books\',
  \'edit_published_posts\'   => \'edit_published_books\',
);
$args = array(
  \'labels\'             => $labels,
  \'public\'             => true,
  \'publicly_queryable\' => true,
  \'show_ui\'            => true,
  \'show_in_menu\'       => false,
  \'query_var\'          => true,
  \'rewrite\'            => array(\'slug\' => \'books\'),
  \'capability_type\'    => \'books\',
  \'has_archive\'        => true,
  \'hierarchical\'       => false,
  \'menu_position\'      => \'\',
  \'supports\'           => false,
  \'map_meta_cap\'       => null,
  \'capabilities\'       => $capabilities,
);

register_post_type( \'wp-type-books\', $args );

1 个回复
SO网友:sMyles

那么,为什么要设置这些自定义功能呢?您正在使用自定义功能注册您的CPT,我注意到的第一件事是您仍然具有capability_type 设置

\'capability_type\'    => \'books\',
如果计划使用自定义功能,则应从数组中省略任何内容,或者至少是一个空字符串(只有在未设置功能的情况下,才会将其用作回退)

\'capability_type\' => \'\',
关于自定义功能。。。确保您的成员插件设置正确。使用自定义功能时,您需要将这些功能添加到特定的用户角色中,以便支持它们。。。所以你说members插件会自动做到这一点,或者说你配置不正确,或者不了解功能和用户角色是如何工作的

我强烈建议您阅读并重新阅读有关自定义帖子类型和功能的文档:

https://codex.wordpress.org/Function_Reference/register_post_type#capabilities

相关推荐

Capabilities Not Changing

我希望编辑器能够列出、添加和编辑用户。我认为下面的代码可以做到这一点,但它不起作用-没有为任何编辑器显示新的用户菜单。我错过什么了吗?function increase_editor_role(){ $role = get_role(\'editor\'); $role->add_cap(\'list_users\'); $role->add_cap(\'edit_users\'); $role->add_cap(\'c