gpt4 book ai didi

php - 如何允许角色编辑器管理 wordpress 中的 woocommerce 分类法?

转载 作者:可可西里 更新时间:2023-10-31 23:04:32 27 4
gpt4 key购买 nike

我希望角色 Editor 能够访问所有 woocommerce 管理,我通过向该角色添加功能来设法做到这一点:

    $role = get_role( 'editor' );
$role->add_cap( 'manage_woocommerce_products' );
$role->add_cap( 'manage_woocommerce_taxonomies' );
$role->add_cap( 'manage_woocommerce_orders' );
$role->add_cap( 'manage_woocommerce' );
$role->add_cap( 'view_woocommerce_reports' );
$role->add_cap( 'manage_woocommerce_coupons' );

$role->add_cap( 'edit_product' );
$role->add_cap( 'read_product' );
$role->add_cap( 'delete_product' );
$role->add_cap( 'edit_products' );
$role->add_cap( 'publish_products' );
$role->add_cap( 'read_private_products' );
$role->add_cap( 'delete_products' );
$role->add_cap( 'delete_private_products' );
$role->add_cap( 'delete_published_products' );
$role->add_cap( 'edit_private_products' );
$role->add_cap( 'edit_published_products' );
$role->add_cap( 'edit_products' );

除了产品类别和标签外,一切似乎都正常,我一直在搜索但没有找到,我想必须有它的能力,但我不知道是哪一个,希望有专家能指导我一下对此。

非常感谢。

最佳答案

您也可以像您尝试的那样以编程方式执行此操作,但是您必须授予更多角色才能使其正常工作。

我通过查询 Woocommerce Shop Manager 角色并将功能与编辑器角色进行比较发现了这一点。

这是添加全部的代码(在撰写本文时):

    //add caps to editor role
$role = get_role("editor");

//for woocommerce
$role->add_cap("manage_woocommerce");
$role->add_cap("view_woocommerce_reports");
$role->add_cap("edit_product");
$role->add_cap("read_product");
$role->add_cap("delete_product");
$role->add_cap("edit_products");
$role->add_cap("edit_others_products");
$role->add_cap("publish_products");
$role->add_cap("read_private_products");
$role->add_cap("delete_products");
$role->add_cap("delete_private_products");
$role->add_cap("delete_published_products");
$role->add_cap("delete_others_products");
$role->add_cap("edit_private_products");
$role->add_cap("edit_published_products");
$role->add_cap("manage_product_terms");
$role->add_cap("edit_product_terms");
$role->add_cap("delete_product_terms");
$role->add_cap("assign_product_terms");
$role->add_cap("edit_shop_order");
$role->add_cap("read_shop_order");
$role->add_cap("delete_shop_order");
$role->add_cap("edit_shop_orders");
$role->add_cap("edit_others_shop_orders");
$role->add_cap("publish_shop_orders");
$role->add_cap("read_private_shop_orders");
$role->add_cap("delete_shop_orders");
$role->add_cap("delete_private_shop_orders");
$role->add_cap("delete_published_shop_orders");
$role->add_cap("delete_others_shop_orders");
$role->add_cap("edit_private_shop_orders");
$role->add_cap("edit_published_shop_orders");
$role->add_cap("manage_shop_order_terms");
$role->add_cap("edit_shop_order_terms");
$role->add_cap("delete_shop_order_terms");
$role->add_cap("assign_shop_order_terms");
$role->add_cap("edit_shop_coupon");
$role->add_cap("read_shop_coupon");
$role->add_cap("delete_shop_coupon");
$role->add_cap("edit_shop_coupons");
$role->add_cap("edit_others_shop_coupons");
$role->add_cap("publish_shop_coupons");
$role->add_cap("read_private_shop_coupons");
$role->add_cap("delete_shop_coupons");
$role->add_cap("delete_private_shop_coupons");
$role->add_cap("delete_published_shop_coupons");
$role->add_cap("delete_others_shop_coupons");
$role->add_cap("edit_private_shop_coupons");
$role->add_cap("edit_published_shop_coupons");
$role->add_cap("manage_shop_coupon_terms");
$role->add_cap("edit_shop_coupon_terms");
$role->add_cap("delete_shop_coupon_terms");
$role->add_cap("assign_shop_coupon_terms");
$role->add_cap("edit_shop_webhook");
$role->add_cap("read_shop_webhook");
$role->add_cap("delete_shop_webhook");
$role->add_cap("edit_shop_webhooks");
$role->add_cap("edit_others_shop_webhooks");
$role->add_cap("publish_shop_webhooks");
$role->add_cap("read_private_shop_webhooks");
$role->add_cap("delete_shop_webhooks");
$role->add_cap("delete_private_shop_webhooks");
$role->add_cap("delete_published_shop_webhooks");
$role->add_cap("delete_others_shop_webhooks");
$role->add_cap("edit_private_shop_webhooks");
$role->add_cap("edit_published_shop_webhooks");
$role->add_cap("manage_shop_webhook_terms");
$role->add_cap("edit_shop_webhook_terms");
$role->add_cap("delete_shop_webhook_terms");
$role->add_cap("assign_shop_webhook_terms");

请注意,这将为所有编辑器添加 woocommerce 中的完整功能。

要检查您是否不需要其他角色,请将这些角色与授予商店经理角色的能力进行比较,如下所示:

    $role = get_role("shop_manager");
print_r($role->capabilities);

关于php - 如何允许角色编辑器管理 wordpress 中的 woocommerce 分类法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27822458/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com