Notice When Editing Someone Else's Post
Reminds editors with a notice in the block editor when the post they opened was written by another author, to avoid unintended changes to a colleague's work.
Opens WPIDE on
Code
add_action( 'enqueue_block_editor_assets', function () {
$post = get_post();
if ( ! $post || ! $post->post_author || (int) $post->post_author === get_current_user_id() || 'auto-draft' === $post->post_status ) {
return;
}
$message = sprintf( 'You are editing a %s written by %s.', get_post_type_object( $post->post_type )->labels->singular_name, get_the_author_meta( 'display_name', $post->post_author ) );
wp_add_inline_script(
'wp-notices',
sprintf( 'wp.domReady(function(){wp.data.dispatch("core/notices").createInfoNotice(%s,{id:"wpide-other-author"});});', wp_json_encode( $message ) ),
'after'
);
wp_enqueue_script( 'wp-notices' );
wp_enqueue_script( 'wp-dom-ready' );
} );
Notes
Shows the original author's name; it does not lock the post.
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.