allow user to create a draft post but not publish wordpress

Im currently using User Role editor to modify permission for the user role. I'd like to be able to restrict the role from publishing a post. They can save the draft but they should not be able to publish. Is there a better way to do it?

Topic user-roles posts Wordpress

Category Web


Give the user the edit_posts capability but not the publish_posts capability.


Use wp_insert_post_data filter. Then check the user role. If user have specific role set-up post status. ( I don't test below script)

add_filter( 'wp_insert_post_data', 'filter_handler', '99');

function filter_handler( $data ) {
    $user = wp_get_current_user();
    $userRole = $user->roles ? $user->roles[0] : false;

    if ( $userRole === 'author') {
        $data['post_status'] = 'pending';
    }

    return $data;
}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.