_wp_rest_api_autosave_meta() – 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.

You appear to be a bot. Output may be restricted

Description

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.

Usage

_wp_rest_api_autosave_meta( $autosave );

Parameters

$autosave
( int|array ) required – The autosave ID or array.

Returns

void

Source

File name: wordpress/wp-includes/blocks/footnotes.php


Lines:

1 to 24 of 24
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'] ) );
}
 

 View on GitHub View on Trac