From 2561a6bb45b9e0b3dac6bfb242fdc26c3c17a05a Mon Sep 17 00:00:00 2001 From: westi Date: Sun, 13 Sep 2009 08:52:39 +0000 Subject: [PATCH] Switch the post|page being editing message from a create_function call to a normal function and reduce the duplicated code. See #10729. git-svn-id: http://svn.automattic.com/wordpress/trunk@11923 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 15 +++++++++++++++ wp-admin/page.php | 6 +----- wp-admin/post.php | 6 +----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 25811b011..32d7b3464 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 fcb7bd205..418d5655c 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 35636448a..c83296351 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');