Make WordPress Core

Ticket #20564: footnotes-from-gb.diff

File footnotes-from-gb.diff, 6.7 KB (added by adamsilverstein, 7 months ago)
  • src/wp-includes/blocks/footnotes.php

    diff --git a/src/wp-includes/blocks/footnotes.php b/src/wp-includes/blocks/footnotes.php
    index 5924db3a19..58f1e86468 100644
    a b  
    99 * Renders the `core/footnotes` block on the server.
    1010 *
    1111 * @since 6.3.0
     12 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    1213 *
    1314 * @param array    $attributes Block attributes.
    1415 * @param string   $content    Block default content.
    function register_block_core_footnotes() { 
    6869                        $post_type,
    6970                        'footnotes',
    7071                        array(
    71                                 'show_in_rest' => true,
    72                                 'single'       => true,
    73                                 'type'         => 'string',
     72                                'show_in_rest'      => true,
     73                                'single'            => true,
     74                                'type'              => 'string',
     75                                'revisions_enabled' => true,
    7476                        )
    7577                );
    7678        }
    add_action( 'init', 'register_block_core_footnotes' ); 
    8789 * Saves the footnotes meta value to the revision.
    8890 *
    8991 * @since 6.3.0
     92 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    9093 *
    9194 * @param int $revision_id The revision ID.
    9295 */
    function wp_save_footnotes_meta( $revision_id ) { 
    102105                }
    103106        }
    104107}
    105 add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );
     108if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
     109        add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );
     110}
    106111
    107112/**
    108113 * Keeps track of the revision ID for "rest_after_insert_{$post_type}".
    109114 *
    110115 * @since 6.3.0
     116 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    111117 *
    112118 * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
    113119 *
    function wp_keep_footnotes_revision_id( $revision_id ) { 
    117123        global $wp_temporary_footnote_revision_id;
    118124        $wp_temporary_footnote_revision_id = $revision_id;
    119125}
    120 add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' );
     126if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
     127        add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' );
     128}
    121129
    122130/**
    123131 * This is a specific fix for the REST API. The REST API doesn't update
    add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' ); 
    131139 * `"rest_after_insert_{$post_type}"` action.
    132140 *
    133141 * @since 6.3.0
     142 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    134143 *
    135144 * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
    136145 *
    function wp_add_footnotes_revisions_to_post_meta( $post ) { 
    160169        }
    161170}
    162171
    163 add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' );
    164 add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' );
     172if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
     173        add_action( 'rest_after_insert_post', 'wp_add_footnotes_revisions_to_post_meta' );
     174        add_action( 'rest_after_insert_page', 'wp_add_footnotes_revisions_to_post_meta' );
     175}
    165176
    166177/**
    167178 * Restores the footnotes meta value from the revision.
    168179 *
    169180 * @since 6.3.0
     181 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    170182 *
    171183 * @param int $post_id     The post ID.
    172184 * @param int $revision_id The revision ID.
    function wp_restore_footnotes_from_revision( $post_id, $revision_id ) { 
    180192                delete_post_meta( $post_id, 'footnotes' );
    181193        }
    182194}
    183 add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );
     195if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
     196        add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );
     197}
    184198
    185199/**
    186  * Adds the footnotes field to the revision.
     200 * Adds the footnotes field to the revisions display.
    187201 *
    188202 * @since 6.3.0
    189203 *
    function wp_add_footnotes_to_revision( $fields ) { 
    197211add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' );
    198212
    199213/**
    200  * Gets the footnotes field from the revision.
     214 * Gets the footnotes field from the revision for the revisions screen.
    201215 *
    202216 * @since 6.3.0
    203217 *
    add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision 
    218232 * `_wp_put_post_revision` when it creates a new autosave.
    219233 *
    220234 * @since 6.3.0
     235 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    221236 *
    222237 * @param int|array $autosave The autosave ID or array.
    223238 */
    function _wp_rest_api_autosave_meta( $autosave ) { 
    242257                return;
    243258        }
    244259
    245         update_post_meta( $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) );
     260        // Can't use update_post_meta() because it doesn't allow revisions.
     261        update_metadata( 'post', $id, 'footnotes', wp_slash( $body['meta']['footnotes'] ) );
     262}
     263
     264if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
     265        // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1.
     266        add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' );
     267        // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398.
     268        // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367.
     269        add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' );
    246270}
    247 // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L391C1-L391C1.
    248 add_action( 'wp_creating_autosave', '_wp_rest_api_autosave_meta' );
    249 // See https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php#L398.
    250 // Then https://github.com/WordPress/wordpress-develop/blob/2103cb9966e57d452c94218bbc3171579b536a40/src/wp-includes/revision.php#L367.
    251 add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' );
    252271
    253272/**
    254273 * This is a workaround for the autosave endpoint returning early if the
    add_action( '_wp_put_post_revision', '_wp_rest_api_autosave_meta' ); 
    261280 * course, this is temporary fix.
    262281 *
    263282 * @since 6.3.0
     283 * @since 6.4.0 Core added post meta revisions, so this is no longer needed.
    264284 *
    265285 * @param WP_Post         $prepared_post The prepared post object.
    266286 * @param WP_REST_Request $request       The request object.
    function _wp_rest_api_force_autosave_difference( $prepared_post, $request ) { 
    282302        $prepared_post->footnotes = '[]';
    283303        return $prepared_post;
    284304}
    285 
    286 add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 );
     305if ( ! function_exists( 'wp_post_revision_meta_keys' ) ) {
     306        add_filter( 'rest_pre_insert_post', '_wp_rest_api_force_autosave_difference', 10, 2 );
     307}