it is possible after the publication of an article by a custom role prevent him from putting it back in the draft (the only admin can do this)? What's the code? Thanks for your help!

1 Answer 1


Sure it is - you can use the wp_insert_post_data filter:

function no_going_back_to_draft($slashed_data , $post_data) {
    if($slashed_data['post_status'] == 'draft') { // we're only interested in posts being saved as "drafts"
        $user = wp_get_current_user();
        if ( in_array( 'no-going-back-to-draft-role', (array) $user->roles ) ) { // we're only interested in users with that special, restricted role
            $post = get_post($post_data['ID']);
                $post && // if $post == null, it's a new post, so it's definitely never been published yet...
                ($post->post_status != 'draft') // so *any other status* but draft can't be brought back to "draft" by this partuclar user
            ) {
                $slashed_data['post_status'] = $post->post_status; // override the post's status: set it to the current value in the db
    return $slashed_data;
add_action( 'wp_insert_post_data', 'no_going_back_to_draft', 10, 2 );

Hope this helps!

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.