Make WordPress Core

Changeset 51959


Ignore:
Timestamp:
10/31/2021 05:17:53 AM (5 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Add visibility information to the Post Types controller.

Props spacedmonkey, peterwilsoncc.
Fixes #54055.

Location:
trunk
Files:
2 edited

Legend:

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

    r51786 r51959  
    196196                if ( in_array( 'hierarchical', $fields, true ) ) {
    197197                        $data['hierarchical'] = $post_type->hierarchical;
     198                }
     199
     200                if ( in_array( 'visibility', $fields, true ) ) {
     201                        $data['visibility'] = array(
     202                                'show_in_nav_menus' => (bool) $post_type->show_in_nav_menus,
     203                                'show_ui'           => (bool) $post_type->show_ui,
     204                        );
    198205                }
    199206
    … …  
    338345                                        'readonly'    => true,
    339346                                ),
     347                                'visibility'   => array(
     348                                        'description' => __( 'The visibility settings for the post type.' ),
     349                                        'type'        => 'object',
     350                                        'context'     => array( 'edit' ),
     351                                        'readonly'    => true,
     352                                        'properties'  => array(
     353                                                'show_ui'           => array(
     354                                                        'description' => __( 'Whether to generate a default UI for managing this post type.' ),
     355                                                        'type'        => 'boolean',
     356                                                ),
     357                                                'show_in_nav_menus' => array(
     358                                                        'description' => __( 'Whether to make the post type is available for selection in navigation menus.' ),
     359                                                        'type'        => 'boolean',
     360                                                ),
     361                                        ),
     362                                ),
    340363                        ),
    341364                );
  • trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php

    r51397 r51959  
    145145                $data       = $response->get_data();
    146146                $properties = $data['schema']['properties'];
    147                 $this->assertCount( 10, $properties );
     147                $this->assertCount( 11, $properties );
    148148                $this->assertArrayHasKey( 'capabilities', $properties );
    149149                $this->assertArrayHasKey( 'description', $properties );
    … …  
    156156                $this->assertArrayHasKey( 'taxonomies', $properties );
    157157                $this->assertArrayHasKey( 'rest_base', $properties );
     158                $this->assertArrayHasKey( 'visibility', $properties );
    158159        }
    159160
    … …  
    217218                        }
    218219                        $this->assertSame( $viewable, $data['viewable'] );
     220                        $visibility = array(
     221                                'show_in_nav_menus' => (bool) $post_type_obj->show_in_nav_menus,
     222                                'show_ui'           => (bool) $post_type_obj->show_ui,
     223                        );
     224                        $this->assertSame( $visibility, $data['visibility'] );
    219225                        $this->assertSame( get_all_post_type_supports( $post_type_obj->name ), $data['supports'] );
    220226                } else {
Note: See TracChangeset for help on using the changeset viewer.