我有一个自定义帖子类型,我想限制对某些角色的访问,但是,我已经使用该自定义帖子类型添加了内容,现在必须对其进行限制。capability_type是“ post”
'capability_type' => 'post'
但是,当内容显示在后端时,哪个很好,但是现在,一旦添加任何功能,内容就会从后端消失?
我尝试自定义功能类型以包括复数定义来构造自己的功能类型,但是一旦删除或更改功能类型,它就消失了!
完整代码:
add_action( 'init', 'register_cpt_gallery' );
function register_cpt_gallery() {
$labels = array(
'name' => _x( 'Galleries', 'gallery' ),
'singular_name' => _x( 'Gallery', 'gallery' ),
'add_new' => _x( 'Add New', 'gallery' ),
'add_new_item' => _x( 'Add New Gallery', 'gallery' ),
'edit_item' => _x( 'Edit Gallery', 'gallery' ),
'new_item' => _x( 'New Gallery', 'gallery' ),
'view_item' => _x( 'View Gallery', 'gallery' ),
'search_items' => _x( 'Search Galleries', 'gallery' ),
'not_found' => _x( 'No galleries found', 'gallery' ),
'not_found_in_trash' => _x( 'No galleries found in Trash', 'gallery' ),
'parent_item_colon' => _x( 'Parent Gallery:', 'gallery' ),
'menu_name' => _x( 'Galleries', 'gallery' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Image galleries for teachers classes',
'supports' => array( 'title', 'editor', 'author'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => get_bloginfo('template_url') . '/images/imagegallery.png',
'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' => 'post',
'capabilities' => array(
'edit_post' => 'edit_gallery',
'edit_posts' => 'edit_galleries',
'edit_others_posts' => 'edit_other_galleries',
'publish_posts' => 'publish_galleries',
'read_post' => 'read_gallery',
'read_private_posts' => 'read_private_galleries',
'delete_post' => 'delete_gallery'
)
);
register_post_type( 'gallery', $args );
}
我还用一种全新的自定义帖子类型测试了这一点,无论功能类型如何,我都会遇到相同的问题,例如即使删除它并添加我的自定义帖子也是如此:
'capability_type' => array('movie','movies');
add_theme_caps()
应该只调用一次,而不是每次加载管理页面时调用。最好将其switch_theme
用作主题激活或register_activation_hook
插件激活的挂钩。