Wordpress:功能自定义 Post 类型 delete_post 不工作

Wordpress: Capabilities Custom Post type delete_post is not working

我在 wordpress 中使用自定义 Post 类型和 "Members" 插件。

我的问题是,在我的自定义 post 类型中,我无法删除 posts,移动到垃圾箱的 link 不存在 :(

这是我的代码:

'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_entrada_tallers_activitats_grups"(delete_post)也许这就是问题所在,但我不知道如何解决它....

更新完整代码

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