Post Edit Collision Detection from mdawaffe. fixes #6043

git-svn-id: https://develop.svn.wordpress.org/trunk@7103 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren
2008-02-29 09:51:36 +00:00
parent 9a77cb8b83
commit e29306e69c
14 changed files with 314 additions and 203 deletions

View File

@@ -18,8 +18,7 @@ function edit_post() {
$post =& get_post( $post_ID );
$now = time();
$then = strtotime($post->post_date_gmt . ' +0000');
// Keep autosave_interval in sync with autosave-js.php.
$delta = apply_filters( 'autosave_interval', 120 ) / 2;
$delta = get_option( 'autosave_interval' ) / 2;
if ( ($now - $then) < $delta )
return $post_ID;
}
@@ -619,4 +618,37 @@ function get_sample_permalink_html($id, $new_slug=null) {
return $return;
}
// false: not locked or locked by current user
// int: user ID of user with lock
function wp_check_post_lock( $post_id ) {
global $current_user;
if ( !$post = get_post( $post_id ) )
return false;
$lock = get_post_meta( $post->ID, '_edit_lock', true );
$last = get_post_meta( $post->ID, '_edit_last', true );
$time_window = apply_filters( 'wp_check_post_lock_window', get_option( 'autosave_interval' ) * 2 );
if ( $lock && $lock > time() - $time_window && $last != $current_user->ID )
return $last;
return false;
}
function wp_set_post_lock( $post_id ) {
global $current_user;
if ( !$post = get_post( $post_id ) )
return false;
if ( !$current_user || !$current_user->ID )
return false;
$now = time();
if ( !add_post_meta( $post->ID, '_edit_lock', $now, true ) )
update_post_meta( $post->ID, '_edit_lock', $now );
if ( !add_post_meta( $post->ID, '_edit_last', $current_user->ID, true ) )
update_post_meta( $post->ID, '_edit_last', $current_user->ID );
}
?>