On this page
heartbeat_autosave( array $response, array $data ): array
Performs autosave with heartbeat.
Parameters
$responsearray Required-
The Heartbeat response.
$dataarray Required-
The $_POST data sent.
Return
array The Heartbeat response.
Source
File: wp-admin/includes/misc.php. View all references
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;
}
Related
Uses
| Uses | Description |
|---|---|
| wp_autosave() wp-admin/includes/post.php | Saves a post submitted with XHR. |
| date_i18n() wp-includes/functions.php | Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Changelog
| Version | Description |
|---|---|
| 3.9.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/heartbeat_autosave