From aeaafa32d2762a1f208281f27a544df74e11bc20 Mon Sep 17 00:00:00 2001 From: westi Date: Tue, 20 Oct 2009 17:00:34 +0000 Subject: [PATCH] Backport of the switch of the post|page being editing message from a create_function call to a normal function and reduce the duplicated code. See #10729 for 2.8 branch. git-svn-id: http://svn.automattic.com/wordpress/branches/2.8@12068 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 26 ++++++++++++++++++++++++++ wp-admin/page.php | 6 +----- wp-admin/post.php | 6 +----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index a026832929..51bb136c0d 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -1059,6 +1059,32 @@ 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.8.5 + * @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'); + + switch ($post->post_type) { + case 'post': + $message = __( 'Warning: %s is currently editing this post' ); + break; + case 'page': + $message = __( 'Warning: %s is currently editing this page' ); + break; + default: + $message = __( 'Warning: %s is currently editing this.' ); + } + + $message = sprintf( $message, esc_html( $last_user_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 68a6690201..9e5eef6871 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -98,11 +98,7 @@ case 'edit': if ( current_user_can('edit_page', $page_ID) ) { 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 008778faeb..cc8e06c777 100644 --- a/wp-admin/post.php +++ b/wp-admin/post.php @@ -133,11 +133,7 @@ case 'edit': if ( current_user_can('edit_post', $post_ID) ) { 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');