wp_add_footnotes_revisions_to_post_meta

The timeline below displays how wordpress function wp_add_footnotes_revisions_to_post_meta has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 3.1

/**
 * This is a specific fix for the REST API. The REST API doesn't update
 * the post and post meta in one go (through `meta_input`). While it
 * does fix the `wp_after_insert_post` hook to be called correctly after
 * updating meta, it does NOT fix hooks such as post_updated and
 * save_post, which are normally also fired after post meta is updated
 * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is
 * added to the `post_updated` action, which means the meta is not
 * available at the time, so we have to add it afterwards through the
 * `"rest_after_insert_{$post_type}"` action.
 *
 * @since 6.3.0
 *
 * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
 *
 * @param WP_Post $post The post object.
 */
function wp_add_footnotes_revisions_to_post_meta($post)
{
    global $wp_temporary_footnote_revision_id;
    if ($wp_temporary_footnote_revision_id) {
        $revision = get_post($wp_temporary_footnote_revision_id);
        if (!$revision) {
            return;
        }
        $post_id = $revision->post_parent;
        // Just making sure we're updating the right revision.
        if ($post->ID === $post_id) {
            $footnotes = get_post_meta($post_id, 'footnotes', true);
            if ($footnotes) {
                // Can't use update_post_meta() because it doesn't allow revisions.
                update_metadata('post', $wp_temporary_footnote_revision_id, 'footnotes', wp_slash($footnotes));
            }
        }
    }
}

WordPress Version: 6.3

/**
 * This is a specific fix for the REST API. The REST API doesn't update
 * the post and post meta in one go (through `meta_input`). While it
 * does fix the `wp_after_insert_post` hook to be called correctly after
 * updating meta, it does NOT fix hooks such as post_updated and
 * save_post, which are normally also fired after post meta is updated
 * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is
 * added to the `post_updated` action, which means the meta is not
 * available at the time, so we have to add it afterwards through the
 * `"rest_after_insert_{$post_type}"` action.
 *
 * @since 6.3.0
 *
 * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
 *
 * @param WP_Post $post The post object.
 */
function wp_add_footnotes_revisions_to_post_meta($post)
{
    global $wp_temporary_footnote_revision_id;
    if ($wp_temporary_footnote_revision_id) {
        $revision = get_post($wp_temporary_footnote_revision_id);
        if (!$revision) {
            return;
        }
        $post_id = $revision->post_parent;
        // Just making sure we're updating the right revision.
        if ($post->ID === $post_id) {
            $footnotes = get_post_meta($post_id, 'footnotes', true);
            if ($footnotes) {
                // Can't use update_post_meta() because it doesn't allow revisions.
                update_metadata('post', $wp_temporary_footnote_revision_id, 'footnotes', $footnotes);
            }
        }
    }
}