0
votes

I have a problem with my 2 custom wordpress taxonomies.

I've created a custom post type called "kurs" and for this custom post type i've also created 2 custom hierarchical taxonomies. This worked fine until I wanted to add custom capabilities for the 2 taxonomies.

I've added the "capabilities" argument for the 2 capabilities

first taxonomy:

    'capabilities' => array(
        'manage_terms' => 'manage_location',
        'edit_terms' => 'edit_location',
        'delete_terms' => 'delete_location',
        'assign_terms' => 'assign_location',
    )

second taxonomy:

    'capabilities' => array(
        'manage_terms' => 'manage_typ',
        'edit_terms' => 'edit_typ',
        'delete_terms' => 'delete_typ',
        'assign_terms' => 'assign_typ',
    )

Then i added all these new custom capabilities to the administrator role with this function:

    function kurse_role_caps() {
    // gets the simple_role role object
    $role = get_role('administrator');

    // add a new capability
    $role->add_cap( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ', true);
    }

    add simple_role capabilities, priority must be after the initial role definition
    add_action('init', 'kurse_role_caps', 11);

But the second custom taxonomy does not show up in the admin menu even though i set the argument 'show_in_menu' to true :Screenshot of my admin menu

If i remove the custom capabilites from the second taxonomy it shows up in the admin: enter image description here

After I searched this problem on the internet no one had a similar problem. Here is my gist for the full code i use for the custom post type and the 2 custom taxonomies: https://gist.github.com/jeremygrlj/a9319591e3d1940e9ef465f024220e84

1

1 Answers

0
votes

Please note that add_cap only accept one capability as string and so you have to loop all capabilities. Change your function like this.

function kurse_role_caps() {
    // gets the simple_role role object
    $role = get_role('administrator');

    // add a new capability
    $capabilities = array( 'manage_location', 'edit_location', 'delete_location', 'assign_location', 'manage_typ', 'edit_typ', 'delete_typ', 'assign_typ' );
    foreach( $capabilities as $cap ) {
        $role->add_cap( $cap );
    }
}

// add simple_role capabilities, priority must be after the initial role definition
add_action('init', 'kurse_role_caps', 11);