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
This commit is contained in:
parent
4cb6db8467
commit
2561a6bb45
|
@ -1072,6 +1072,21 @@ function wp_set_post_lock( $post_id ) {
|
||||||
update_post_meta( $post->ID, '_edit_last', $current_user->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 "<div class='error'><p>$message</p></div>";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates autosave data for the specified post from $_POST data.
|
* Creates autosave data for the specified post from $_POST data.
|
||||||
*
|
*
|
||||||
|
|
|
@ -108,11 +108,7 @@ case 'edit':
|
||||||
wp_enqueue_script('word-count');
|
wp_enqueue_script('word-count');
|
||||||
|
|
||||||
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
||||||
$last_user = get_userdata( $last );
|
add_action('admin_notices', '_admin_notice_post_locked' );
|
||||||
$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( "'", "\'", "<div class='error'><p>$message</p></div>" );
|
|
||||||
add_action('admin_notices', create_function( '', "echo '$message';" ) );
|
|
||||||
} else {
|
} else {
|
||||||
wp_set_post_lock( $post->ID );
|
wp_set_post_lock( $post->ID );
|
||||||
wp_enqueue_script('autosave');
|
wp_enqueue_script('autosave');
|
||||||
|
|
|
@ -143,11 +143,7 @@ case 'edit':
|
||||||
enqueue_comment_hotkeys_js();
|
enqueue_comment_hotkeys_js();
|
||||||
|
|
||||||
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
||||||
$last_user = get_userdata( $last );
|
add_action('admin_notices', '_admin_notice_post_locked' );
|
||||||
$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( "'", "\'", "<div class='error'><p>$message</p></div>" );
|
|
||||||
add_action('admin_notices', create_function( '', "echo '$message';" ) );
|
|
||||||
} else {
|
} else {
|
||||||
wp_set_post_lock( $post->ID );
|
wp_set_post_lock( $post->ID );
|
||||||
wp_enqueue_script('autosave');
|
wp_enqueue_script('autosave');
|
||||||
|
|
Loading…
Reference in New Issue