Make WordPress Core


Ignore:
Timestamp:
03/16/2013 09:15:43 PM (12 years ago)
Author:
azaozz
Message:

Create one autosave per user rather than a single autosave for all users. Remove unused code from autosave.js and wp_ajax_autosave(). See #23665.

File:
1 edited

Legend:

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

    r23729 r23735  
    10441044
    10451045    $do_autosave = (bool) $_POST['autosave'];
    1046     $do_lock = true;
    10471046    $data = '';
    10481047    $supplemental = array();
    10491048    $id = $revision_id = 0;
    10501049
    1051     /* translators: draft saved date format, see http://php.net/date */
    1052     $draft_saved_date_format = __('g:i:s a');
    1053     /* translators: %s: date and time */
    1054     $message = sprintf( __('Draft saved at %s.'), date_i18n( $draft_saved_date_format ) );
     1050    if ( ! $user_id = get_current_user_id() )
     1051        wp_die('-1');
    10551052
    10561053    $post_id = (int) $_POST['post_id'];
     
    10591056    if ( 'auto-draft' == $post->post_status )
    10601057        $_POST['post_status'] = 'draft';
    1061 
    1062     if ( $last = wp_check_post_lock( $post->ID ) ) {
    1063         // This will change after we have per-user autosaves
    1064         $do_autosave = $do_lock = false;
    1065 
    1066         $last_user = get_userdata( $last );
    1067         $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
    1068         $data = __( 'Autosave disabled.' );
    1069 
    1070         $supplemental['disable_autosave'] = 'disable';
    1071     }
    10721058
    10731059    if ( 'page' == $post->post_type ) {
     
    10801066
    10811067    if ( $do_autosave ) {
    1082         // Drafts and auto-drafts are just overwritten by autosave
    1083         if ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) {
     1068        // Drafts and auto-drafts are just overwritten by autosave for the same user
     1069        if ( $user_id == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
    10841070            $id = edit_post();
    1085         } else { // Non drafts are not overwritten. The autosave is stored in a special post revision.
     1071        } else { // Non drafts are not overwritten. The autosave is stored in a special post revision for each user.
    10861072            $revision_id = wp_create_post_autosave( $post->ID );
    10871073            if ( is_wp_error($revision_id) )
     
    10901076                $id = $post->ID;
    10911077        }
    1092         $data = $message;
     1078
     1079        if ( is_wp_error($id) ) {
     1080            // is_wp_error($id) overwrites $data in WP_Ajax_Response but no point in doing wp_create_nonce('update-post_' . $id) below
     1081            // todo: Needs review. The errors generated in WP_Ajax_Response and parsed with wpAjax.parseAjaxResponse() haven't been used for many years.
     1082            $data = $id;
     1083            $id = 0;
     1084        } else {
     1085            /* translators: draft saved date format, see http://php.net/date */
     1086            $draft_saved_date_format = __('g:i:s a');
     1087            /* translators: %s: date and time */
     1088            $data = sprintf( __('Draft saved at %s.'), date_i18n( $draft_saved_date_format ) );
     1089        }
    10931090    } else {
    10941091        if ( ! empty( $_POST['auto_draft'] ) )
     
    11041101        $supplemental['replace-closedpostboxesnonce'] = wp_create_nonce('closedpostboxes');
    11051102        $supplemental['replace-_ajax_linking_nonce'] = wp_create_nonce( 'internal-linking' );
    1106         if ( $id ) {
    1107             if ( $_POST['post_type'] == 'post' )
    1108                 $supplemental['replace-_wpnonce'] = wp_create_nonce('update-post_' . $id);
    1109             elseif ( $_POST['post_type'] == 'page' )
    1110                 $supplemental['replace-_wpnonce'] = wp_create_nonce('update-page_' . $id);
    1111         }
     1103        if ( $id )
     1104            $supplemental['replace-_wpnonce'] = wp_create_nonce('update-post_' . $id);
    11121105    }
    11131106
Note: See TracChangeset for help on using the changeset viewer.