I've wrote this code.
function wpo_install() {
update_option( 'wpo_version', WPO_VERSION );
wpo_add_caps();
wpo_add_roles();
set_transient( '_wpo_activation_redirect', true );
}
register_activation_hook( WPO_ROOT, 'wpo_install' );
In another file:
global $wpo_shared_caps;
$wpo_shared_caps = array(
'edit_wp_orders',
'edit_wp_order',
'edit_others_wp_orders',
'read_wp_order',
'read_private_wp_orders',
'delete_wp_order'
);
function wpo_add_caps() {
global $wpo_shared_caps;
$admin_caps = array(
'backup_settings',
'view_full_reports',
'get_report_output'
);
$admin_caps = array_merge( $admin_caps, $wpo_shared_caps );
$admin = get_role( 'administrator' );
foreach( $admin_caps as $admin_cap )
$admin->add_cap( 'administrator', $admin_cap );
}
function wpo_add_roles() {
remove_role( 'accountant' );
remove_role( 'employer' );
global $wpo_shared_caps;
$read_caps = array(
'read_wp_order' => true,
'read_private_wp_orders' => true
);
$acc_caps = array();
foreach( $wpo_shared_caps as $cap )
$acc_caps[ $cap ] = true;
add_role( 'accountant', __( 'Accountant', 'wpo' ), $acc_caps );
add_role( 'employer', __( 'Employer', 'wpo' ), $read_caps );
}
But these aren't working. Please help me. I've confused!