Make WordPress Core


Ignore:
Timestamp:
02/29/2008 09:51:36 AM (18 years ago)
Author:
ryan
Message:

Post Edit Collision Detection from mdawaffe. fixes #6043

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r6983 r7103  
    1919                $now = time();
    2020                $then = strtotime($post->post_date_gmt . ' +0000');
    21                 // Keep autosave_interval in sync with autosave-js.php.
    22                 $delta = apply_filters( 'autosave_interval', 120 ) / 2;
     21                $delta = get_option( 'autosave_interval' ) / 2;
    2322                if ( ($now - $then) < $delta )
    2423                        return $post_ID;
     
    620619}
    621620
     621// false: not locked or locked by current user
     622// int: user ID of user with lock
     623function wp_check_post_lock( $post_id ) {
     624        global $current_user;
     625
     626        if ( !$post = get_post( $post_id ) )
     627                return false;
     628
     629        $lock = get_post_meta( $post->ID, '_edit_lock', true );
     630        $last = get_post_meta( $post->ID, '_edit_last', true );
     631
     632        $time_window = apply_filters( 'wp_check_post_lock_window', get_option( 'autosave_interval' ) * 2 );
     633
     634        if ( $lock && $lock > time() - $time_window && $last != $current_user->ID )
     635                return $last;
     636        return false;
     637}
     638
     639function wp_set_post_lock( $post_id ) {
     640        global $current_user;
     641        if ( !$post = get_post( $post_id ) )
     642                return false;
     643        if ( !$current_user || !$current_user->ID )
     644                return false;
     645       
     646        $now = time();
     647
     648        if ( !add_post_meta( $post->ID, '_edit_lock', $now, true ) )
     649                update_post_meta( $post->ID, '_edit_lock', $now );
     650        if ( !add_post_meta( $post->ID, '_edit_last', $current_user->ID, true ) )
     651                update_post_meta( $post->ID, '_edit_last', $current_user->ID );
     652}
     653
    622654?>
Note: See TracChangeset for help on using the changeset viewer.