Make WordPress Core


Ignore:
Timestamp:
07/25/2023 03:03:22 PM (17 months ago)
Author:
audrasjb
Message:

Editor: update npm packages with bug fixes for 6.3 RC2.

Includes miscellaneous bug fixes for 6.3 RC12.

Props ramonopoly, audrasjb, swissspidy, peterwilsoncc, joemcgill.
Reviewed by audrasjb, mikeschroder.
Merges [56298] to the 6.3 branch.
Fixes #58804.

Location:
branches/6.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.3

  • branches/6.3/src/wp-includes/blocks/footnotes.php

    r56127 r56305  
    88/**
    99 * Renders the `core/footnotes` block on the server.
     10 *
     11 * @since 6.3.0
    1012 *
    1113 * @param array    $attributes Block attributes.
     
    5860/**
    5961 * Registers the `core/footnotes` block on the server.
     62 *
     63 * @since 6.3.0
    6064 */
    6165function register_block_core_footnotes() {
     
    7983}
    8084add_action( 'init', 'register_block_core_footnotes' );
     85
     86/**
     87 * Saves the footnotes meta value to the revision.
     88 *
     89 * @since 6.3.0
     90 *
     91 * @param int $revision_id The revision ID.
     92 */
     93function wp_save_footnotes_meta( $revision_id ) {
     94    $post_id = wp_is_post_revision( $revision_id );
     95
     96    if ( $post_id ) {
     97        $footnotes = get_post_meta( $post_id, 'footnotes', true );
     98
     99        if ( $footnotes ) {
     100            // Can't use update_post_meta() because it doesn't allow revisions.
     101            update_metadata( 'post', $revision_id, 'footnotes', $footnotes );
     102        }
     103    }
     104}
     105add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );
     106
     107/**
     108 * Keeps track of the revision ID for "rest_after_insert_{$post_type}".
     109 *
     110 * @since 6.3.0
     111 *
     112 * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
     113 *
     114 * @param int $revision_id The revision ID.
     115 */
     116function wp_keep_footnotes_revision_id( $revision_id ) {
     117    global $wp_temporary_footnote_revision_id;
     118    $wp_temporary_footnote_revision_id = $revision_id;
     119}
     120add_action( '_wp_put_post_revision', 'wp_keep_footnotes_revision_id' );
     121
     122/**
     123 * This is a specific fix for the REST API. The REST API doesn't update
     124 * the post and post meta in one go (through `meta_input`). While it
     125 * does fix the `wp_after_insert_post` hook to be called correctly after
     126 * updating meta, it does NOT fix hooks such as post_updated and
     127 * save_post, which are normally also fired after post meta is updated
     128 * in `wp_insert_post()`. Unfortunately, `wp_save_post_revision` is
     129 * added to the `post_updated` action, which means the meta is not
     130 * available at the time, so we have to add it afterwards through the
     131 * `"rest_after_insert_{$post_type}"` action.
     132 *
     133 * @since 6.3.0
     134 *
     135 * @global int $wp_temporary_footnote_revision_id The footnote revision ID.
     136 *
     137 * @param WP_Post $post The post object.
     138 */
     139function wp_add_footnotes_revisions_to_post_meta( $post ) {
     140    global $wp_temporary_footnote_revision_id;
     141
     142    if ( $wp_temporary_footnote_revision_id ) {
     143        $revision = get_post( $wp_temporary_footnote_revision_id );
     144
     145        if ( ! $revision ) {
     146            return;
     147        }
     148
     149        $post_id = $revision->post_parent;
     150
     151        // Just making sure we're updating the right revision.
     152        if ( $post->ID === $post_id ) {
     153            $footnotes = get_post_meta( $post_id, 'footnotes', true );
     154
     155            if ( $footnotes ) {
     156                // Can't use update_post_meta() because it doesn't allow revisions.
     157                update_metadata( 'post', $wp_temporary_footnote_revision_id, 'footnotes', $footnotes );
     158            }
     159        }
     160    }
     161}
     162
     163foreach ( array( 'post', 'page' ) as $post_type ) {
     164    add_action( "rest_after_insert_{$post_type}", 'wp_add_footnotes_revisions_to_post_meta' );
     165}
     166
     167/**
     168 * Restores the footnotes meta value from the revision.
     169 *
     170 * @since 6.3.0
     171 *
     172 * @param int $post_id     The post ID.
     173 * @param int $revision_id The revision ID.
     174 */
     175function wp_restore_footnotes_from_revision( $post_id, $revision_id ) {
     176    $footnotes = get_post_meta( $revision_id, 'footnotes', true );
     177
     178    if ( $footnotes ) {
     179        update_post_meta( $post_id, 'footnotes', $footnotes );
     180    } else {
     181        delete_post_meta( $post_id, 'footnotes' );
     182    }
     183}
     184add_action( 'wp_restore_post_revision', 'wp_restore_footnotes_from_revision', 10, 2 );
     185
     186/**
     187 * Adds the footnotes field to the revision.
     188 *
     189 * @since 6.3.0
     190 *
     191 * @param array $fields The revision fields.
     192 * @return array The revision fields.
     193 */
     194function wp_add_footnotes_to_revision( $fields ) {
     195    $fields['footnotes'] = __( 'Footnotes' );
     196    return $fields;
     197}
     198add_filter( '_wp_post_revision_fields', 'wp_add_footnotes_to_revision' );
     199
     200/**
     201 * Gets the footnotes field from the revision.
     202 *
     203 * @since 6.3.0
     204 *
     205 * @param string $revision_field The field value, but $revision->$field
     206 *                               (footnotes) does not exist.
     207 * @param string $field          The field name, in this case "footnotes".
     208 * @param object $revision       The revision object to compare against.
     209 * @return string The field value.
     210 */
     211function wp_get_footnotes_from_revision( $revision_field, $field, $revision ) {
     212    return get_metadata( 'post', $revision->ID, $field, true );
     213}
     214add_filter( 'wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 );
Note: See TracChangeset for help on using the changeset viewer.