Make WordPress Core

Changeset 24273


Ignore:
Timestamp:
05/16/2013 03:47:09 AM (11 years ago)
Author:
azaozz
Message:

Separate the nonces update from checking the post lock. Fix scheduling the logged out check. See #23697, see #23295.

Location:
trunk
Files:
3 edited

Legend:

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

    r24209 r24273  
    624624        }
    625625
     626        $response['wp-refresh-post-lock'] = $send;
     627    }
     628
     629    return $response;
     630}
     631add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
     632
     633/**
     634 * Check nonce expiration on the New/Edit Post screen and refresh if needed
     635 *
     636 * @since 3.6
     637 */
     638function wp_refresh_post_nonces( $response, $data, $screen_id ) {
     639    if ( 'post' == $screen_id && array_key_exists( 'wp-refresh-post-nonces', $data ) ) {
     640        $received = $data['wp-refresh-post-nonces'];
     641
     642        if ( ! $post_id = absint( $received['post_id'] ) )
     643            return $response;
     644
     645        if ( ! current_user_can('edit_post', $post_id) )
     646            return $response;
     647
    626648        if ( ! empty( $received['post_nonce'] ) && 2 === wp_verify_nonce( $received['post_nonce'], 'update-post_' . $post_id ) ) {
    627             $send['update_nonces'] = array(
     649            $response['wp-refresh-post-nonces'] = array(
    628650                'replace-autosavenonce' => wp_create_nonce('autosave'),
    629651                'replace-getpermalinknonce' => wp_create_nonce('getpermalink'),
     
    634656            );
    635657        }
    636 
    637         $response['wp-refresh-post-lock'] = $send;
    638658    }
    639659
    640660    return $response;
    641661}
    642 add_filter( 'heartbeat_received', 'wp_refresh_post_lock', 10, 3 );
     662add_filter( 'heartbeat_received', 'wp_refresh_post_nonces', 10, 3 );
    643663
    644664/**
  • trunk/wp-admin/js/post.js

    r24209 r24273  
    255255    var lock = $('#active_post_lock').val(),
    256256        post_id = $('#post_ID').val(),
    257         post_nonce = $('#_wpnonce').val(),
    258257        send = {};
    259258
     
    265264    if ( lock )
    266265        send['lock'] = lock;
    267 
    268     if ( post_nonce )
    269         send['post_nonce'] = post_nonce;
    270266
    271267    data['wp-refresh-post-lock'] = send;
     
    320316});
    321317
     318}(jQuery));
     319
     320(function($) {
     321    var check, timeout;
     322
     323    function schedule() {
     324        check = false;
     325        window.clearTimeout( timeout );
     326        timeout = window.setTimeout( function(){ check = 1; }, 3600000 );
     327    }
     328
     329    $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
     330        var nonce, post_id;
     331
     332        if ( check ) {
     333            if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
     334                data['wp-refresh-post-nonces'] = {
     335                    post_id: post_id,
     336                    post_nonce: nonce
     337                };
     338            }
     339            check = 2;
     340        }
     341    }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
     342        if ( check === 2 )
     343            schedule();
     344
     345        if ( data['wp-refresh-post-nonces'] ) {
     346            $.each( data['wp-refresh-post-nonces'], function( selector, value ) {
     347                if ( selector.match(/^replace-/) )
     348                    $( '#' + selector.replace('replace-', '') ).val( value );
     349            });
     350        }
     351    }).ready( function() {
     352        schedule();
     353    });
    322354}(jQuery));
    323355
  • trunk/wp-includes/js/wp-auth-check.js

    r24271 r24273  
    7373        check = false;
    7474        window.clearTimeout( timeout );
    75         timeout = window.setTimeout( function(){ check = true; }, 180000 ); // 3 min.
     75        timeout = window.setTimeout( function(){ check = 1; }, 180000 ); // 3 min.
    7676    }
    7777
    7878    $( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
    79         if ( check )
     79        if ( check === 2 )
    8080            schedule();
    8181
     
    104104            if ( check || ! empty )
    105105                data['wp-auth-check'] = 1;
     106
     107            if ( check )
     108                check = 2;
    106109        });
    107110    });
Note: See TracChangeset for help on using the changeset viewer.