mercredi 11 octobre 2017

Wordpress Capabilities For Different Users With Different Roles

I am very experienced with Wordpress development, however, I have been asked to do something that I haven't before and my initial thoughts of setting and removing capabilities from individual users isn't working out too well...so I thought I would get a second opinion.

The situation is as follows: On the user edit profile screen in the admin area I have added some additional check boxes. The site has a few different custom post types, so there is a checkbox for each post type for User Can Moderate [Post Type] .

Each user on the site has the Author role, but what I want to do is manage the user capabilities so if say a user named John has the checkbox for Moderate Test Post Type checked they should be able to edit, publish and delete other people's posts in that particular post type. They should also be able to create , edit, publish and delete their own in that post type unless another checkbox is unchecked saying they can't create their own content.

Now I assumed that when saving the options I could bring in a WP_User object and add_cap and remove_cap on the custom post type. It works to an extent but it seems to trip up on itself and I'm not sure what I am doing wrong.

So for example, if the user is NOT able to create their own content but CAN edit, publish and delete other peoples content I would have thought removing the edit_posts, create_posts and delete_posts would do that and adding capabilities (replacing _posts with the post type) for edit_others_posts, publish_others_posts and delete_others_posts would do it, but it doesn't! If I remove their ability to create their own content I can't seem to get them to be able to edit other peoples content.

Has anyone any idea how to solve this?




Aucun commentaire:

Enregistrer un commentaire