Hello,
There are a few example on the web about how to prevent editing a post while the post meets certain conditions. Adding the following snippet to your functions.php file would prevent posts from being edited by non-admins when the post has the status “pitch”.
function restrict_editing_by_status( $allcaps, $cap, $args ) {
if( 'edit_post' != $args[0] && 'delete_post' != $args[0]
|| !empty( $allcaps['manage_options'] ) // don't restrict if the user can manage options
|| empty( $allcaps['edit_posts'] ) // the user already can't edit post
) {
return $allcaps;
}
$post = get_post( $args[2] );
// If the post status is pitch
if ( $post->post_status === 'pitch' ) {
$allcaps[$cap[0]] = false;
}
return $allcaps;
}
add_filter( 'user_has_cap', 'restrict_editing_by_status', 10, 3 );
Thanks!
Connor