Make WordPress Core

Changeset 43038 for branches/4.9


Ignore:
Timestamp:
04/30/2018 04:30:23 AM (8 years ago)
Author:
SergeyBiryukov
Message:

REST API: Include viewable attribute on Post Type resource for edit context.

For the block editor to be able to expose the Preview button correctly, it needs to know the is_post_type_viewable() setting, this change adds it to the Post Type response.

Props danielbachhuber.
Merges [43007] to the 4.9 branch.
Fixes #43739.

Location:
branches/4.9
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

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

    r41731 r43038  
    156156                        'description'  => $post_type->description,
    157157                        'hierarchical' => $post_type->hierarchical,
     158                        'viewable'     => is_post_type_viewable( $post_type ),
    158159                        'labels'       => $post_type->labels,
    159160                        'name'         => $post_type->label,
     
    224225                                        'readonly'     => true,
    225226                                ),
     227                                'viewable'         => array(
     228                                        'description'  => __( 'Whether or not the post type can be viewed.' ),
     229                                        'type'         => 'boolean',
     230                                        'context'      => array( 'edit' ),
     231                                        'readonly'     => true,
     232                                ),
    226233                                'labels'           => array(
    227234                                        'description'  => __( 'Human-readable labels for the post type for various contexts.' ),
  • branches/4.9/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r41176 r43038  
    129129                $data = $response->get_data();
    130130                $properties = $data['schema']['properties'];
    131                 $this->assertEquals( 9, count( $properties ) );
     131                $this->assertEquals( 10, count( $properties ) );
    132132                $this->assertArrayHasKey( 'capabilities', $properties );
    133133                $this->assertArrayHasKey( 'description', $properties );
    134134                $this->assertArrayHasKey( 'hierarchical', $properties );
     135                $this->assertArrayHasKey( 'viewable', $properties );
    135136                $this->assertArrayHasKey( 'labels', $properties );
    136137                $this->assertArrayHasKey( 'name', $properties );
     
    190191                        $this->assertEquals( $post_type_obj->cap, $data['capabilities'] );
    191192                        $this->assertEquals( $post_type_obj->labels, $data['labels'] );
     193                        if ( in_array( $post_type_obj->name, array( 'post', 'page' ), true ) ) {
     194                                $viewable = true;
     195                        } else {
     196                                $viewable = is_post_type_viewable( $post_type_obj );
     197                        }
     198                        $this->assertEquals( $viewable, $data['viewable'] );
    192199                        $this->assertEquals( get_all_post_type_supports( $post_type_obj->name ), $data['supports'] );
    193200                } else {
    194201                        $this->assertFalse( isset( $data['capabilities'] ) );
     202                        $this->assertFalse( isset( $data['viewable'] ) );
    195203                        $this->assertFalse( isset( $data['labels'] ) );
    196204                        $this->assertFalse( isset( $data['supports'] ) );
Note: See TracChangeset for help on using the changeset viewer.