Make WordPress Core


Ignore:
Timestamp:
10/19/2018 01:48:42 PM (6 years ago)
Author:
danielbachhuber
Message:

REST API: Introduce Autosaves controller and endpoint.

  • Adds WP_REST_Autosaves_Controller which extends WP_REST_Revisions_Controller.
  • Autosaves endpoint is registered for all post types except attachment because even post types without revisions enabled are expected to autosave.
  • Because setting the DOING_AUTOSAVE constant pollutes the test suite, autosaves tests are run last. We may want to improve upon this later.

Props adamsilverstein, aduth, azaozz, danielbachhuber, rmccue.
Fixes #43316.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.0/tests/phpunit/tests/rest-api/rest-schema-setup.php

    r43739 r43768  
    9090            '/wp/v2/posts/(?P<parent>[\\d]+)/revisions',
    9191            '/wp/v2/posts/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)',
     92            '/wp/v2/posts/(?P<parent>[\\d]+)/autosaves',
     93            '/wp/v2/posts/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)',
    9294            '/wp/v2/pages',
    9395            '/wp/v2/pages/(?P<id>[\\d]+)',
    9496            '/wp/v2/pages/(?P<parent>[\\d]+)/revisions',
    9597            '/wp/v2/pages/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)',
     98            '/wp/v2/pages/(?P<parent>[\\d]+)/autosaves',
     99            '/wp/v2/pages/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)',
    96100            '/wp/v2/media',
    97101            '/wp/v2/media/(?P<id>[\\d]+)',
     
    156160        $post_revision_id = $post_revisions[ count( $post_revisions ) - 1 ]->ID;
    157161
     162        // Create an autosave.
     163        wp_create_post_autosave(
     164            array(
     165                'post_ID'      => $post_id,
     166                'post_content' => 'Autosave post content.',
     167                'post_type'    => 'post',
     168            )
     169        );
     170
     171
    158172        $page_id = $this->factory->post->create( array(
    159173            'post_type'      => 'page',
     
    173187        $page_revision_id = $page_revisions[ count( $page_revisions ) - 1 ]->ID;
    174188
     189        // Create an autosave.
     190        wp_create_post_autosave(
     191            array(
     192                'post_ID'      => $page_id,
     193                'post_content' => 'Autosave page content.',
     194                'post_type'    => 'page',
     195            )
     196        );
     197
    175198        $tag_id = $this->factory->tag->create( array(
    176199            'name'        => 'REST API Client Fixture: Tag',
     
    259282            ),
    260283            array(
     284                'route' => '/wp/v2/posts/' . $post_id . '/autosaves',
     285                'name'  => 'postAutosaves',
     286            ),
     287            array(
     288                'route' => '/wp/v2/posts/' . $post_id . '/autosaves/' . $post_revision_id,
     289                'name'  => 'autosave',
     290            ),
     291            array(
    261292                'route' => '/wp/v2/pages',
    262293                'name'  => 'PagesCollection',
     
    273304                'route' => '/wp/v2/pages/'. $page_id . '/revisions/' . $page_revision_id,
    274305                'name'  => 'pageRevision',
     306            ),
     307            array(
     308                'route' => '/wp/v2/pages/' . $page_id . '/autosaves',
     309                'name'  => 'pageAutosaves',
     310            ),
     311            array(
     312                'route' => '/wp/v2/pages/' . $page_id . '/autosaves/' . $page_revision_id,
     313                'name'  => 'pageAutosave',
    275314            ),
    276315            array(
Note: See TracChangeset for help on using the changeset viewer.