Make WordPress Core

Ticket #18515: 18515-2.patch

File 18515-2.patch, 2.4 KB (added by azaozz, 12 years ago)
  • wp-admin/admin-ajax.php

     
    15451545        echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) );
    15461546        die();
    15471547        break;
     1548case 'wp-remove-post-lock' :
     1549
     1550        $post_id = isset($_POST['post_ID']) ? (int) $_POST['post_ID'] : 0;
     1551        if ( !current_user_can('edit_post', $post_id) || empty($_POST['user_ID']) )
     1552                die();
     1553
     1554        $post = $post_type = null;
     1555
     1556        if ( $post_id ) {
     1557                $post = get_post($post_id);
     1558                if ( $post )
     1559                        $post_type = $post->post_type;
     1560        }
     1561
     1562        check_ajax_referer('update-' . $post_type . '_' . $post_id);
     1563
     1564        sleep(4);
     1565
     1566        if ( !$lock = get_post_meta( $post_id, '_edit_lock', true ) )
     1567                die('-1');
     1568
     1569        $lock = explode( ':', $lock );
     1570        $user_id = isset( $lock[1] ) ? $lock[1] : get_post_meta( $post_id, '_edit_last', true );
     1571        $locked = (int) $lock[0];
     1572
     1573        if ( time() - $locked < 5 ) // give a few seconds for the lock to be refreshed if the user reloaded the page
     1574                die('0');
     1575
     1576        if ( $user_id == $_POST['user_ID'] )
     1577                delete_post_meta( $post_id, '_edit_lock' );
     1578
     1579        die('1');
     1580        break;
    15481581default :
    15491582        do_action( 'wp_ajax_' . $_POST['action'] );
    15501583        die('0');
  • wp-admin/js/post.dev.js

     
    643643        }
    644644
    645645        wptitlehint();
     646
     647        // remove the post lock on unload
     648        $(window).unload(function() {
     649                $.ajax({
     650                        type: 'POST',
     651                        url: ajaxurl,
     652                        data: {
     653                                action: 'wp-remove-post-lock',
     654                                _wpnonce: $('#_wpnonce').val(),
     655                                post_ID: $('#post_ID').val(),
     656                                user_ID: $('#user_ID').val()
     657                        }
     658                });
     659        });
    646660});
  • wp-includes/script-loader.php

     
    281281
    282282                $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), '20110822', 1 );
    283283
    284                 $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20110524', 1 );
     284                $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), '20110824', 1 );
    285285                $scripts->add_script_data( 'post', 'postL10n', array(
    286286                        'ok' => __('OK'),
    287287                        'cancel' => __('Cancel'),