Allow WordPress User Roles to Edit Posts in Single Category
A PublishPress user asked us this question:
Can I set up my WordPress site so users from “Department A” can only create and edit posts in “Category A”? Then we'd like to do the same thing for other departments.
Yes, that is possible with the PublishPress plugins and I'm going to show you how it's done:
Step #1. Create the Roles
You can create the roles using any plugin or technique, but we're going to show you how to do this using the PublishPress Capabilities plugin.
- Go to “Capabilities” in your WordPress admin.
- Choose “Subscriber” under “Select Role to View / Edit”.
- Click “Load”.
- Enter “Department A” into the “Copy Subscriber Role” box.
- Click “Copy”.
You will now have a new role called “Department A”. You can now repeat this process to create “Department B” and “Department C” roles. You'll be able to see these new roles in the “Select Role to View / Edit” dropdown:
Step #2. Add the Users to Roles
Now you can go to your “Users” area and add users to these different roles. I've added one user to each of my three new roles:
Step #3. Create the Categories
The next step requires installing the PublishPress Permissions Pro plugin.
After installing the PublishPress Permissions Pro plugin, go to Posts > Categories.
Create a new category for “Department A”:
- Click “Edit” for the “Department A” category.
- At the bottom of the screen, check the box “enable custom permissions for Categories”.
- Click “Update”.
When the screen refreshes you will see new options:
- Post Reading Exceptions: Control who can read posts in this category.
- Post Editing Exceptions: Control who can edit posts in this category.
- Post Revision Exceptions: Control who can create revisions for posts in this category.
- Post Category Assignment Exceptions: Control who can add posts to this category.
So you can customize permissions for this category in multiple ways. We're going to use the example of “Post Editing Exceptions”. This will control who can edit posts that have this category:
In this example, we will deny editing permissions to everyone except “Department A”.
Repeat this process by creating categories for Department B and Department C users. Make sure to set the correct permissions using the “Post Editing Exceptions” area.
Step #4. Test the user accounts
At this point, I would highly recommend testing the user accounts to make sure their permissions are accurate.
First, let's create a test post:
- Create a Post.
- Add the “Department A” category to your new Post:
Now we're going to login using one of the accounts that we want to restrict.
If you're using dummy users, you can reset their passwords. If you're testing with real users, the User Switching plugin is very helpful.
In this example, the Department A users will only be able to see the “Posts” menu link and the Posts that have the “Department A” category. They will not see the Pages for any other department.
Repeat this test for your other departments. When you're finished, you should now have a site with user in different roles can only post or edit content in the category that you choose.
In this tutorial we focused only on editing, but you can also customize the category permissions for reading, creating posts, and creating revisions. PublishPress Permissions Pro is a very powerful and flexible plugin.