douzaoqu4447 2015-11-13 20:37
浏览 51
已采纳

Wordpress:功能自定义帖子类型delete_post不起作用

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条回答 默认 最新

  • drvxclagw656708070 2015-11-14 22:29
    关注

    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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试