WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/22/2014 04:55:37 AM (7 years ago)
Author:
azaozz
Message:

Autosave: refactor autosave.js, use heartbeat for transport and move all "Add/Edit Post" related functionality to post.js. See #25272.

File:
1 edited

Legend:

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

    r26981 r26995  
    10901090}
    10911091
    1092 function wp_ajax_autosave() {
    1093     define( 'DOING_AUTOSAVE', true );
    1094 
    1095     check_ajax_referer( 'autosave', 'autosavenonce' );
    1096 
    1097     if ( ! empty( $_POST['catslist'] ) )
    1098         $_POST['post_category'] = explode( ',', $_POST['catslist'] );
    1099     if ( $_POST['post_type'] == 'page' || empty( $_POST['post_category'] ) )
    1100         unset( $_POST['post_category'] );
    1101 
    1102     $data = '';
    1103     $supplemental = array();
    1104     $id = $revision_id = 0;
    1105 
    1106     $post_id = (int) $_POST['post_id'];
    1107     $_POST['ID'] = $_POST['post_ID'] = $post_id;
    1108     $post = get_post( $post_id );
    1109     if ( empty( $post->ID ) || ! current_user_can( 'edit_post', $post->ID ) )
    1110         wp_die( __( 'You are not allowed to edit this post.' ) );
    1111 
    1112     if ( 'page' == $post->post_type && ! current_user_can( 'edit_page', $post->ID ) )
    1113         wp_die( __( 'You are not allowed to edit this page.' ) );
    1114 
    1115     if ( 'auto-draft' == $post->post_status )
    1116         $_POST['post_status'] = 'draft';
    1117 
    1118     if ( ! empty( $_POST['autosave'] ) ) {
    1119         if ( ! wp_check_post_lock( $post->ID ) && get_current_user_id() == $post->post_author && ( 'auto-draft' == $post->post_status || 'draft' == $post->post_status ) ) {
    1120             // Drafts and auto-drafts are just overwritten by autosave for the same user if the post is not locked
    1121             $id = edit_post();
    1122         } else {
    1123             // Non drafts or other users drafts are not overwritten. The autosave is stored in a special post revision for each user.
    1124             $revision_id = wp_create_post_autosave( $post->ID );
    1125             if ( is_wp_error($revision_id) )
    1126                 $id = $revision_id;
    1127             else
    1128                 $id = $post->ID;
    1129         }
    1130 
    1131         if ( ! is_wp_error($id) ) {
    1132             /* translators: draft saved date format, see http://php.net/date */
    1133             $draft_saved_date_format = __('g:i:s a');
    1134             /* translators: %s: date and time */
    1135             $data = sprintf( __('Draft saved at %s.'), date_i18n( $draft_saved_date_format ) );
    1136         }
    1137     } else {
    1138         if ( ! empty( $_POST['auto_draft'] ) )
    1139             $id = 0; // This tells us it didn't actually save
    1140         else
    1141             $id = $post->ID;
    1142     }
    1143 
    1144     // @todo Consider exposing any errors, rather than having 'Saving draft...'
    1145     $x = new WP_Ajax_Response( array(
    1146         'what' => 'autosave',
    1147         'id' => $id,
    1148         'data' => $data,
    1149         'supplemental' => $supplemental
    1150     ) );
    1151     $x->send();
    1152 }
    1153 
    11541092function wp_ajax_closed_postboxes() {
    11551093    check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' );
Note: See TracChangeset for help on using the changeset viewer.