WordPress Version: 3.1
/**
* The REST API autosave endpoint doesn't save meta, so we can use the
* `wp_creating_autosave` when it updates an exiting autosave, and
* `_wp_put_post_revision` when it creates a new autosave.
*
* @since 6.3.0
*
* @param int|array $autosave The autosave ID or array.
*/
function _wp_rest_api_autosave_meta($autosave)
{
// Ensure it's a REST API request.
if (!defined('REST_REQUEST') || !REST_REQUEST) {
return;
}
$body = rest_get_server()->get_raw_data();
$body = json_decode($body, true);
if (!isset($body['meta']['footnotes'])) {
return;
}
// `wp_creating_autosave` passes the array,
// `_wp_put_post_revision` passes the ID.
$id = is_int($autosave) ? $autosave : $autosave['ID'];
if (!$id) {
return;
}
update_post_meta($id, 'footnotes', wp_slash($body['meta']['footnotes']));
}