How to Let Contributors Edit Their WordPress Posts After Being Approved

How to Let Contributors Edit Their WordPress Posts After Being Approved
WordPress offers a variety of user roles, each with different permissions. The “Contributor” role, by default, allows users to write posts, but they can’t publish them. An Editor or Administrator needs to review and approve their submissions. Once a post is approved and published, the Contributor loses the ability to edit it. This limitation can be frustrating for Contributors who want to make revisions or updates after their content has gone live. Fortunately, there are several ways to grant Contributors the ability to edit their published posts, enhancing collaboration and content management.
Understanding the Default WordPress Roles and Permissions
Before diving into solutions, it’s crucial to understand how WordPress manages user roles and capabilities. Each role has a defined set of permissions. These permissions determine what a user can and cannot do within the WordPress environment. The Contributor role is deliberately restricted to prevent unapproved changes to the live website.
The key roles involved are:
- Administrator: Has ultimate control over the WordPress site. Can do everything.
- Editor: Can manage and publish posts, including those of other users.
- Author: Can write, edit, and publish their own posts.
- Contributor: Can write posts but needs approval to publish.
- Subscriber: Can only manage their profile and comment on posts.
The default Contributor role lacks the “edit_published_posts” capability. This is the permission we need to grant to allow post-approval editing.
Methods to Allow Contributors to Edit Approved Posts
Several approaches can be used to enable post-approval editing for Contributors. Each method has its advantages and disadvantages, depending on your specific needs and technical comfort level.
1. Using a Plugin to Modify User Roles
The easiest and often most recommended method is to use a plugin. Several WordPress plugins are designed to manage user roles and capabilities. These plugins provide a user-friendly interface to modify permissions without directly editing code. Popular options include:
- User Role Editor: A comprehensive plugin that allows granular control over user roles and capabilities.
- Members: Another powerful plugin for managing roles, capabilities, and content access.
- WPFront User Role Editor: A simpler alternative focused on user role management.
How to use a plugin like User Role Editor:
- Install and activate the plugin. Search for “User Role Editor” in the WordPress plugin repository and install it. Activate the plugin after installation.
- Navigate to the User Role Editor. After activation, you’ll typically find the plugin under the “Users” menu in your WordPress dashboard.
- Select the “Contributor” role. The plugin interface will display a list of user roles. Select the “Contributor” role to modify its capabilities.
- Grant the “edit_published_posts” capability. Search for the “edit_published_posts” capability in the list of available capabilities. Check the box next to it to grant this permission to the Contributor role.
- Update the role. Save your changes to apply the new permissions to the Contributor role.
After completing these steps, Contributors will be able to edit their approved posts.
2. Adding Code to Your Theme’s functions.php File (or a Custom Plugin)
A more technical approach involves adding code to your theme’s functions.php
file or creating a custom plugin. This method requires some PHP knowledge and caution, as incorrect code can break your website. It is strongly recommended to back up your website before making any changes to the functions.php
file. Ideally, create a custom plugin for this purpose to avoid issues when updating your theme.
Here’s the code snippet you can use:
function add_contributor_caps() {
$contributor = get_role( 'contributor' );
$contributor->add_cap( 'edit_published_posts' );
}
add_action( 'admin_init', 'add_contributor_caps');
Explanation:
get_role( 'contributor' )
retrieves the Contributor role object.add_cap( 'edit_published_posts' )
adds the “edit_published_posts” capability to the role.add_action( 'admin_init', 'add_contributor_caps')
executes the function when the WordPress admin area is initialized.
Steps to implement:
- Back up your website. This is crucial before editing any core files.
- Access your theme’s
functions.php
file. You can find it inwp-content/themes/your-theme-name/functions.php
. You can access it through the WordPress theme editor (Appearance -> Theme Editor) or using an FTP client. - Add the code snippet. Paste the code snippet at the end of the
functions.php
file, before the closing?>
tag (if it exists). - Save the changes. Update the
functions.php
file.
Alternatively, create a custom plugin for this code. This keeps your theme’s functions.php
file cleaner and prevents the changes from being overwritten when the theme is updated.
3. Using Filters to Modify Post Status Transitions
This method involves using WordPress filters to modify the post status transitions. Specifically, you can use the wp_insert_post_data
filter to change the post status back to “draft” when a Contributor saves an approved post. This allows the Contributor to make changes, and then an Editor or Administrator needs to review and re-approve the post before it’s published again. This approach provides an extra layer of control and ensures that all changes are reviewed before going live.
Here’s the code snippet you can use in your functions.php
file or a custom plugin:
function allow_contributor_edit_approved_posts( $data, $postarr ) {
$post = get_post( $postarr['ID'] );
if ( $post && $post->post_type == 'post' && $post->post_status == 'publish' && current_user_can( 'contributor' ) && isset( $_POST['save'] ) ) {
$data['post_status'] = 'pending';
}
return $data;
}
add_filter( 'wp_insert_post_data', 'allow_contributor_edit_approved_posts', 10, 2 );
Explanation:
- The function checks if the current user is a Contributor and if they are trying to save a published post.
- If these conditions are met, the function changes the post status to “pending”.
- This triggers the approval workflow again, requiring an Editor or Administrator to review the changes.
Steps to implement:
- Back up your website. This is a critical step.
- Access your theme’s
functions.php
file or create a custom plugin. - Add the code snippet. Paste the code into the appropriate file.
- Save the changes. Update the file.
Considerations and Best Practices
Before implementing any of these solutions, consider the following:
- Security: Carefully consider the security implications of granting editing privileges to Contributors. Ensure that your website has strong security measures in place, such as regular backups, strong passwords, and a security plugin.
- Workflow: Establish a clear workflow for Contributors to edit approved posts. Communicate the new permissions to your team and explain how the process works.
- Revision Control: WordPress automatically saves revisions of posts. Encourage Contributors to use the revision history feature to track changes and revert to previous versions if needed.
- Communication: Encourage open communication between Contributors and Editors. Clear communication can prevent misunderstandings and ensure that all changes are properly reviewed.
Conclusion
Allowing Contributors to edit their approved WordPress posts can significantly improve content management efficiency and collaboration. By using a plugin, adding code to your functions.php
file, or modifying post status transitions, you can empower Contributors to make updates and revisions while maintaining control over the publishing process. Choose the method that best suits your technical skills and workflow requirements, and always prioritize security and communication.