Release a user's post lock when the user leaves a post. see #18515.
git-svn-id: http://svn.automattic.com/wordpress/trunk@18796 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -988,8 +988,10 @@ case 'autosave' : // The name of this action is hardcoded in edit_post()
|
||||
$id = $post->ID;
|
||||
}
|
||||
|
||||
if ( $do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric( $id ) )
|
||||
wp_set_post_lock( $id );
|
||||
if ( $do_lock && empty( $_POST['auto_draft'] ) && $id && is_numeric( $id ) ) {
|
||||
$lock_result = wp_set_post_lock( $id );
|
||||
$supplemental['active-post-lock'] = implode( ':', $lock_result );
|
||||
}
|
||||
|
||||
if ( $nonce_age == 2 ) {
|
||||
$supplemental['replace-autosavenonce'] = wp_create_nonce('autosave');
|
||||
@@ -1551,6 +1553,26 @@ case 'wp-fullscreen-save-post' :
|
||||
echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) );
|
||||
die();
|
||||
break;
|
||||
case 'wp-remove-post-lock' :
|
||||
if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
|
||||
die( '0' );
|
||||
$post_id = (int) $_POST['post_ID'];
|
||||
if ( ! $post = get_post( $post_id ) )
|
||||
die( '0' );
|
||||
|
||||
check_ajax_referer( 'update-' . $post->post_type . '_' . $post_id );
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) )
|
||||
die( '-1' );
|
||||
|
||||
$active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
|
||||
if ( $active_lock[1] != get_current_user_id() )
|
||||
die( '0' );
|
||||
|
||||
$new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ) + 5 ) . ':' . $active_lock[1];
|
||||
update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
|
||||
die( '1' );
|
||||
|
||||
default :
|
||||
do_action( 'wp_ajax_' . $_POST['action'] );
|
||||
die('0');
|
||||
|
||||
@@ -231,7 +231,10 @@ require_once('./admin-header.php');
|
||||
<input type="hidden" id="post_type" name="post_type" value="<?php echo esc_attr( $post_type ) ?>" />
|
||||
<input type="hidden" id="original_post_status" name="original_post_status" value="<?php echo esc_attr( $post->post_status) ?>" />
|
||||
<input type="hidden" id="referredby" name="referredby" value="<?php echo esc_url(stripslashes(wp_get_referer())); ?>" />
|
||||
<?php if ( ! empty( $active_post_lock ) ) { ?>
|
||||
<input type="hidden" id="active_post_lock" value="<?php echo esc_attr( implode( ':', $active_post_lock ) ); ?>" />
|
||||
<?php
|
||||
}
|
||||
if ( 'draft' != $post->post_status )
|
||||
wp_original_referer_field(true, 'previous');
|
||||
|
||||
|
||||
@@ -1239,7 +1239,8 @@ function wp_check_post_lock( $post_id ) {
|
||||
* @since 2.5.0
|
||||
*
|
||||
* @param int $post_id ID of the post to being edited
|
||||
* @return bool Returns false if the post doesn't exist of there is no current user
|
||||
* @return bool|array Returns false if the post doesn't exist of there is no current user, or
|
||||
* an array of the lock time and the user ID.
|
||||
*/
|
||||
function wp_set_post_lock( $post_id ) {
|
||||
if ( !$post = get_post( $post_id ) )
|
||||
@@ -1251,6 +1252,7 @@ function wp_set_post_lock( $post_id ) {
|
||||
$lock = "$now:$user_id";
|
||||
|
||||
update_post_meta( $post->ID, '_edit_lock', $lock );
|
||||
return array( $now, $user_id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -174,7 +174,7 @@ case 'edit':
|
||||
if ( $last = wp_check_post_lock( $post->ID ) ) {
|
||||
add_action('admin_notices', '_admin_notice_post_locked' );
|
||||
} else {
|
||||
wp_set_post_lock( $post->ID );
|
||||
$active_post_lock = wp_set_post_lock( $post->ID );
|
||||
wp_enqueue_script('autosave');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user