0

my question title says it all.

I am not sure if I should approach this by adding a capability to the author role or adding a capabilities array when I register the custom post type or even when I register the custom taxonomy.

If the correct approach is to add a capabilities array to the arguments to register_post_type it is still not clear to me from the documentation how this works. (I don't even understand the concept of adding a capability to a post because a post is not a role; there seems to be some suggestion that this array is a mapping e.g. assign_terms =>edit_posts will allow roles who have edit posts capabilities to assign terms - but that did not work for me).

The documentation definitely does not explain this.

Edit1: I don't need the ability for authors to manage taxonomy terms - just see the existing terms and assign them to the (custom) post.

Thanks

4
  • note that you are not assigning a capability to a post. There's a difference between saying a Role has a capability, and a post needs/requires it. Nails require hammers to be used, but people own and possess hammers
    – Tom J Nowell
    Commented Jul 3, 2023 at 16:53
  • @TomJNowell - ok, so taken with my solution below, what this is saying is "this taxonomy needs the user of it to have edit_post capabilities in order to grant the assign_terms capability". (By the way assign_term and assign_terms seem to work interchangably).
    – Kropotkin
    Commented Jul 3, 2023 at 17:02
  • try to limit yourself to 1 question per question, you need to be able to assign an answer as the correct/accepted answer which becomes impossible if it becomes a rambling discussion. You can always create additional questions on the site.
    – Tom J Nowell
    Commented Jul 3, 2023 at 17:05
  • As for capabilities, I don't see how it's different to a keycard/pass or a set of keys? A lock needs a key, a user can have a key. Saying that does not mean that a lock owns a key, I think you've muddled up words and technical terms. Note that you've not provided an example of CPT registration for context and as a result it's very difficult to reason about your question without misunderstandings and ambiguity. You've also moved a large chunk of your question into an answer posted below which is confusing, adding that code would make your question clearer
    – Tom J Nowell
    Commented Jul 3, 2023 at 17:08

1 Answer 1

0

Yes. It is some kind of mapping. So now, when I register the custom taxonomy I pass it:

 $caps = array(
            'manage_terms'  => 'activate_plugins',
            'edit_terms'    => 'activate_plugins',
            'delete_terms'  => 'activate_plugins',
            'assign_terms'  => 'edit_posts'
        );

With this result authors can now assign terms. I am just using 'activate_plugins' because, by default, authors do not have this capability and so by the mapping they cannot manage terms. If I put edit_posts here then they can manage the terms and I don't want that.

So, what this seems to be saying, is "for this custom taxonomy any role which has the edit_posts capability will be able to assign terms from this taxonomy to any post which the taxonomy is registered to"

While this actually seems to work it is still opaque to me what is going on. I would be interested in any further explanations.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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