Make WordPress Core

Ticket #39033: 39033.1.diff

File 39033.1.diff, 3.0 KB (added by rachelbaker, 8 years ago)

Moves the supports key above taxonomies to keep the alpha order

  • src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php

     
    149149                $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
    150150                $taxonomies = wp_list_pluck( $taxonomies, 'name' );
    151151                $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
     152                $supports = get_all_post_type_supports( $post_type->name );
     153
    152154                $data = array(
    153155                        'capabilities' => $post_type->cap,
    154156                        'description'  => $post_type->description,
     
    156158                        'labels'       => $post_type->labels,
    157159                        'name'         => $post_type->label,
    158160                        'slug'         => $post_type->name,
     161                        'supports'     => $supports,
    159162                        'taxonomies'   => array_values( $taxonomies ),
    160163                        'rest_base'    => $base,
    161164                );
     
    239242                                        'context'      => array( 'view', 'edit', 'embed' ),
    240243                                        'readonly'     => true,
    241244                                ),
     245                                'supports'         => array(
     246                                        'description'  => __( 'All features, supported by the post type.' ),
     247                                        'type'         => 'object',
     248                                        'context'      => array( 'edit' ),
     249                                        'readonly'     => true,
     250                                ),
    242251                                'taxonomies'       => array(
    243252                                        'description'  => __( 'Taxonomies associated with post type.' ),
    244253                                        'type'         => 'array',
  • tests/phpunit/tests/rest-api/rest-post-types-controller.php

     
    119119                $response = $this->server->dispatch( $request );
    120120                $data = $response->get_data();
    121121                $properties = $data['schema']['properties'];
    122                 $this->assertEquals( 8, count( $properties ) );
     122                $this->assertEquals( 9, count( $properties ) );
    123123                $this->assertArrayHasKey( 'capabilities', $properties );
    124124                $this->assertArrayHasKey( 'description', $properties );
    125125                $this->assertArrayHasKey( 'hierarchical', $properties );
     
    126126                $this->assertArrayHasKey( 'labels', $properties );
    127127                $this->assertArrayHasKey( 'name', $properties );
    128128                $this->assertArrayHasKey( 'slug', $properties );
     129                $this->assertArrayHasKey( 'supports', $properties );
    129130                $this->assertArrayHasKey( 'taxonomies', $properties );
    130131                $this->assertArrayHasKey( 'rest_base', $properties );
    131132        }
     
    179180                if ( 'edit' === $context ) {
    180181                        $this->assertEquals( $post_type_obj->cap, $data['capabilities'] );
    181182                        $this->assertEquals( $post_type_obj->labels, $data['labels'] );
     183                        $this->assertEquals( get_all_post_type_supports( $post_type_obj->name ), $data['supports'] );
    182184                } else {
    183185                        $this->assertFalse( isset( $data['capabilities'] ) );
    184186                        $this->assertFalse( isset( $data['labels'] ) );
     187                        $this->assertFalse( isset( $data['supports'] ) );
    185188                }
    186189        }
    187190