您也可以像尝试那样以编程方式执行此操作,但是您必须授予更多角色才能使其工作。
我通过查询 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 中添加 FULL 功能。
要检查您是否不需要其他角色,请将这些与授予商店经理角色的功能进行比较,如下所示:
$role = get_role("shop_manager");
print_r($role->capabilities);