0

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!

  • Please file an edit and describe exactly what is not working. Where are your code failing you, what are you trying to achieve – Pieter Goosen Jul 1 '14 at 15:19
1

This line in your wpo_add_caps() function is incorrect:

$admin->add_cap( 'administrator', $admin_cap );

It should simply read:

$admin->add_cap( $admin_cap );

Source: WP_Role::add_cap().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.