doushao1948 2018-12-03 20:03
浏览 41

产品变体没有定义“删除帖子”的功能

I've made Woocommerce product variations show up in the admin main menu as a "post type list".

add_filter('woocommerce_register_post_type_product_variation', 'my_func1');
function my_func1($arr){
$arr['public'] = true;
$arr['supports'] = array('title', 'editor', 'custom-fields');
$arr['menu_icon'] = 'dashicons-calendar-alt';
$arr['menu_name'] = 'Dates';
$arr['label'] = 'Dates';
return $arr;
}

When looking at the post-type admin page in debug mode I get:

Notice: Undefined property: stdClass::$delete_posts in /wp-admin/includes/class-wp-posts-list-table.php on line 400

If I var_dump at line 392 in class-wp-posts-list-table.php: var_dump($post_type_obj);

The result is an object without "delete_posts" defined, only "delete_post" defined.

["cap"]=> object(stdClass)#16026 (8) { 
["edit_post"]=> string(12) "edit_product" 
["read_post"]=> string(12) "read_product" 
["delete_post"]=> string(14) "delete_product" 
["edit_posts"]=> string(13) "edit_products" 
["edit_others_posts"]=> string(20) "edit_others_products" 
["publish_posts"]=> string(16) "publish_products" 
["read_private_posts"]=> string(21) "read_private_products" 
["create_posts"]=> string(13) "edit_products" }`

Is this an oversight? Why isn't this part of capability_type='product'? Where does that capability get registered? How do I register the capability of "delete_posts" to an existing post_type registered by Woocommerce core?

  • 写回答

1条回答 默认 最新

  • douan4106 2018-12-03 22:00
    关注

    Seems it helped to read the wordpress codex more thouroughly...

    You can set map_meta_capin the register hook:

    add_filter('woocommerce_register_post_type_product_variation', 'my_func1');
    function my_func1($arr){
    $arr['public'] = true;
    $arr['supports'] = array('title', 'editor', 'custom-fields');
    $arr['menu_icon'] = 'dashicons-calendar-alt';
    $arr['menu_name'] = 'Dates';
    $arr['label'] = 'Dates';
    $arr['map_meta_cap'] = true;
    return $arr;
    }
    

    This picks up the capabilites I seemed to be lacking.

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?