Created
December 22, 2021 22:03
-
-
Save janvier005/f1d4018dd1049a674c78b1dbe789cab7 to your computer and use it in GitHub Desktop.
Add shop_manager role to access Atum Stock Manager into Wordpress / Woocommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shop_manager_stock_capabilities() { | |
$capabilities = array( | |
// Purchase price caps. | |
'edit_purchase_price', | |
'view_purchase_price', | |
// Purchase Orders caps. | |
'edit_purchase_order', | |
'read_purchase_order', | |
'delete_purchase_order', | |
'read_private_purchase_orders', | |
'publish_purchase_orders', | |
'edit_purchase_orders', | |
'edit_others_purchase_orders', | |
'create_purchase_orders', | |
'delete_purchase_orders', | |
'delete_other_purchase_orders', | |
// Inventory Logs caps. | |
'edit_inventory_log', | |
'read_inventory_log', | |
'delete_inventory_log', | |
'read_private_inventory_logs', | |
'publish_inventory_logs', | |
'edit_inventory_logs', | |
'edit_others_inventory_logs', | |
'create_inventory_logs', | |
'delete_inventory_logs', | |
'delete_other_inventory_logs', | |
// Inbound Stock caps. | |
'read_inbound_stock', | |
// Out Stock Threshold caps. | |
'edit_out_stock_threshold', | |
'edit_low_stock_threshold', | |
// Suppliers caps. | |
'edit_supplier', | |
'read_supplier', | |
'delete_supplier', | |
'edit_suppliers', | |
'edit_others_suppliers', | |
'publish_suppliers', | |
'read_private_suppliers', | |
'create_suppliers', | |
'delete_suppliers', | |
'delete_private_suppliers', | |
'delete_published_suppliers', | |
'delete_other_suppliers', | |
'edit_private_suppliers', | |
'edit_published_suppliers', | |
// Settings caps. | |
'manage_settings', | |
'edit_visual_settings', | |
// ATUM menus caps. | |
'view_admin_menu', | |
'view_admin_bar_menu', | |
// ATUM Order notes caps. | |
'read_order_notes', | |
'create_order_notes', | |
'delete_order_notes', | |
// ATUM Locations caps. | |
'manage_location_terms', | |
'edit_location_terms', | |
'delete_location_terms', | |
'assign_location_terms', | |
// Other caps. | |
'export_data', | |
'view_statistics', | |
); | |
$wp_capabilities = array( | |
'edit_others_multiple_post_types', | |
'read_private_multiple_post_types', | |
); | |
$capabilities = array_merge( preg_filter( '/^/', ATUM_PREFIX, $capabilities ), $wp_capabilities, apply_filters( 'atum/capabilities', [] ) ); | |
d($capabilities); | |
// get the the role object | |
$role_object = get_role( 'shop_manager' ); | |
// add $cap capability to this role object | |
foreach ( $capabilities as $cap ) { | |
$role_object->add_cap( $cap, true ); | |
} | |
d(get_role( 'shop_manager' )); | |
} | |
add_action('init', 'shop_manager_stock_capabilities'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment