Skip to content

Limiting the ability to edit a published post for certain roles in WordPress

Warning: this article was written over 10 years ago, some information may be out of date.

For one of the sites I have been working on, I was faced with a problem: having given access, via registration, to a role that can only enter posts and put them up for review, once an administrator publishes the post, the user can easily edit the published post.
Wanting to limit this functionality, I found the following trick:

function wporg_always_pending( $data , $postarr ) { 
    if ( ! current_user_can( 'moderate_comments' ) ) {
           $data['post_status'] = 'pending';     
    }
    return $data;  
}

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

Each time the user edits the post, it returns to the pending status, and an administrator will have to publish it again.

Previous article

Next article

Thread

Leave a comment

Your email address will not be published.