Make WordPress Core

Changeset 58452

Timestamp:
06/21/2024 01:04:47 PM (7 weeks ago)
Author:
jorgefilipecosta
Message:

REST API: Add template and template_lock to post types endpoint.

Adds template and template_lock property of the post type to post types REST API endpoint.
This change allows us to fix a bug where the template of a page is not respected when creating a new page on the site editor.

Props jorgefilipecosta, oandregal, timothyblynjacobs, mukesh27.
Fixes #61477.

Location:
trunk
Files:
3 edited

Legend:

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

    r56586 r58452  
    245245        if ( rest_is_field_included( 'rest_namespace', $fields ) ) {
    246246            $data['rest_namespace'] = $namespace;
     247
     248
     249
     250
     251
     252
     253
     254
    247255        }
    248256
     
    408416                    'readonly'    => true,
    409417                ),
     418
     419
     420
     421
     422
     423
     424
     425
     426
     427
     428
     429
     430
    410431            ),
    411432        );
  • trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r56746 r58452  
    7878    }
    7979
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
    80101    public function test_get_item_page() {
    81102        $request  = new WP_REST_Request( 'GET', '/wp/v2/types/page' );
     
    166187        $properties = $data['schema']['properties'];
    167188
    168         $this->assertCount( 14, $properties, 'Schema should have 14 properties' );
     189        $this->assertCount( 1 properties' );
    169190        $this->assertArrayHasKey( 'capabilities', $properties, '`capabilities` should be included in the schema' );
    170191        $this->assertArrayHasKey( 'description', $properties, '`description` should be included in the schema' );
     
    181202        $this->assertArrayHasKey( 'visibility', $properties, '`visibility` should be included in the schema' );
    182203        $this->assertArrayHasKey( 'icon', $properties, '`icon` should be included in the schema' );
     204
     205
    183206    }
    184207
     
    231254        $this->assertSame( $post_type_obj->rest_namespace, $data['rest_namespace'] );
    232255        $this->assertSame( $post_type_obj->has_archive, $data['has_archive'] );
     256
     257
    233258
    234259        $links = test_rest_expand_compact_links( $links );
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r58340 r58452  
    1301513015        "rest_base": "posts",
    1301613016        "rest_namespace": "wp/v2",
     13017
     13018
    1301713019        "_links": {
    1301813020            "collection": [
     
    1304513047        "rest_base": "pages",
    1304613048        "rest_namespace": "wp/v2",
     13049
     13050
    1304713051        "_links": {
    1304813052            "collection": [
     
    1307513079        "rest_base": "media",
    1307613080        "rest_namespace": "wp/v2",
     13081
     13082
    1307713083        "_links": {
    1307813084            "collection": [
     
    1310713113        "rest_base": "menu-items",
    1310813114        "rest_namespace": "wp/v2",
     13115
     13116
    1310913117        "_links": {
    1311013118            "collection": [
     
    1313913147        "rest_base": "blocks",
    1314013148        "rest_namespace": "wp/v2",
     13149
     13150
    1314113151        "_links": {
    1314213152            "collection": [
     
    1316913179        "rest_base": "templates",
    1317013180        "rest_namespace": "wp/v2",
     13181
     13182
    1317113183        "_links": {
    1317213184            "collection": [
     
    1319913211        "rest_base": "template-parts",
    1320013212        "rest_namespace": "wp/v2",
     13213
     13214
    1320113215        "_links": {
    1320213216            "collection": [
     
    1322913243        "rest_base": "global-styles",
    1323013244        "rest_namespace": "wp/v2",
     13245
     13246
    1323113247        "_links": {
    1323213248            "collection": [
     
    1325913275        "rest_base": "navigation",
    1326013276        "rest_namespace": "wp/v2",
     13277
     13278
    1326113279        "_links": {
    1326213280            "collection": [
     
    1328913307        "rest_base": "font-families",
    1329013308        "rest_namespace": "wp/v2",
     13309
     13310
    1329113311        "_links": {
    1329213312            "collection": [
     
    1331913339        "rest_base": "font-families/(?P<font_family_id>[\\d]+)/font-faces",
    1332013340        "rest_namespace": "wp/v2",
     13341
     13342
    1332113343        "_links": {
    1332213344            "collection": [
     
    1335313375    ],
    1335413376    "rest_base": "posts",
    13355     "rest_namespace": "wp/v2"
     13377    "rest_namespace": "wp/v2",
     13378    "template": [],
     13379    "template_lock": false
    1335613380};
    1335713381
Note: See TracChangeset for help on using the changeset viewer.