我现在通过这段代码添加了这些功能。我对我的解决方案不满意,如果有人能找到一种合适的方法添加到过滤器中,那就太好了。我真的很想知道如何使它正常工作。
add_action( \'admin_init\', \'jp_add_atum_caps_to_shop_manager\');
function jp_add_atum_caps_to_shop_manager() {
if(!user_can( 217 , \'atum_read_inbound_stock\')) {
$capabilities = array(
// Purchase price caps.
\'edit_purchase_price\',
\'view_purchase_price\',
// Inbound Stock caps.
\'read_inbound_stock\',
// Out Stock Threshold caps.
\'edit_out_stock_threshold\',
// Settings caps.
\'manage_settings\',
\'edit_visual_settings\',
// ATUM menus caps.
\'view_admin_menu\',
\'view_admin_bar_menu\',
// Other caps.
\'export_data\',
\'view_statistics\',
);
// Add the ATUM prefix to all the capabilities.
$capabilities = preg_filter( \'/^/\', \'atum_\' , $capabilities );
$admin_role = get_role( \'shop_manager\' );
foreach ( $capabilities as $cap ) {
$admin_role->add_cap( $cap );
}
}
}