admin管理员组

文章数量:1122846

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?

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?

Share Improve this question asked Feb 21, 2020 at 18:34 Charles XavierCharles Xavier 1911 silver badge16 bronze badges 1
  • Not sure why you ask this, maybe I am wrong but that's just an option in User Role Editor. Select the role and add it to the role or just leave it inactive imho. – Charles Commented Feb 21, 2020 at 19:33
Add a comment  | 

2 Answers 2

Reset to default 1

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;
}

本文标签: allow user to create a draft post but not publish wordpress