WordPress does not allow Contributor to publish its articles. But still I have seen that many WordPress users want the Contributor to edit and publish their posts.
In such a situation you will have to use custom script. So let’s see how to allow Contributor to publish posts in WordPress:
// get the "contributor" role object $obj_existing_role = get_role( 'contributor' ); // add the "Edit published posts" capability $obj_existing_role->add_cap( 'edit_published_posts' ); // add the "Publishing" capability $obj_existing_role->add_cap( 'publish_posts' );
Now you must be thinking how to default it again. Let’s see how to remove permission again.
// remove the "Edit published posts" capability $obj_existing_role->remove_cap( 'edit_published_posts' ); // remove the "Publishing" capability $obj_existing_role->remove_cap( 'publish_posts' );
If you are a newbie in WordPress development then you should also know where to write this custom script. Many blogs will tell you to add it to the function of your theme, but I’ll tell you a good solution to it so that there is no further issues in your theme.
- Go to CPanel and open WordPress directory.
- Create New PHP file in your plugin directory . For Ex – “Custom.php”.
– Write these code first:
< ? php /* Plugin Name: Custom Plugin URI: http://example.com/ Description: Created by AR Mishra Author: AR Author URI: http://example.com/ License: Self Generated License URI: - Version: 1.0 */
- Add your Script below the Description in your custom.php file.
- Save the file.
- Open WordPress Admin Panel
- Activate your custom Plugin.