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?

3
  • 1
    What is wrong with using the contributor role? Oct 20, 2014 at 19:49
  • Contributor role can not upload images...
    – NewUser
    Oct 20, 2014 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. Oct 20, 2014 at 20:22

2 Answers 2

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' );
4
  • 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, 2014 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, 2014 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, 2014 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, 2014 at 13:37
0

Yes, in WordPress, you can change the default post status for author user roles so that their posts are set to "draft" instead of being published immediately. To do this, you'll need to use a code snippet or a plugin that allows you to modify user capabilities and post statuses. Here's a step-by-step guide on how to achieve this using a code snippet:

  1. Access your WordPress site's files using an FTP client or a file manager from your hosting provider.

  2. In the root directory of your WordPress installation, you'll find a file called functions.php within your theme's folder. If you're using a child theme, you can use the child theme's functions.php file.

  3. Edit the functions.php file using a text editor.

  4. Add the following code to the functions.php file:

    function set_default_author_post_status() { if (current_user_can('author')) { // Set the default post status to 'draft' for authors return 'draft'; } // For other user roles, maintain the default behavior return get_option('default_post_status'); } add_filter('default_content', 'set_default_author_post_status');

This code checks if the current user has the "author" role and sets the default post status to "draft" for authors. For all other user roles, it maintains the default behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.