mirror of
git://develop.git.wordpress.org/
synced 2025-04-11 23:52:01 +02:00
REST API: Add visibility information to the Post Types controller.
Props spacedmonkey, peterwilsoncc. Fixes #54055. git-svn-id: https://develop.svn.wordpress.org/trunk@51959 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9f9c81f567
commit
57ded3c85d
@ -197,6 +197,13 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
||||
$data['hierarchical'] = $post_type->hierarchical;
|
||||
}
|
||||
|
||||
if ( in_array( 'visibility', $fields, true ) ) {
|
||||
$data['visibility'] = array(
|
||||
'show_in_nav_menus' => (bool) $post_type->show_in_nav_menus,
|
||||
'show_ui' => (bool) $post_type->show_ui,
|
||||
);
|
||||
}
|
||||
|
||||
if ( in_array( 'viewable', $fields, true ) ) {
|
||||
$data['viewable'] = is_post_type_viewable( $post_type );
|
||||
}
|
||||
@ -337,6 +344,22 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
||||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'visibility' => array(
|
||||
'description' => __( 'The visibility settings for the post type.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'properties' => array(
|
||||
'show_ui' => array(
|
||||
'description' => __( 'Whether to generate a default UI for managing this post type.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_in_nav_menus' => array(
|
||||
'description' => __( 'Whether to make the post type is available for selection in navigation menus.' ),
|
||||
'type' => 'boolean',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -144,7 +144,7 @@ class WP_Test_REST_Post_Types_Controller extends WP_Test_REST_Controller_Testcas
|
||||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertCount( 10, $properties );
|
||||
$this->assertCount( 11, $properties );
|
||||
$this->assertArrayHasKey( 'capabilities', $properties );
|
||||
$this->assertArrayHasKey( 'description', $properties );
|
||||
$this->assertArrayHasKey( 'hierarchical', $properties );
|
||||
@ -155,6 +155,7 @@ class WP_Test_REST_Post_Types_Controller extends WP_Test_REST_Controller_Testcas
|
||||
$this->assertArrayHasKey( 'supports', $properties );
|
||||
$this->assertArrayHasKey( 'taxonomies', $properties );
|
||||
$this->assertArrayHasKey( 'rest_base', $properties );
|
||||
$this->assertArrayHasKey( 'visibility', $properties );
|
||||
}
|
||||
|
||||
public function test_get_additional_field_registration() {
|
||||
@ -216,6 +217,11 @@ class WP_Test_REST_Post_Types_Controller extends WP_Test_REST_Controller_Testcas
|
||||
$viewable = is_post_type_viewable( $post_type_obj );
|
||||
}
|
||||
$this->assertSame( $viewable, $data['viewable'] );
|
||||
$visibility = array(
|
||||
'show_in_nav_menus' => (bool) $post_type_obj->show_in_nav_menus,
|
||||
'show_ui' => (bool) $post_type_obj->show_ui,
|
||||
);
|
||||
$this->assertSame( $visibility, $data['visibility'] );
|
||||
$this->assertSame( get_all_post_type_supports( $post_type_obj->name ), $data['supports'] );
|
||||
} else {
|
||||
$this->assertArrayNotHasKey( 'capabilities', $data );
|
||||
|
Loading…
x
Reference in New Issue
Block a user