6

I run a multi author blog and i am looking for a non plugin solution.

The default author user role in Wordpress can publish posts without any approvel - look at Role Capabilities Wordpress Codex. Using the contributor role to achieve my goal is not possible, because the contributor role can not upload images...

Is it possible to set all author posts to a status like "draft" - so that only a editor can publish the posts?

  • 1
    What is wrong with using the contributor role? – Mark Kaplun Oct 20 '14 at 19:49
  • Contributor role can not upload images... – NewUser Oct 20 '14 at 19:53
  • 2
    then use a plugin to add the ability... If you trust the people to not upload porn/vitus then it will be the easiest solution. – Mark Kaplun Oct 20 '14 at 20:22
13
+250

Add the following code to your functions.php:

function allow_contributor_uploads() {
    $contributor = get_role('contributor');
    $contributor->add_cap('upload_files');
}
if ( current_user_can('contributor') && !current_user_can('upload_files') ) {
    add_action('admin_init', 'allow_contributor_uploads');
}

This will add the upload_files capability to the Contributor role. It only needs to run once; just login to admin as a user with the Contributor role. After it successfully adds the capability, you can remove (or comment out) the code if you want.

To remove the upload_files capability and return the Contributor role to default, use the following:

function deny_contributor_uploads() {
    $contributor = get_role('contributor');
    $contributor->remove_cap('upload_files');
}
if ( current_user_can('contributor') && current_user_can('upload_files') ) {
    add_action('admin_init', 'deny_contributor_uploads');
}

Plugin Option

From the suggestions made by Kaiser, here is a plugin that will create a NEW user role with the Contributor capabilities (edit, delete and read posts), PLUS the upload files capability.

<?php
/**
 * Plugin Name: Add Contributor Plus Role
 * Description: Activate plugin to create a user role with Contributor capabilities, PLUS upload_files.
 * Plugin URI: http://wordpress.stackexchange.com/questions/165951/publish-author-posts-only-with-editor-approval/165957#165957
 * Version: 1.0
 */

add_action( 'wp_loaded', 'add_new_contributor_plus_role');
function add_new_contributor_plus_role() {
    add_role(
        'contributor_plus',
        __( 'Contributor Plus' ),
        array(
            'edit_posts'   => true,
            'delete_posts' => true,
            'read'         => true,
            'upload_files' => true
        )
    );
}
?> 

Add the above code to /wp-content/plugins/add-contributor-plus-role/add-contributor-plus-role.php, OR create the /add-contributor-plus-role/add-contributor-plus-role.php folder and file locally, add to a zip file, and upload using Plugins > Add New > Uploads. Feel free to change the name of the user role to whatever you want.

Active the plugin and the role will be added. You can deactivate the plugin, and delete it; it won't effect the newly created user role.

If you change your mind and want the "Contributor Plus" user role removed, use the following in place of the add_role lines (through to the ; semicolon) and active the plugin once more:

remove_role( 'contributor_plus' );
  • 2
    +1, but this should probably be wrapped in a plugin and attached to a hook like wp_loaded where it's safer to run. Another note for a possible improvement: Add a custom role, so the default contributor doesn't get messed up with capabilities that aren't meant for such users. – kaiser Oct 21 '14 at 2:31
  • Looks great! It would be awesome if you can provide me the code to set the upload_files capability back to default. Maybe i need it later on - Thank you so much – NewUser Oct 21 '14 at 3:09
  • 1
    OK, I've added code for later removing upload_files from Contributor. I also added an alternative solution, based on suggestions by @kaiser, that uses a plugin to add a new user role with the capabilities you need. – Gabriel Oct 21 '14 at 5:34
  • Looks great Gabriel - thank you so much. I will give it a try a bit later. Maybe there is another suggestion to change the author role cap... best – NewUser Oct 21 '14 at 13:37

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.