Ticket #15130: 15130.add-id-to-lock.3.diff

File 15130.add-id-to-lock.3.diff, 1.8 KB (added by duck_, 2 years ago)
  • wp-admin/includes/post.php

     
    12011201        if ( !$post = get_post( $post_id ) ) 
    12021202                return false; 
    12031203 
    1204         $lock = get_post_meta( $post->ID, '_edit_lock', true ); 
    1205         $last = get_post_meta( $post->ID, '_edit_last', true ); 
     1204        if ( !$lock = get_post_meta( $post->ID, '_edit_lock', true ) ) 
     1205                return false; 
    12061206 
     1207        $lock = explode( ':', $lock ); 
     1208        $time = $lock[0]; 
     1209        $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 
     1210         
    12071211        $time_window = apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ); 
    12081212 
    1209         if ( $lock && $lock > time() - $time_window && $last != get_current_user_id() ) 
    1210                 return $last; 
     1213        if ( $time && $time > time() - $time_window && $user != get_current_user_id() ) 
     1214                return $user; 
    12111215        return false; 
    12121216} 
    12131217 
     
    12221226function wp_set_post_lock( $post_id ) { 
    12231227        if ( !$post = get_post( $post_id ) ) 
    12241228                return false; 
    1225         if ( 0 == get_current_user_id() ) 
     1229        if ( 0 == ($user_id = get_current_user_id()) ) 
    12261230                return false; 
    12271231 
    12281232        $now = time(); 
     1233        $lock = "$now:$user_id"; 
    12291234 
    1230         update_post_meta( $post->ID, '_edit_lock', $now ); 
     1235        update_post_meta( $post->ID, '_edit_lock', $lock ); 
    12311236} 
    12321237 
    12331238/** 
     
    12381243 */ 
    12391244function _admin_notice_post_locked() { 
    12401245        global $post; 
    1241         $last_user = get_userdata( get_post_meta( $post->ID, '_edit_last', true ) ); 
     1246 
     1247        $lock = explode( ':', get_post_meta( $post->ID, '_edit_lock', true ) ); 
     1248        $user = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post->ID, '_edit_last', true ); 
     1249        $last_user = get_userdata( $user ); 
    12421250        $last_user_name = $last_user ? $last_user->display_name : __('Somebody'); 
    12431251 
    12441252        switch ($post->post_type) {