heartbeat_autosave() WordPress Function
The heartbeat_autosave() function in WordPress allows you to automatically save a post or page while you are editing it. This is a great way to make sure that you don't lose any of your work if something happens to your computer or if you accidentally close your browser.
heartbeat_autosave( array $response, array $data ) #
Performs autosave with heartbeat.
Parameters
- $response
(array)(Required)The Heartbeat response.
- $data
(array)(Required)The $_POST data sent.
Return
(array) The Heartbeat response.
Source
File: wp-admin/includes/misc.php
function heartbeat_autosave( $response, $data ) { if ( ! empty( $data['wp_autosave'] ) ) { $saved = wp_autosave( $data['wp_autosave'] ); if ( is_wp_error( $saved ) ) { $response['wp_autosave'] = array( 'success' => false, 'message' => $saved->get_error_message(), ); } elseif ( empty( $saved ) ) { $response['wp_autosave'] = array( 'success' => false, 'message' => __( 'Error while saving.' ), ); } else { /* translators: Draft saved date format, see https://www.php.net/manual/datetime.format.php */ $draft_saved_date_format = __( 'g:i:s a' ); $response['wp_autosave'] = array( 'success' => true, /* translators: %s: Date and time. */ 'message' => sprintf( __( 'Draft saved at %s.' ), date_i18n( $draft_saved_date_format ) ), ); } } return $response; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
3.9.0 | Introduced. |