Wordpress: Capabilities Custom Post type delete_po

2019-09-01 16:11发布

I'm using Custom Post Type and "Members" plugin in wordpress.

My problem is that in my custom post type I can't delete posts, the link to move to trash is not there :(

Here is my code:

'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', 

In the Edit Capabilities page plugin it appear and I have checked the checkbox of:

  • 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)

But not "delete_entrada_tallers_activitats_grups" ( the delete_post) maybe this is the problem but I don0t know how to fix it....

UPDATE full code

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

1条回答
Bombasti
2楼-- · 2019-09-01 16:52

I have found some error in your code so I rewrite your full code.

Note: You can translate it on your on Language

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');
查看更多
登录 后发表回答