WordPress的:功能自定义帖子类型delete_post不工作
问题描述:
我在wordpress中使用自定义帖子类型和“成员”插件。WordPress的:功能自定义帖子类型delete_post不工作
我的问题是,在我的自定义后类型我无法删除帖子,移动到垃圾链接是不是有:(
这里是我的代码:
'capabilities' => array(
'edit_post' => 'edit_entrada_tallers_activitats_grups',
'read_post' => 'read_entrada_tallers_activitats_grups',
'delete_post' => 'delete_entrada_tallers_activitats_grups',
'delete_posts' => 'delete_entradas_tallers_activitats_grups',
'delete_others_posts' => 'delete_others_entradas_tallers_activitats_grups',
'delete_published_posts' => 'delete_published_entradas_tallers_activitats_grups',
'edit_posts' => 'edit_entrada_tallers_activitats_grups',
'edit_others_posts' => 'edit_others_entrada_tallers_activitats_grups',
'publish_posts' => 'publish_entrada_tallers_activitats_grups',
'read_private_posts' => 'read_private_entrada_tallers_activitats_grups',
'create_posts' => 'edit_create_entrada_tallers_activitats_grups',
在编辑功能页面插件,它似乎和我检查的复选框:
- delete_entradas_tallers_activitats_grups(delete_posts) 个
- delete_others_entradas_tallers_activitats_grups(delete_others_posts)
- delete_published_entradas_tallers_activitats_grups(delete_published_posts)
但不是 “delete_entrada_tallers_activitats_grups”(该delete_post)也许这就是问题,但我don0t知道如何解决它? 。
更新完整代码
function my_custom_post_tallers_grup() {
$labels = array(
'name' => _x('Aquí t’escoltem', 'post type general name'),
'singular_name' => _x('Taller i activitat per a grups', 'post type singular name'),
'add_new' => _x('Afegeix', 'oferta'),
'add_new_item' => __('Afegeix nova entrada'),
'edit_item' => __('Editar'),
'new_item' => __('Nova entrada'),
'all_items' => __('Totes les entrades'),
'view_item' => __('Veure entrada'),
'search_items' => __('Cercar entrades'),
'not_found' => __('No s\'ha trobat.'),
'not_found_in_trash' => __('No s\'ha trobat a la paperera'),
'parent_item_colon' => '',
'menu_name' => 'Aquí t’escoltem'
);
$args = array(
'labels' => $labels,
'description' => 'Entrades d\'aqui t'escoltem',
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'public' => true,
'query_var' => true,
'menu_position' => 3,
'rewrite' => array('slug' => 'tallers-i-activitats-per-a-grups', 'with_front' => false),
'supports' => array('title', 'editor', 'sticky', 'thumbnail'),
'has_archive' => true,
'capability_type' => 'post',
'hierarchical' => false,
'capabilities' => array(
'edit_post' => 'edit_entrada_tallers_activitats_grups',
'read_post' => 'read_entrada_tallers_activitats_grups',
'delete_post' => 'delete_entrada_tallers_activitats_grups',
'delete_posts' => 'delete_entradas_tallers_activitats_grups',
'delete_others_posts' => 'delete_others_entradas_tallers_activitats_grups',
'delete_published_posts' => 'delete_published_entradas_tallers_activitats_grups',
'edit_posts' => 'edit_entrada_tallers_activitats_grups',
'edit_others_posts' => 'edit_others_entrada_tallers_activitats_grups',
'publish_posts' => 'publish_entrada_tallers_activitats_grups',
'read_private_posts' => 'read_private_entrada_tallers_activitats_grups',
'create_posts' => 'edit_create_entrada_tallers_activitats_grups',
)
);
register_post_type('tallers_grup', $args);
register_taxonomy_for_object_type('category', 'tallers_grup');
}
add_action('init', 'my_custom_post_tallers_grup');
答
我在代码中发现了一些错误,所以我重写了完整的代码。
注意:您可以在语言
function tallers_grup_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
'name' => _x('Aquí t’escoltem', 'tallers_grup'),
'singular_name' => _x('Taller i activitat per a grups', 'tallers_grup'),
'menu_name' => __('Aquí t’escoltem', 'tallers_grup'),
'parent_item_colon' => __('Parent Aquí t’escoltem', 'tallers_grup'),
'all_items' => __('Totes les entrades', 'tallers_grup'),
'view_item' => __('Veure', 'tallers_grup'),
'add_new_item' => __('Afegeix nova entrada', 'tallers_grup'),
'add_new' => __('Afegeix', 'tallers_grup'),
'edit_item' => __('Editar', 'tallers_grup'),
'update_item' => __('Actualizar', 'tallers_grup'),
'search_items' => __('Buscar ', 'tallers_grup'),
'not_found' => __('Extraviado', 'tallers_grup'),
'not_found_in_trash' => __('No encontrado en la basura', 'tallers_grup'),
);
$capabilities = array(
'publish_posts' => 'publish_tallers_grup',
'edit_posts' => 'edit_tallers_grup',
'edit_others_posts' => 'edit_others_tallers_grup',
'delete_posts' => 'delete_tallers_grup',
'delete_others_posts' => 'delete_others_tallers_grup',
'read_private_posts' => 'read_private_tallers_grup',
'edit_post' => 'edit_tallers_grup',
'delete_post' => 'delete_tallers_grup',
'read_post' => 'read_tallers_grup',
'create_posts' => 'edit_create_tallers_grup',
);
// Set other options for Custom Post Type
$args = array(
'label' => __('Tallers grup', 'tallers_grup'),
'description' => __('Entrades d\'aqui t\'escoltem', 'tallers_grup'),
'labels' => $labels,
'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields',),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-download',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'tallers_grup',
'capabilities' => $capabilities,
);
// Registering your Custom Post Type
register_post_type('tallers_grup', $args);
}
add_action('init', 'tallers_grup_post_type', 0);
///********************** CUSTOM ROLE *****************************/
add_role('dictionary_entry_author', 'Grup de tallers de dirigents', array (
'publish_dictionary_entry' => true,
'edit_dictionary_entry' => true,
'edit_others_dictionary_entry' => true,
'delete_dictionary_entry' => true,
'delete_others_dictionary_entry' => true,
'read_private_dictionary_entry' => true,
'edit_dictionary_entry' => true,
'delete_dictionary_entry' => true,
'read_dictionary_entry' => true,
// more standard capabilities here
'read' => true,
)
);
//==============================================
add_action('init', 'create_tallers_grup_taxonomies', 0);
function create_tallers_grup_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x('Tallers Grup Categoría', 'tallers_grups'),
'singular_name' => _x('Tallers Grup Categoría', 'tallers_grups'),
'search_items' => __('Search Tallers Grup Categoría'),
'all_items' => __('Todas Tallers Grup Categoría'),
'parent_item' => __('Parent Tallers Grup Categoría'),
'parent_item_colon' => __('Parent Tallers Grup Categoría:'),
'edit_item' => __('Editar Tallers Grup Categoría'),
'update_item' => __('Actualizar Tallers Grup Categoría'),
'add_new_item' => __('Agregar nuevo Tallers Grup Categoría'),
'new_item_name' => __('Nuevo Tallers Grup Categoría'),
'menu_name' => __('Tallers Grup Categoría'),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'tallers_grups'),
);
register_taxonomy('tallers_grups', array('tallers_grup'), $args);
}
function add_tallers_grup_caps() {
$role = get_role('administrator');
$role->add_cap('edit_tallers_grup');
$role->add_cap('edit_tallers_grups');
$role->add_cap('edit_tallers_grups');
$role->add_cap('publish_tallers_grups');
$role->add_cap('read_tallers_grup');
$role->add_cap('read_private_tallers_grups');
$role->add_cap('delete_tallers_grup');
$role->add_cap('edit_published_tallers_grups');
$role->add_cap('delete_published_tallers_grups');
$role->add_cap('edit_create_tallers_grup');
$role->add_cap('edit_create_tallers_grups');
}
add_action('admin_init', 'add_tallers_grup_caps');
+0
感谢Firefog ...只是将$ capabilities数组更改为您的建议! – curosio
什么是你的自定义后类型塞在你的翻译呢? – Firefog
发布您的完整代码我将解决它 – Firefog
我更新代码;)谢谢! – curosio