Make WordPress Core

Changeset 54273


Ignore:
Timestamp:
09/21/2022 12:27:33 PM (19 months ago)
Author:
jorgefilipecosta
Message:

Editor: Add has_archive property to the post types REST endpoint.

Backports PHP changes in WordPress/gutenberg#42746 to the core. Adds a has_archive field to the post types endpoint.

Props mcsf, ntsekouras, oandregal.
See #56467.

Location:
trunk
Files:
3 edited

Legend:

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

    r54269 r54273  
    197197        if ( rest_is_field_included( 'hierarchical', $fields ) ) {
    198198            $data['hierarchical'] = $post_type->hierarchical;
     199        }
     200
     201        if ( rest_is_field_included( 'hierarchical', $fields ) ) {
     202            $data['has_archive'] = $post_type->has_archive;
    199203        }
    200204
     
    354358                    'readonly'    => true,
    355359                ),
     360                'has_archive'    => array(
     361                    'description' => __( 'If the value is a string, the value will be used as the archive slug. If the value is false the post type has no archive.' ),
     362                    'type'        => array( 'string', 'boolean' ),
     363                    'context'     => array( 'view', 'edit' ),
     364                    'readonly'    => true,
     365                ),
    356366                'taxonomies'     => array(
    357367                    'description' => __( 'Taxonomies associated with post type.' ),
  • trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r54269 r54273  
    168168        $properties = $data['schema']['properties'];
    169169
    170         $this->assertCount( 13, $properties, 'Schema should have 13 properties' );
     170        $this->assertCount( 14, $properties, 'Schema should have 14 properties' );
    171171        $this->assertArrayHasKey( 'capabilities', $properties, '`capabilities` should be included in the schema' );
    172172        $this->assertArrayHasKey( 'description', $properties, '`description` should be included in the schema' );
     
    177177        $this->assertArrayHasKey( 'slug', $properties, '`slug` should be included in the schema' );
    178178        $this->assertArrayHasKey( 'supports', $properties, '`supports` should be included in the schema' );
     179        $this->assertArrayHasKey( 'has_archive', $properties, '`has_archive` should be included in the schema' );
    179180        $this->assertArrayHasKey( 'taxonomies', $properties, '`taxonomies` should be included in the schema' );
    180181        $this->assertArrayHasKey( 'rest_base', $properties, '`rest_base` should be included in the schema' );
     
    231232        $this->assertSame( $post_type_obj->rest_base, $data['rest_base'] );
    232233        $this->assertSame( $post_type_obj->rest_namespace, $data['rest_namespace'] );
     234        $this->assertSame( $post_type_obj->has_archive, $data['has_archive'] );
    233235
    234236        $links = test_rest_expand_compact_links( $links );
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r54269 r54273  
    1166411664        "description": "",
    1166511665        "hierarchical": false,
     11666        "has_archive": false,
    1166611667        "name": "Posts",
    1166711668        "slug": "post",
     
    1169611697        "description": "",
    1169711698        "hierarchical": true,
     11699        "has_archive": false,
    1169811700        "name": "Pages",
    1169911701        "slug": "page",
     
    1172511727        "description": "",
    1172611728        "hierarchical": false,
     11729        "has_archive": false,
    1172711730        "name": "Media",
    1172811731        "slug": "attachment",
     
    1175411757        "description": "",
    1175511758        "hierarchical": false,
     11759        "has_archive": false,
    1175611760        "name": "Navigation Menu Items",
    1175711761        "slug": "nav_menu_item",
     
    1178511789        "description": "",
    1178611790        "hierarchical": false,
     11791        "has_archive": false,
    1178711792        "name": "Reusable blocks",
    1178811793        "slug": "wp_block",
     
    1181411819        "description": "Templates to include in your theme.",
    1181511820        "hierarchical": false,
     11821        "has_archive": false,
    1181611822        "name": "Templates",
    1181711823        "slug": "wp_template",
     
    1184311849        "description": "Template parts to include in your templates.",
    1184411850        "hierarchical": false,
     11851        "has_archive": false,
    1184511852        "name": "Template Parts",
    1184611853        "slug": "wp_template_part",
     
    1187211879        "description": "Navigation menus that can be inserted into your site.",
    1187311880        "hierarchical": false,
     11881        "has_archive": false,
    1187411882        "name": "Navigation Menus",
    1187511883        "slug": "wp_navigation",
     
    1190311911    "description": "",
    1190411912    "hierarchical": false,
     11913    "has_archive": false,
    1190511914    "name": "Posts",
    1190611915    "slug": "post",
Note: See TracChangeset for help on using the changeset viewer.