diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 25811b0119..32d7b3464d 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1072,6 +1072,21 @@ function wp_set_post_lock( $post_id ) { update_post_meta( $post->ID, '_edit_last', $current_user->ID ); } +/** + * Outputs the notice message to say that someone else is editing this post at the moment. + * + * @since 2.9.0 + * @return none + */ +function _admin_notice_post_locked() { + global $post; + $last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) ); + $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); + $post_type_name = ('page' == $post->post_type) ? _x('page', 'Used to describe page in admin_notice when other user editing.') : _x('post','Used to describe post in admin_notice when other user editing.'); + $message = sprintf( __( 'Warning: %1$s is currently editing this %2$s' ), esc_html( $last_user_name ), esc_html( $post_type_name ) ); + echo "

$message

"; +} + /** * Creates autosave data for the specified post from $_POST data. * diff --git a/wp-admin/page.php b/wp-admin/page.php index fcb7bd205e..418d5655c1 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -108,11 +108,7 @@ case 'edit': wp_enqueue_script('word-count'); if ( $last = wp_check_post_lock( $post->ID ) ) { - $last_user = get_userdata( $last ); - $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); - $message = sprintf( __( 'Warning: %s is currently editing this page' ), esc_html( $last_user_name ) ); - $message = str_replace( "'", "\'", "

$message

" ); - add_action('admin_notices', create_function( '', "echo '$message';" ) ); + add_action('admin_notices', '_admin_notice_post_locked' ); } else { wp_set_post_lock( $post->ID ); wp_enqueue_script('autosave'); diff --git a/wp-admin/post.php b/wp-admin/post.php index 35636448ab..c832963519 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -143,11 +143,7 @@ case 'edit': enqueue_comment_hotkeys_js(); if ( $last = wp_check_post_lock( $post->ID ) ) { - $last_user = get_userdata( $last ); - $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); - $message = sprintf( __( 'Warning: %s is currently editing this post' ), esc_html( $last_user_name ) ); - $message = str_replace( "'", "\'", "

$message

" ); - add_action('admin_notices', create_function( '', "echo '$message';" ) ); + add_action('admin_notices', '_admin_notice_post_locked' ); } else { wp_set_post_lock( $post->ID ); wp_enqueue_script('autosave');