| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Classes; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
/** |
| 10 |
* Canonical role → capability matrix for the StoreEngine ecosystem. |
| 11 |
* |
| 12 |
* Single source of truth used by Role classes (so caps aren't duplicated |
| 13 |
* across `add_*_role()` methods) and by the one-shot migration that |
| 14 |
* back-fills caps onto existing role objects when the plugin updates. |
| 15 |
*/ |
| 16 |
final class Capabilities { |
| 17 |
|
| 18 |
const ROLE_SHOP_MANAGER = 'storeengine_shop_manager'; |
| 19 |
const ROLE_CUSTOMER = 'storeengine_customer'; |
| 20 |
|
| 21 |
/** |
| 22 |
* Caps granted to `storeengine_shop_manager`. |
| 23 |
*/ |
| 24 |
public static function shop_manager_caps(): array { |
| 25 |
return [ |
| 26 |
// admin gates |
| 27 |
'manage_storeengine_shop_manager', |
| 28 |
'manage_storeengine_settings', |
| 29 |
'edit_storeengine_orders', |
| 30 |
|
| 31 |
// product |
| 32 |
'edit_storeengine_product', |
| 33 |
'read_storeengine_product', |
| 34 |
'delete_storeengine_product', |
| 35 |
'delete_storeengine_products', |
| 36 |
'edit_storeengine_products', |
| 37 |
'edit_others_storeengine_products', |
| 38 |
'read_private_storeengine_products', |
| 39 |
|
| 40 |
// coupon |
| 41 |
'edit_storeengine_coupon', |
| 42 |
'read_storeengine_coupon', |
| 43 |
'delete_storeengine_coupon', |
| 44 |
'delete_storeengine_coupons', |
| 45 |
'edit_storeengine_coupons', |
| 46 |
'edit_others_storeengine_coupons', |
| 47 |
'read_private_storeengine_coupons', |
| 48 |
|
| 49 |
// membership |
| 50 |
'edit_storeengine_group', |
| 51 |
'read_storeengine_group', |
| 52 |
'delete_storeengine_group', |
| 53 |
'delete_storeengine_groups', |
| 54 |
'edit_storeengine_groups', |
| 55 |
'edit_others_storeengine_groups', |
| 56 |
'publish_storeengine_group', |
| 57 |
'publish_storeengine_groups', |
| 58 |
'read_private_storeengine_groups', |
| 59 |
|
| 60 |
// common WP |
| 61 |
'edit_post', |
| 62 |
'edit_posts', |
| 63 |
'read', |
| 64 |
'upload_files', |
| 65 |
'edit_others_posts', |
| 66 |
|
| 67 |
// order bumps |
| 68 |
'edit_se_order_bump', |
| 69 |
'read_se_order_bump', |
| 70 |
'delete_se_order_bump', |
| 71 |
'edit_se_order_bumps', |
| 72 |
'publish_se_order_bumps', |
| 73 |
'read_private_se_order_bumps', |
| 74 |
]; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Caps granted to `administrator` on top of WP defaults. |
| 79 |
*/ |
| 80 |
public static function admin_extra_caps(): array { |
| 81 |
return [ |
| 82 |
'manage_storeengine_shop_manager', |
| 83 |
'manage_storeengine_settings', |
| 84 |
'edit_storeengine_orders', |
| 85 |
'publish_storeengine_products', |
| 86 |
'publish_storeengine_coupons', |
| 87 |
'publish_storeengine_groups', |
| 88 |
'publish_se_order_bumps', |
| 89 |
'read_private_storeengine_products', |
| 90 |
'read_private_storeengine_coupons', |
| 91 |
'read_private_storeengine_groups', |
| 92 |
'read_private_se_order_bumps', |
| 93 |
]; |
| 94 |
} |
| 95 |
|
| 96 |
/** |
| 97 |
* Caps granted to `storeengine_customer`. |
| 98 |
*/ |
| 99 |
public static function customer_caps(): array { |
| 100 |
// @TODO drop edit_posts once the customer dashboard no longer relies on it. |
| 101 |
return [ 'read', 'edit_posts' ]; |
| 102 |
} |
| 103 |
} |
| 104 |
|