0

My question is exactly what is in the title: how can I disallow "contributors" to edit their own posts once they've been set to "Pending Review"? I can't seem to find any documentation on how to do this. Thanks!

0

You can do this by checking if the post author is a contributor and post status is pending before the post is saved.

Before the post is saved:

add_filter( 'wp_insert_post_data', 'disallow_edit_pending_3748', 99, 2 );

function disallow_edit_pending_3748( $post_data, $post_array ){

    if( 'pending' == $post_data['post_status'] && current_user_can( 'contributor' ) ){

        // there's no other way to do this.
        // Nothing can stop the post from saving and still make sense to the user, except this.
        wp_redirect(add_query_arg( 'message', 999, get_edit_post_link( $post_array['ID'], 'url' )));
        exit;   
    }

    return $post_data;
}

The add_query_arg to add message=999 is optional. You could just do wp_redirect(get_edit_post_link( $post_arr['ID'], 'url' ));

However, adding that extra parameter can let you show a message. I'm hooking into WordPress's own message display.

add_filter( 'post_updated_messages', 'add_custom_message_3748' );

function add_custom_message_3748( $messages ){
    $messages['post'][999] = "No, you can't do this!";
        return $messages;
}

The problem with this is that it will always be the update (green color) type. You can get creative and add admin notices using other ways.

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.