Make WordPress Core

Changeset 52186


Ignore:
Timestamp:
11/16/2021 06:04:49 PM (3 years ago)
Author:
spacedmonkey
Message:

REST API: Make the templates controller follow core REST patterns.

The templates controller now respects the _fields parameter and filters the response accordingly. The schema has been updated to include all the fields returned. The content.block_version field has been added. The controller now returns WP_Error objects for improved error handling.

Add new unit tests.

Props TimothyBlynJacobs, hellofromtonya, zieladam.
Fixes #54422.

Location:
trunk
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php

    r52062 r52186  
    7171            '/' . $this->rest_base . '/(?P<id>[\/\w-]+)',
    7272            array(
     73                'args'   => array(
     74                    'id' => array(
     75                        'description' => __( 'The id of a template' ),
     76                        'type'        => 'string',
     77                    ),
     78                ),
    7379                array(
    7480                    'methods'             => WP_REST_Server::READABLE,
     
    7682                    'permission_callback' => array( $this, 'get_item_permissions_check' ),
    7783                    'args'                => array(
    78                         'id' => array(
    79                             'description' => __( 'The id of a template' ),
    80                             'type'        => 'string',
    81                         ),
     84                        'context' => $this->get_context_param( array( 'default' => 'view' ) ),
    8285                    ),
    8386                ),
     
    232235        if ( isset( $request['source'] ) && 'theme' === $request['source'] ) {
    233236            wp_delete_post( $template->wp_id, true );
    234             return $this->prepare_item_for_response( get_block_file_template( $request['id'], $this->post_type ), $request );
     237            $request->set_param( 'context', 'edit' );
     238
     239            $template = get_block_template( $request['id'], $this->post_type );
     240            $response = $this->prepare_item_for_response( $template, $request );
     241
     242            return rest_ensure_response( $response );
    235243        }
    236244
     
    242250            $result = wp_insert_post( wp_slash( (array) $changes ), true );
    243251        }
     252
    244253        if ( is_wp_error( $result ) ) {
     254            if ( 'db_update_error' === $result->get_error_code() ) {
     255                $result->add_data( array( 'status' => 500 ) );
     256            } else {
     257                $result->add_data( array( 'status' => 400 ) );
     258            }
    245259            return $result;
    246260        }
     
    252266        }
    253267
    254         return $this->prepare_item_for_response(
    255             get_block_template( $request['id'], $this->post_type ),
    256             $request
    257         );
     268        $request->set_param( 'context', 'edit' );
     269
     270        $response = $this->prepare_item_for_response( $template, $request );
     271
     272        return rest_ensure_response( $response );
    258273    }
    259274
     
    279294     */
    280295    public function create_item( $request ) {
    281         $changes            = $this->prepare_item_for_database( $request );
    282         $changes->post_name = $request['slug'];
    283         $result             = wp_insert_post( wp_slash( (array) $changes ), true );
    284         if ( is_wp_error( $result ) ) {
    285             return $result;
    286         }
    287         $posts = get_block_templates( array( 'wp_id' => $result ), $this->post_type );
     296        $prepared_post            = $this->prepare_item_for_database( $request );
     297        $prepared_post->post_name = $request['slug'];
     298        $post_id                  = wp_insert_post( wp_slash( (array) $prepared_post ), true );
     299        if ( is_wp_error( $post_id ) ) {
     300            if ( 'db_insert_error' === $post_id->get_error_code() ) {
     301                $post_id->add_data( array( 'status' => 500 ) );
     302            } else {
     303                $post_id->add_data( array( 'status' => 400 ) );
     304            }
     305
     306            return $post_id;
     307        }
     308        $posts = get_block_templates( array( 'wp_id' => $post_id ), $this->post_type );
    288309        if ( ! count( $posts ) ) {
    289             return new WP_Error( 'rest_template_insert_error', __( 'No templates exist with that id.' ) );
     310            return new WP_Error( 'rest_template_insert_error', __( 'No templates exist with that id.' ), array( 'status' => 400 ) );
    290311        }
    291312        $id            = $posts[0]->id;
     
    296317        }
    297318
    298         return $this->prepare_item_for_response(
    299             get_block_template( $id, $this->post_type ),
    300             $request
    301         );
     319        $response = $this->prepare_item_for_response( $template, $request );
     320        $response = rest_ensure_response( $response );
     321
     322        $response->set_status( 201 );
     323        $response->header( 'Location', rest_url( sprintf( '%s/%s/%s', $this->namespace, $this->rest_base, $template->id ) ) );
     324
     325        return $response;
    302326    }
    303327
     
    334358        $force = (bool) $request['force'];
    335359
     360        $request->set_param( 'context', 'edit' );
     361
    336362        // If we're forcing, then delete permanently.
    337363        if ( $force ) {
    338364            $previous = $this->prepare_item_for_response( $template, $request );
    339             wp_delete_post( $id, true );
     365            $result   = wp_delete_post( $id, true );
    340366            $response = new WP_REST_Response();
    341367            $response->set_data(
     
    345371                )
    346372            );
    347 
    348             return $response;
    349         }
    350 
    351         // Otherwise, only trash if we haven't already.
    352         if ( 'trash' === $template->status ) {
     373        } else {
     374            // Otherwise, only trash if we haven't already.
     375            if ( 'trash' === $template->status ) {
     376                return new WP_Error(
     377                    'rest_template_already_trashed',
     378                    __( 'The template has already been deleted.' ),
     379                    array( 'status' => 410 )
     380                );
     381            }
     382
     383            // (Note that internally this falls through to `wp_delete_post()`
     384            // if the Trash is disabled.)
     385            $result           = wp_trash_post( $id );
     386            $template->status = 'trash';
     387            $response         = $this->prepare_item_for_response( $template, $request );
     388        }
     389
     390        if ( ! $result ) {
    353391            return new WP_Error(
    354                 'rest_template_already_trashed',
    355                 __( 'The template has already been deleted.' ),
    356                 array( 'status' => 410 )
     392                'rest_cannot_delete',
     393                __( 'The template cannot be deleted.' ),
     394                array( 'status' => 500 )
    357395            );
    358396        }
    359397
    360         wp_trash_post( $id );
    361         $template->status = 'trash';
    362         return $this->prepare_item_for_response( $template, $request );
     398        return $response;
    363399    }
    364400
     
    393429        }
    394430        if ( isset( $request['content'] ) ) {
    395             $changes->post_content = $request['content'];
     431            if ( is_string( $request['content'] ) ) {
     432                $changes->post_content = $request['content'];
     433            } elseif ( isset( $request['content']['raw'] ) ) {
     434                $changes->post_content = $request['content']['raw'];
     435            }
    396436        } elseif ( null !== $template && 'custom' !== $template->source ) {
    397437            $changes->post_content = $template->content;
    398438        }
    399439        if ( isset( $request['title'] ) ) {
    400             $changes->post_title = $request['title'];
     440            if ( is_string( $request['title'] ) ) {
     441                $changes->post_title = $request['title'];
     442            } elseif ( ! empty( $request['title']['raw'] ) ) {
     443                $changes->post_title = $request['title']['raw'];
     444            }
    401445        } elseif ( null !== $template && 'custom' !== $template->source ) {
    402446            $changes->post_title = $template->title;
     
    434478        // Restores the more descriptive, specific name for use within this method.
    435479        $template = $item;
    436         $result   = array(
    437             'id'             => $template->id,
    438             'theme'          => $template->theme,
    439             'content'        => array( 'raw' => $template->content ),
    440             'slug'           => $template->slug,
    441             'source'         => $template->source,
    442             'type'           => $template->type,
    443             'description'    => $template->description,
    444             'title'          => array(
    445                 'raw'      => $template->title,
    446                 'rendered' => $template->title,
    447             ),
    448             'status'         => $template->status,
    449             'wp_id'          => $template->wp_id,
    450             'has_theme_file' => $template->has_theme_file,
    451         );
    452 
    453         if ( 'wp_template_part' === $template->type ) {
    454             $result['area'] = $template->area;
    455         }
    456 
    457         $result = $this->add_additional_fields_to_object( $result, $request );
    458 
    459         $response = rest_ensure_response( $result );
    460         $links    = $this->prepare_links( $template->id );
     480
     481        $fields = $this->get_fields_for_response( $request );
     482
     483        // Base fields for every template.
     484        $data = array();
     485
     486        if ( rest_is_field_included( 'id', $fields ) ) {
     487            $data['id'] = $template->id;
     488        }
     489
     490        if ( rest_is_field_included( 'theme', $fields ) ) {
     491            $data['theme'] = $template->theme;
     492        }
     493
     494        if ( rest_is_field_included( 'content', $fields ) ) {
     495            $data['content'] = array();
     496        }
     497        if ( rest_is_field_included( 'content.raw', $fields ) ) {
     498            $data['content']['raw'] = $template->content;
     499        }
     500
     501        if ( rest_is_field_included( 'content.block_version', $fields ) ) {
     502            $data['content']['block_version'] = block_version( $template->content );
     503        }
     504
     505        if ( rest_is_field_included( 'slug', $fields ) ) {
     506            $data['slug'] = $template->slug;
     507        }
     508
     509        if ( rest_is_field_included( 'source', $fields ) ) {
     510            $data['source'] = $template->source;
     511        }
     512
     513        if ( rest_is_field_included( 'type', $fields ) ) {
     514            $data['type'] = $template->type;
     515        }
     516
     517        if ( rest_is_field_included( 'description', $fields ) ) {
     518            $data['description'] = $template->description;
     519        }
     520
     521        if ( rest_is_field_included( 'title', $fields ) ) {
     522            $data['title'] = array();
     523        }
     524
     525        if ( rest_is_field_included( 'title.raw', $fields ) ) {
     526            $data['title']['raw'] = $template->title;
     527        }
     528
     529        if ( rest_is_field_included( 'title.rendered', $fields ) ) {
     530            if ( $template->wp_id ) {
     531                /** This filter is documented in wp-includes/post-template.php */
     532                $data['title']['rendered'] = apply_filters( 'the_title', $template->title, $template->wp_id );
     533            } else {
     534                $data['title']['rendered'] = $template->title;
     535            }
     536        }
     537
     538        if ( rest_is_field_included( 'status', $fields ) ) {
     539            $data['status'] = $template->status;
     540        }
     541
     542        if ( rest_is_field_included( 'wp_id', $fields ) ) {
     543            $data['wp_id'] = (int) $template->wp_id;
     544        }
     545
     546        if ( rest_is_field_included( 'has_theme_file', $fields ) ) {
     547            $data['has_theme_file'] = (bool) $template->has_theme_file;
     548        }
     549
     550        if ( rest_is_field_included( 'area', $fields ) && 'wp_template_part' === $template->type ) {
     551            $data['area'] = $template->area;
     552        }
     553
     554        $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
     555        $data    = $this->add_additional_fields_to_object( $data, $request );
     556        $data    = $this->filter_response_by_context( $data, $context );
     557
     558        // Wrap the data in a response object.
     559        $response = rest_ensure_response( $data );
     560
     561        $links = $this->prepare_links( $template->id );
    461562        $response->add_links( $links );
    462563        if ( ! empty( $links['self']['href'] ) ) {
     
    531632    public function get_collection_params() {
    532633        return array(
    533             'context'   => $this->get_context_param(),
     634            'context'   => $this->get_context_param( array( 'default' => 'view' ) ),
    534635            'wp_id'     => array(
    535636                'description' => __( 'Limit to the specified post id.' ),
     
    584685                    'context'     => array( 'embed', 'view', 'edit' ),
    585686                ),
     687                'type'           => array(
     688                    'description' => __( 'Type of template.' ),
     689                    'type'        => 'string',
     690                    'context'     => array( 'embed', 'view', 'edit' ),
     691                ),
    586692                'source'         => array(
    587693                    'description' => __( 'Source of template' ),
     
    595701                    'default'     => '',
    596702                    'context'     => array( 'embed', 'view', 'edit' ),
     703                    'properties'  => array(
     704                        'raw'           => array(
     705                            'description' => __( 'Content for the template, as it exists in the database.' ),
     706                            'type'        => 'string',
     707                            'context'     => array( 'view', 'edit' ),
     708                        ),
     709                        'block_version' => array(
     710                            'description' => __( 'Version of the content block format used by the template.' ),
     711                            'type'        => 'integer',
     712                            'context'     => array( 'edit' ),
     713                            'readonly'    => true,
     714                        ),
     715                    ),
    597716                ),
    598717                'title'          => array(
     
    601720                    'default'     => '',
    602721                    'context'     => array( 'embed', 'view', 'edit' ),
     722                    'properties'  => array(
     723                        'raw'      => array(
     724                            'description' => __( 'Title for the template, as it exists in the database.' ),
     725                            'type'        => 'string',
     726                            'context'     => array( 'view', 'edit', 'embed' ),
     727                        ),
     728                        'rendered' => array(
     729                            'description' => __( 'HTML title for the template, transformed for display.' ),
     730                            'type'        => 'string',
     731                            'context'     => array( 'view', 'edit', 'embed' ),
     732                            'readonly'    => true,
     733                        ),
     734                    ),
    603735                ),
    604736                'description'    => array(
     
    611743                    'description' => __( 'Status of template.' ),
    612744                    'type'        => 'string',
     745                    'enum'        => array_keys( get_post_stati( array( 'internal' => false ) ) ),
    613746                    'default'     => 'publish',
    614747                    'context'     => array( 'embed', 'view', 'edit' ),
  • trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php

    r52185 r52186  
    77 */
    88
    9 class WP_REST_Template_Controller_Test extends WP_Test_REST_Controller_Testcase {
     9/**
     10 * Tests for REST API for templates.
     11 *
     12 * @covers WP_REST_Templates_Controller
     13 *
     14 * @group restapi
     15 */
     16class Tests_REST_WpRestTemplatesController extends WP_Test_REST_Controller_Testcase {
    1017    /**
    1118     * @var int
     
    5461    }
    5562
     63    /**
     64     * @covers WP_REST_Templates_Controller::get_context_param
     65     */
    5666    public function test_context_param() {
    57         // TODO: Implement test_context_param() method.
    58     }
    59 
     67        // Collection.
     68        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates' );
     69        $response = rest_get_server()->dispatch( $request );
     70        $data     = $response->get_data();
     71        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     72        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     73        // Single.
     74        $request  = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates/default//my_template' );
     75        $response = rest_get_server()->dispatch( $request );
     76        $data     = $response->get_data();
     77        $this->assertSame( 'view', $data['endpoints'][0]['args']['context']['default'] );
     78        $this->assertSame( array( 'view', 'embed', 'edit' ), $data['endpoints'][0]['args']['context']['enum'] );
     79    }
     80
     81    /**
     82     * @covers WP_REST_Templates_Controller::get_items
     83     */
    6084    public function test_get_items() {
    61         function find_and_normalize_template_by_id( $templates, $id ) {
    62             foreach ( $templates as $template ) {
    63                 if ( $template['id'] === $id ) {
    64                     unset( $template['content'] );
    65                     unset( $template['_links'] );
    66                     return $template;
    67                 }
    68             }
    69 
    70             return null;
    71         }
    72 
    73         wp_set_current_user( 0 );
    74         $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
    75         $response = rest_get_server()->dispatch( $request );
    76         $this->assertErrorResponse( 'rest_cannot_manage_templates', $response, 401 );
    77 
    7885        wp_set_current_user( self::$admin_id );
    7986        $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
     
    97104                'has_theme_file' => false,
    98105            ),
    99             find_and_normalize_template_by_id( $data, 'default//my_template' )
    100         );
    101     }
    102 
     106            $this->find_and_normalize_template_by_id( $data, 'default//my_template' )
     107        );
     108    }
     109
     110    /**
     111     * @covers WP_REST_Templates_Controller::get_items
     112     */
     113    public function test_get_items_no_permission() {
     114        wp_set_current_user( 0 );
     115        $request  = new WP_REST_Request( 'GET', '/wp/v2/templates' );
     116        $response = rest_get_server()->dispatch( $request );
     117        $this->assertErrorResponse( 'rest_cannot_manage_templates', $response, 401 );
     118    }
     119
     120    /**
     121     * @covers WP_REST_Templates_Controller::get_item
     122     */
    103123    public function test_get_item() {
    104124        wp_set_current_user( self::$admin_id );
     
    129149    }
    130150
     151    /**
     152     * @ticket 54422
     153     * @covers WP_REST_Templates_Controller::create_item
     154     */
    131155    public function test_create_item() {
    132156        wp_set_current_user( self::$admin_id );
     
    167191    }
    168192
     193    /**
     194     * @ticket 54422
     195     * @covers WP_REST_Templates_Controller::create_item
     196     */
     197    public function test_create_item_raw() {
     198        wp_set_current_user( self::$admin_id );
     199        $request = new WP_REST_Request( 'POST', '/wp/v2/templates' );
     200        $request->set_body_params(
     201            array(
     202                'slug'        => 'my_custom_template_raw',
     203                'description' => 'Just a description',
     204                'title'       => array(
     205                    'raw' => 'My Template',
     206                ),
     207                'content'     => array(
     208                    'raw' => 'Content',
     209                ),
     210            )
     211        );
     212        $response = rest_get_server()->dispatch( $request );
     213        $data     = $response->get_data();
     214        unset( $data['_links'] );
     215        unset( $data['wp_id'] );
     216
     217        $this->assertSame(
     218            array(
     219                'id'             => 'default//my_custom_template_raw',
     220                'theme'          => 'default',
     221                'content'        => array(
     222                    'raw' => 'Content',
     223                ),
     224                'slug'           => 'my_custom_template_raw',
     225                'source'         => 'custom',
     226                'type'           => 'wp_template',
     227                'description'    => 'Just a description',
     228                'title'          => array(
     229                    'raw'      => 'My Template',
     230                    'rendered' => 'My Template',
     231                ),
     232                'status'         => 'publish',
     233                'has_theme_file' => false,
     234            ),
     235            $data
     236        );
     237    }
     238
     239    /**
     240     * @covers WP_REST_Templates_Controller::update_item
     241     */
    169242    public function test_update_item() {
    170243        wp_set_current_user( self::$admin_id );
     
    181254    }
    182255
     256    /**
     257     * @covers WP_REST_Templates_Controller::update_item
     258     */
     259    public function test_update_item_raw() {
     260        wp_set_current_user( self::$admin_id );
     261        $request = new WP_REST_Request( 'PUT', '/wp/v2/templates/default//my_template' );
     262        $request->set_body_params(
     263            array(
     264                'title' => array( 'raw' => 'My new raw Index Title' ),
     265            )
     266        );
     267        $response = rest_get_server()->dispatch( $request );
     268        $data     = $response->get_data();
     269        $this->assertSame( 'My new raw Index Title', $data['title']['raw'] );
     270        $this->assertSame( 'custom', $data['source'] );
     271    }
     272
     273    /**
     274     * @covers WP_REST_Templates_Controller::delete_item
     275     */
    183276    public function test_delete_item() {
     277        // Set up template post.
     278        $args    = array(
     279            'post_type'    => 'wp_template',
     280            'post_name'    => 'my_test_template',
     281            'post_title'   => 'My Template',
     282            'post_content' => 'Content',
     283            'post_excerpt' => 'Description of my template.',
     284            'tax_input'    => array(
     285                'wp_theme' => array(
     286                    get_stylesheet(),
     287                ),
     288            ),
     289        );
     290        $post_id = self::factory()->post->create( $args );
     291        wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
     292
     293        wp_set_current_user( self::$admin_id );
     294        $request = new WP_REST_Request( 'DELETE', '/wp/v2/templates/default//my_test_template' );
     295        $request->set_param( 'force', 'false' );
     296        $response = rest_get_server()->dispatch( $request );
     297        $data     = $response->get_data();
     298        $this->assertSame( 'My Template', $data['title']['raw'] );
     299        $this->assertSame( 'trash', $data['status'] );
     300    }
     301
     302    /**
     303     * @covers WP_REST_Templates_Controller::delete_item
     304     */
     305    public function test_delete_item_skip_trash() {
     306        // Set up template post.
     307        $args    = array(
     308            'post_type'    => 'wp_template',
     309            'post_name'    => 'my_test_template',
     310            'post_title'   => 'My Template',
     311            'post_content' => 'Content',
     312            'post_excerpt' => 'Description of my template.',
     313            'tax_input'    => array(
     314                'wp_theme' => array(
     315                    get_stylesheet(),
     316                ),
     317            ),
     318        );
     319        $post_id = self::factory()->post->create( $args );
     320        wp_set_post_terms( $post_id, get_stylesheet(), 'wp_theme' );
     321
     322        wp_set_current_user( self::$admin_id );
     323        $request = new WP_REST_Request( 'DELETE', '/wp/v2/templates/default//my_test_template' );
     324        $request->set_param( 'force', 'true' );
     325        $response = rest_get_server()->dispatch( $request );
     326        $this->assertSame( 200, $response->get_status() );
     327        $data = $response->get_data();
     328        $this->assertTrue( $data['deleted'] );
     329        $this->assertNotEmpty( $data['previous'] );
     330    }
     331
     332    /**
     333     * @covers WP_REST_Templates_Controller::delete_item
     334     */
     335    public function test_delete_item_fail() {
    184336        wp_set_current_user( self::$admin_id );
    185337        $request  = new WP_REST_Request( 'DELETE', '/wp/v2/templates/justrandom//template' );
     
    192344    }
    193345
     346    public function test_prepare_item_limit_fields() {
     347        wp_set_current_user( self::$admin_id );
     348
     349        $endpoint = new WP_REST_Templates_Controller( 'wp_template' );
     350        $request  = new WP_REST_Request( 'GET', '/wp/v2/templates/default//my_template' );
     351        $request->set_param( 'context', 'edit' );
     352        $request->set_param( '_fields', 'id,slug' );
     353        $obj      = get_block_template( 'default//my_template', 'wp_template' );
     354        $response = $endpoint->prepare_item_for_response( $obj, $request );
     355        $this->assertSame(
     356            array(
     357                'id',
     358                'slug',
     359            ),
     360            array_keys( $response->get_data() )
     361        );
     362    }
     363
     364    /**
     365     * @ticket 54422
     366     * @covers WP_REST_Templates_Controller::get_item_schema
     367     */
    194368    public function test_get_item_schema() {
    195         // TODO: Implement test_get_item_schema() method.
    196     }
     369        $request    = new WP_REST_Request( 'OPTIONS', '/wp/v2/templates' );
     370        $response   = rest_get_server()->dispatch( $request );
     371        $data       = $response->get_data();
     372        $properties = $data['schema']['properties'];
     373        $this->assertCount( 11, $properties );
     374        $this->assertArrayHasKey( 'id', $properties );
     375        $this->assertArrayHasKey( 'description', $properties );
     376        $this->assertArrayHasKey( 'slug', $properties );
     377        $this->assertArrayHasKey( 'theme', $properties );
     378        $this->assertArrayHasKey( 'type', $properties );
     379        $this->assertArrayHasKey( 'source', $properties );
     380        $this->assertArrayHasKey( 'content', $properties );
     381        $this->assertArrayHasKey( 'title', $properties );
     382        $this->assertArrayHasKey( 'description', $properties );
     383        $this->assertArrayHasKey( 'status', $properties );
     384        $this->assertArrayHasKey( 'wp_id', $properties );
     385        $this->assertArrayHasKey( 'has_theme_file', $properties );
     386    }
     387
     388    protected function find_and_normalize_template_by_id( $templates, $id ) {
     389        foreach ( $templates as $template ) {
     390            if ( $template['id'] === $id ) {
     391                unset( $template['content'] );
     392                unset( $template['_links'] );
     393                return $template;
     394            }
     395        }
     396
     397        return null;
     398    }
     399
    197400}
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r52184 r52186  
    50015001                                "edit"
    50025002                            ],
     5003                            "default": "view",
    50035004                            "required": false
    50045005                        },
     
    50345035                        "theme": {
    50355036                            "description": "Theme identifier for the template.",
     5037                            "type": "string",
     5038                            "required": false
     5039                        },
     5040                        "type": {
     5041                            "description": "Type of template.",
    50365042                            "type": "string",
    50375043                            "required": false
     
    50445050                                "string"
    50455051                            ],
     5052                            "properties": {
     5053                                "raw": {
     5054                                    "description": "Content for the template, as it exists in the database.",
     5055                                    "type": "string",
     5056                                    "context": [
     5057                                        "view",
     5058                                        "edit"
     5059                                    ]
     5060                                },
     5061                                "block_version": {
     5062                                    "description": "Version of the content block format used by the template.",
     5063                                    "type": "integer",
     5064                                    "context": [
     5065                                        "edit"
     5066                                    ],
     5067                                    "readonly": true
     5068                                }
     5069                            },
    50465070                            "required": false
    50475071                        },
     
    50535077                                "string"
    50545078                            ],
     5079                            "properties": {
     5080                                "raw": {
     5081                                    "description": "Title for the template, as it exists in the database.",
     5082                                    "type": "string",
     5083                                    "context": [
     5084                                        "view",
     5085                                        "edit",
     5086                                        "embed"
     5087                                    ]
     5088                                },
     5089                                "rendered": {
     5090                                    "description": "HTML title for the template, transformed for display.",
     5091                                    "type": "string",
     5092                                    "context": [
     5093                                        "view",
     5094                                        "edit",
     5095                                        "embed"
     5096                                    ],
     5097                                    "readonly": true
     5098                                }
     5099                            },
    50555100                            "required": false
    50565101                        },
     
    50655110                            "description": "Status of template.",
    50665111                            "type": "string",
     5112                            "enum": [
     5113                                "publish",
     5114                                "future",
     5115                                "draft",
     5116                                "pending",
     5117                                "private"
     5118                            ],
    50675119                            "required": false
    50685120                        }
     
    50975149                            "type": "string",
    50985150                            "required": false
     5151                        },
     5152                        "context": {
     5153                            "description": "Scope under which the request is made; determines fields present in response.",
     5154                            "type": "string",
     5155                            "enum": [
     5156                                "view",
     5157                                "embed",
     5158                                "edit"
     5159                            ],
     5160                            "default": "view",
     5161                            "required": false
    50995162                        }
    51005163                    }
     
    51075170                    ],
    51085171                    "args": {
     5172                        "id": {
     5173                            "description": "The id of a template",
     5174                            "type": "string",
     5175                            "required": false
     5176                        },
    51095177                        "slug": {
    51105178                            "description": "Unique slug identifying the template.",
     
    51165184                        "theme": {
    51175185                            "description": "Theme identifier for the template.",
     5186                            "type": "string",
     5187                            "required": false
     5188                        },
     5189                        "type": {
     5190                            "description": "Type of template.",
    51185191                            "type": "string",
    51195192                            "required": false
     
    51255198                                "string"
    51265199                            ],
     5200                            "properties": {
     5201                                "raw": {
     5202                                    "description": "Content for the template, as it exists in the database.",
     5203                                    "type": "string",
     5204                                    "context": [
     5205                                        "view",
     5206                                        "edit"
     5207                                    ]
     5208                                },
     5209                                "block_version": {
     5210                                    "description": "Version of the content block format used by the template.",
     5211                                    "type": "integer",
     5212                                    "context": [
     5213                                        "edit"
     5214                                    ],
     5215                                    "readonly": true
     5216                                }
     5217                            },
    51275218                            "required": false
    51285219                        },
     
    51335224                                "string"
    51345225                            ],
     5226                            "properties": {
     5227                                "raw": {
     5228                                    "description": "Title for the template, as it exists in the database.",
     5229                                    "type": "string",
     5230                                    "context": [
     5231                                        "view",
     5232                                        "edit",
     5233                                        "embed"
     5234                                    ]
     5235                                },
     5236                                "rendered": {
     5237                                    "description": "HTML title for the template, transformed for display.",
     5238                                    "type": "string",
     5239                                    "context": [
     5240                                        "view",
     5241                                        "edit",
     5242                                        "embed"
     5243                                    ],
     5244                                    "readonly": true
     5245                                }
     5246                            },
    51355247                            "required": false
    51365248                        },
     
    51435255                            "description": "Status of template.",
    51445256                            "type": "string",
     5257                            "enum": [
     5258                                "publish",
     5259                                "future",
     5260                                "draft",
     5261                                "pending",
     5262                                "private"
     5263                            ],
    51455264                            "required": false
    51465265                        }
     
    51525271                    ],
    51535272                    "args": {
     5273                        "id": {
     5274                            "description": "The id of a template",
     5275                            "type": "string",
     5276                            "required": false
     5277                        },
    51545278                        "force": {
    51555279                            "type": "boolean",
     
    53725496                            "required": false
    53735497                        },
     5498                        "type": {
     5499                            "description": "Type of template.",
     5500                            "type": "string",
     5501                            "required": false
     5502                        },
    53745503                        "content": {
    53755504                            "description": "Content of template.",
     
    53785507                                "string"
    53795508                            ],
     5509                            "properties": {
     5510                                "raw": {
     5511                                    "description": "Content for the template, as it exists in the database.",
     5512                                    "type": "string",
     5513                                    "context": [
     5514                                        "view",
     5515                                        "edit"
     5516                                    ]
     5517                                },
     5518                                "block_version": {
     5519                                    "description": "Version of the content block format used by the template.",
     5520                                    "type": "integer",
     5521                                    "context": [
     5522                                        "edit"
     5523                                    ],
     5524                                    "readonly": true
     5525                                }
     5526                            },
    53805527                            "required": false
    53815528                        },
     
    53865533                                "string"
    53875534                            ],
     5535                            "properties": {
     5536                                "raw": {
     5537                                    "description": "Title for the template, as it exists in the database.",
     5538                                    "type": "string",
     5539                                    "context": [
     5540                                        "view",
     5541                                        "edit",
     5542                                        "embed"
     5543                                    ]
     5544                                },
     5545                                "rendered": {
     5546                                    "description": "HTML title for the template, transformed for display.",
     5547                                    "type": "string",
     5548                                    "context": [
     5549                                        "view",
     5550                                        "edit",
     5551                                        "embed"
     5552                                    ],
     5553                                    "readonly": true
     5554                                }
     5555                            },
    53885556                            "required": false
    53895557                        },
     
    53965564                            "description": "Status of template.",
    53975565                            "type": "string",
     5566                            "enum": [
     5567                                "publish",
     5568                                "future",
     5569                                "draft",
     5570                                "pending",
     5571                                "private"
     5572                            ],
    53985573                            "required": false
    53995574                        }
     
    54585633                                "edit"
    54595634                            ],
     5635                            "default": "view",
    54605636                            "required": false
    54615637                        },
     
    54915667                        "theme": {
    54925668                            "description": "Theme identifier for the template.",
     5669                            "type": "string",
     5670                            "required": false
     5671                        },
     5672                        "type": {
     5673                            "description": "Type of template.",
    54935674                            "type": "string",
    54945675                            "required": false
     
    55015682                                "string"
    55025683                            ],
     5684                            "properties": {
     5685                                "raw": {
     5686                                    "description": "Content for the template, as it exists in the database.",
     5687                                    "type": "string",
     5688                                    "context": [
     5689                                        "view",
     5690                                        "edit"
     5691                                    ]
     5692                                },
     5693                                "block_version": {
     5694                                    "description": "Version of the content block format used by the template.",
     5695                                    "type": "integer",
     5696                                    "context": [
     5697                                        "edit"
     5698                                    ],
     5699                                    "readonly": true
     5700                                }
     5701                            },
    55035702                            "required": false
    55045703                        },
     
    55105709                                "string"
    55115710                            ],
     5711                            "properties": {
     5712                                "raw": {
     5713                                    "description": "Title for the template, as it exists in the database.",
     5714                                    "type": "string",
     5715                                    "context": [
     5716                                        "view",
     5717                                        "edit",
     5718                                        "embed"
     5719                                    ]
     5720                                },
     5721                                "rendered": {
     5722                                    "description": "HTML title for the template, transformed for display.",
     5723                                    "type": "string",
     5724                                    "context": [
     5725                                        "view",
     5726                                        "edit",
     5727                                        "embed"
     5728                                    ],
     5729                                    "readonly": true
     5730                                }
     5731                            },
    55125732                            "required": false
    55135733                        },
     
    55225742                            "description": "Status of template.",
    55235743                            "type": "string",
     5744                            "enum": [
     5745                                "publish",
     5746                                "future",
     5747                                "draft",
     5748                                "pending",
     5749                                "private"
     5750                            ],
    55245751                            "required": false
    55255752                        },
     
    55595786                            "type": "string",
    55605787                            "required": false
     5788                        },
     5789                        "context": {
     5790                            "description": "Scope under which the request is made; determines fields present in response.",
     5791                            "type": "string",
     5792                            "enum": [
     5793                                "view",
     5794                                "embed",
     5795                                "edit"
     5796                            ],
     5797                            "default": "view",
     5798                            "required": false
    55615799                        }
    55625800                    }
     
    55695807                    ],
    55705808                    "args": {
     5809                        "id": {
     5810                            "description": "The id of a template",
     5811                            "type": "string",
     5812                            "required": false
     5813                        },
    55715814                        "slug": {
    55725815                            "description": "Unique slug identifying the template.",
     
    55785821                        "theme": {
    55795822                            "description": "Theme identifier for the template.",
     5823                            "type": "string",
     5824                            "required": false
     5825                        },
     5826                        "type": {
     5827                            "description": "Type of template.",
    55805828                            "type": "string",
    55815829                            "required": false
     
    55875835                                "string"
    55885836                            ],
     5837                            "properties": {
     5838                                "raw": {
     5839                                    "description": "Content for the template, as it exists in the database.",
     5840                                    "type": "string",
     5841                                    "context": [
     5842                                        "view",
     5843                                        "edit"
     5844                                    ]
     5845                                },
     5846                                "block_version": {
     5847                                    "description": "Version of the content block format used by the template.",
     5848                                    "type": "integer",
     5849                                    "context": [
     5850                                        "edit"
     5851                                    ],
     5852                                    "readonly": true
     5853                                }
     5854                            },
    55895855                            "required": false
    55905856                        },
     
    55955861                                "string"
    55965862                            ],
     5863                            "properties": {
     5864                                "raw": {
     5865                                    "description": "Title for the template, as it exists in the database.",
     5866                                    "type": "string",
     5867                                    "context": [
     5868                                        "view",
     5869                                        "edit",
     5870                                        "embed"
     5871                                    ]
     5872                                },
     5873                                "rendered": {
     5874                                    "description": "HTML title for the template, transformed for display.",
     5875                                    "type": "string",
     5876                                    "context": [
     5877                                        "view",
     5878                                        "edit",
     5879                                        "embed"
     5880                                    ],
     5881                                    "readonly": true
     5882                                }
     5883                            },
    55975884                            "required": false
    55985885                        },
     
    56055892                            "description": "Status of template.",
    56065893                            "type": "string",
     5894                            "enum": [
     5895                                "publish",
     5896                                "future",
     5897                                "draft",
     5898                                "pending",
     5899                                "private"
     5900                            ],
    56075901                            "required": false
    56085902                        },
     
    56195913                    ],
    56205914                    "args": {
     5915                        "id": {
     5916                            "description": "The id of a template",
     5917                            "type": "string",
     5918                            "required": false
     5919                        },
    56215920                        "force": {
    56225921                            "type": "boolean",
     
    58396138                            "required": false
    58406139                        },
     6140                        "type": {
     6141                            "description": "Type of template.",
     6142                            "type": "string",
     6143                            "required": false
     6144                        },
    58416145                        "content": {
    58426146                            "description": "Content of template.",
     
    58456149                                "string"
    58466150                            ],
     6151                            "properties": {
     6152                                "raw": {
     6153                                    "description": "Content for the template, as it exists in the database.",
     6154                                    "type": "string",
     6155                                    "context": [
     6156                                        "view",
     6157                                        "edit"
     6158                                    ]
     6159                                },
     6160                                "block_version": {
     6161                                    "description": "Version of the content block format used by the template.",
     6162                                    "type": "integer",
     6163                                    "context": [
     6164                                        "edit"
     6165                                    ],
     6166                                    "readonly": true
     6167                                }
     6168                            },
    58476169                            "required": false
    58486170                        },
     
    58536175                                "string"
    58546176                            ],
     6177                            "properties": {
     6178                                "raw": {
     6179                                    "description": "Title for the template, as it exists in the database.",
     6180                                    "type": "string",
     6181                                    "context": [
     6182                                        "view",
     6183                                        "edit",
     6184                                        "embed"
     6185                                    ]
     6186                                },
     6187                                "rendered": {
     6188                                    "description": "HTML title for the template, transformed for display.",
     6189                                    "type": "string",
     6190                                    "context": [
     6191                                        "view",
     6192                                        "edit",
     6193                                        "embed"
     6194                                    ],
     6195                                    "readonly": true
     6196                                }
     6197                            },
    58556198                            "required": false
    58566199                        },
     
    58636206                            "description": "Status of template.",
    58646207                            "type": "string",
     6208                            "enum": [
     6209                                "publish",
     6210                                "future",
     6211                                "draft",
     6212                                "pending",
     6213                                "private"
     6214                            ],
    58656215                            "required": false
    58666216                        },
Note: See TracChangeset for help on using the changeset viewer.