Make WordPress Core

09/26/2023 03:30:34 PM (9 months ago)

Revisions: framework for storing post meta revisions.

Enable the storing of post meta in revisions including autosaves and previews:

Add a new argument revisions_enabled to the register_meta function which enables storing meta in revisions.

Add a new wp_post_revision_meta_keys filter which developers can use to control which meta is revisioned - it passes an array of the meta keys with revisions enabled as well as the post type.

Meta keys with revisions enabled are also stored for autosaves, and are restored when a revision or autosave is restored. In addition, meta values are now stored with the autosave revision used for previews. Changes to meta can now be previewed correctly without overwriting the published meta (see #20299) or passing data as a query variable, as the editor currently does to preview changes to the featured image.

Changes to meta with revisions enabled are considered when determining if a new revision should be created. A new revision is created if the meta value has changed since the last revision.

Revisions are now saved on the wp_after_insert_post hook instead of post_updated. The wp_after_insert_post action is fired after post meta has been saved by the REST API which enables attaching meta to the revision. To ensure backwards compatibility with existing action uses, wp_save_post_revision_on_insert function exits early if plugins have removed the previous do_action( 'post_updated', 'wp_save_post_revision' ) call.

Props: alexkingorg, johnbillion, markjaquith, WraithKenny, kovshenin, azaozz, tv-productions, p51labs, mattheu, mikeschroder, Mamaduka, ellatrix, timothyblynjacobs, jakemgold, bookwyrm, ryanduff, mintindeed, wonderboymusic, sanchothefat, westonruter, spacedmonkey, hellofromTonya, drewapicture, adamsilverstein, swisspiddy.
Fixes #20564, #20299.

1 edited


  • trunk/tests/phpunit/tests/rest-api/rest-autosaves-controller.php

    r56548 r56714  
    216216            'date',
    217217            'date_gmt',
     218            'id',
     219            'meta',
    218220            'modified',
    219221            'modified_gmt',
    220             'guid',
    221             'id',
    222222            'parent',
    223223            'slug',
     224            'guid',
    224225            'title',
    225226            'excerpt',
    289290        $data       = $response->get_data();
    290291        $properties = $data['schema']['properties'];
    291         $this->assertCount( 13, $properties );
     292        $this->assertCount( 14, $properties );
    292293        $this->assertArrayHasKey( 'author', $properties );
    293294        $this->assertArrayHasKey( 'content', $properties );
    303304        $this->assertArrayHasKey( 'title', $properties );
    304305        $this->assertArrayHasKey( 'preview_link', $properties );
     306        $this->assertArrayHasKey( 'meta', $properties );
    305307    }
Note: See TracChangeset for help on using the changeset viewer.