Stop Authors Editing Posts After They Are Published
Lets authors and contributors write and submit posts as usual, but once a post is published only editors and administrators can change it, which keeps approved content approved.
Opens WPIDE on
Code
// Days after publishing during which authors may still edit (0 = never).
$wpide_lock_after_days = 0;
add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id, $args ) use ( $wpide_lock_after_days ) {
if ( ! in_array( $cap, array( 'edit_post', 'delete_post' ), true ) || empty( $args[0] ) ) {
return $caps;
}
$post = get_post( (int) $args[0] );
if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) {
return $caps;
}
// Editors and administrators are never locked out.
if ( user_can( $user_id, 'edit_others_posts' ) ) {
return $caps;
}
if ( $wpide_lock_after_days && get_post_time( 'U', true, $post ) > time() - $wpide_lock_after_days * DAY_IN_SECONDS ) {
return $caps;
}
$caps[] = 'do_not_allow';
return $caps;
}, 10, 4 );
Notes
Set $wpide_lock_after_days to give authors a grace period, for example 1 day to fix typos.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.