heartbeat_autosave

Autosave with heartbeat.

Description

(array) heartbeat_autosave( (array) $response, (array) $data ); 

Returns (array)

The Heartbeat response.

Parameters (2)

0. $response (array)
The Heartbeat response.
1. $data (array)
The $_POST data sent.

Usage

  1. if ( !function_exists( 'heartbeat_autosave' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/misc.php'; 
  3.  
  4. // The Heartbeat response. 
  5. $response = array(); 
  6.  
  7. // The $_POST data sent. 
  8. $data = array(); 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = heartbeat_autosave($response, $data); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/misc.php  
  1. function heartbeat_autosave( $response, $data ) { 
  2. if ( ! empty( $data['wp_autosave'] ) ) { 
  3. $saved = wp_autosave( $data['wp_autosave'] ); 
  4.  
  5. if ( is_wp_error( $saved ) ) { 
  6. $response['wp_autosave'] = array( 'success' => false, 'message' => $saved->get_error_message() ); 
  7. } elseif ( empty( $saved ) ) { 
  8. $response['wp_autosave'] = array( 'success' => false, 'message' => __( 'Error while saving.' ) ); 
  9. } else { 
  10. /** translators: draft saved date format, see https://secure.php.net/date */ 
  11. $draft_saved_date_format = __( 'g:i:s a' ); 
  12. /** translators: %s: date and time */ 
  13. $response['wp_autosave'] = array( 'success' => true, 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ) ); 
  14.  
  15. return $response;