0

I have a "product" post type, to which i would like to associate several users according to their (custom) roles ( "designer", "producer"). They will be able to create (but not publish), edit and submit each product for deletion. More or less like the default "contributor" role, really.

I fail to understand where to start to make this association between a custom post type and a user possible?

2
  • What do you mean by "associate" have them as the post's author or allow them to be able to edit/manage the post's?
    – Brooke.
    Jul 2 '13 at 17:21
  • They will be able to create (but not publish), edit and submit each product for deletion. More or less like the default "contributor" role, really. Thank you for your question.
    – pixeline
    Jul 2 '13 at 18:10
2

You have a few options. Either give your post type a custom permission or work within the existing permissions (such as post)

In my opinion the best way to go about this would be to set a custom capability type when you register the post type. A good one to use in your case may be 'product'

Then you can assign the capabilities you would like.

// get the "author" role object
$role = get_role( 'designer' );

// add "edit_products" to this role object
$role->add_cap( 'edit_products' );

Now if you don't want to assign all the capabilities manually in a custom plugin or functions.php file you can use the Members Plugin for an awesome GUI for this.

As mentioned, you could also use the core "edit_posts" instead of assigning a new capability type just depends on how much you care to limit the role. For example, if they are allowed to edit post and products or just products.

Here is a chart from the codex of capabilities:

    [edit_post]              =>  "edit_{$capability_type}"
    [read_post]              => "read_{$capability_type}"
    [delete_post]            => "delete_{$capability_type}"
    [edit_posts]             => "edit_{$capability_type}s"
    [edit_others_posts]      => "edit_others_{$capability_type}s"
    [publish_posts]          => "publish_{$capability_type}s"
    [read_private_posts]     => "read_private_{$capability_type}s"
    [delete_posts]           => "delete_{$capability_type}s"
    [delete_private_posts]   => "delete_private_{$capability_type}s"
    [delete_published_posts] => "delete_published_{$capability_type}s"
    [delete_others_posts]    => "delete_others_{$capability_type}s"
    [edit_private_posts]     => "edit_private_{$capability_type}s"
    [edit_published_posts]   => "edit_published_{$capability_type}s
5
  • thanks, i'm going to try this. Question: will it allow to have several designers (and/or scientists) for one product?
    – pixeline
    Jul 2 '13 at 19:08
  • 1
    yes, if you allow them to "edit_others_products" they can edit each others post otherwise they can only edit their own product. But custom roles follow the same rules as core roles.
    – Brooke.
    Jul 2 '13 at 19:37
  • thank you, very clear. But i've added the capabilities, and no UI shows up on the edit product screen, allowing to specify the designers and producers. Do i need to do more?
    – pixeline
    Jul 2 '13 at 19:39
  • Did you install the members plugin? or are you trying to do it all manually via a custom plugin? I would really recommend you install the members plugin. I assumed you already added the roles so next you just need to add each capability you want those roles to have.
    – Brooke.
    Jul 2 '13 at 19:47
  • yes i tried that plugin, but i realize i may have expressed my need in the wrong way: i would like, as an admin, to be able to edit products and specify a few producers and a few designers to each product, from the product edit screen. So, I'm considering using a custom taxonomy for Designer and Producer now instead of the Users system. Complicated...
    – pixeline
    Jul 3 '13 at 6:26

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.