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/misc.php

    r26924 r26995  
    735735            $response['wp-refresh-post-nonces'] = array(
    736736                'replace' => array(
    737                     'autosavenonce' => wp_create_nonce('autosave'),
    738737                    'getpermalinknonce' => wp_create_nonce('getpermalink'),
    739738                    'samplepermalinknonce' => wp_create_nonce('samplepermalink'),
     
    769768}
    770769add_filter( 'heartbeat_settings', 'wp_heartbeat_set_suspension' );
     770
     771/**
     772 * Autosave with heartbeat
     773 *
     774 * @since 3.9
     775 */
     776function heartbeat_autosave( $response, $data ) {
     777    if ( ! empty( $data['wp_autosave'] ) ) {
     778        $saved = wp_autosave( $data['wp_autosave'] );
     779
     780        if ( is_wp_error( $saved ) ) {
     781            $response['wp_autosave'] = array( 'success' => false, 'message' => $saved->get_error_message() );
     782        } elseif ( empty( $saved ) ) {
     783            $response['wp_autosave'] = array( 'success' => false, 'message' => __( 'Error while saving.' ) );
     784        } else {
     785            /* translators: draft saved date format, see http://php.net/date */
     786            $draft_saved_date_format = __( 'g:i:s a' );
     787            /* translators: %s: date and time */
     788            $response['wp_autosave'] = array( 'success' => true, 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ) );
     789        }
     790    }
     791
     792    return $response;
     793}
     794// Run later as we have to set DOING_AUTOSAVE for back-compat
     795add_filter( 'heartbeat_received', 'heartbeat_autosave', 500, 2 );
Note: See TracChangeset for help on using the changeset viewer.