我已经创建了一个自定义帖子类型,并在WordPress后端添加了自定义字段,如屏幕截图中所示
但是现在当我尝试删除此自定义字段时,会收到此警告
You do not have permission to do that.
我有点困惑,为什么出现这个警告,因为我已经使用管理员帐户登录了。
我开发了一个用于创建自定义帖子类型的插件,代码是
public function charities_register_plugin() {
$labels = array(
'name' => _x('Charities', 'charities'),
'singular_name' => _x('Charity', 'charities'),
'add_new' => _x('Add New', 'charities'),
'add_new_item' => _x('Add New Charity', 'charities'),
'edit_item' => _x('Edit Charity', 'charities'),
'new_item' => _x('New Charity', 'charities'),
'view_item' => _x('View Charity', 'charities'),
'search_items' => _x('Search Charity', 'charities'),
'not_found' => _x('No charities found', 'charities'),
'not_found_in_trash' => _x('No charities found in Trash', 'charities'),
'parent_item_colon' => _x('Parent Charity:', 'charities'),
'menu_name' => _x('Charities', 'charities'),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Allow Admin to create charities',
'supports' => array('title', 'editor', 'revisions','custom-fields'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'exclude_from_search' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array("slug" => "mycharities",'with_front'=>FALSE)
);
register_post_type('charities', $args);
}
使用
触发它 add_action('init', array($this, 'charities_register_plugin'));
非常感谢任何帮助。
答案 0 :(得分:0)
在你的args中使用以下代码,如果你的问题得到解决,请告诉我:
$args = array(
'labels' => $labels,
'capability_type' => 'charities',
'capabilities' => array(
'publish_posts' => 'publish_charities',
'edit_posts' => 'edit_charities',
'edit_others_posts' => 'edit_others_charities',
'delete_posts' => 'delete_charities',
'delete_others_posts' => 'delete_others_charities',
'read_private_posts' => 'read_private_charities',
'edit_post' => 'edit_charities',
'delete_post' => 'delete_charities',
'read_post' => 'read_charities',
),
'hierarchical' => true,
'description' => 'Allow Admin to create charities',
'supports' => array('title', 'editor', 'revisions','custom-fields'),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'exclude_from_search' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array("slug" => "mycharities",'with_front'=>FALSE)
);