REST API: Show taxonomy visibility settings.
For Gutenberg and other admin-type interfaces, it's useful to be able to see the visibility settings for taxonomies. Props joehoyle, pento. Fixes #42707. git-svn-id: https://develop.svn.wordpress.org/trunk@42729 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
9377c9a873
commit
1e3781cd71
|
@ -191,6 +191,14 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
'show_cloud' => $taxonomy->show_tagcloud,
|
||||
'hierarchical' => $taxonomy->hierarchical,
|
||||
'rest_base' => $base,
|
||||
'visibility' => array(
|
||||
'public' => (bool) $taxonomy->public,
|
||||
'publicly_queryable' => (bool) $taxonomy->publicly_queryable,
|
||||
'show_admin_column' => (bool) $taxonomy->show_admin_column,
|
||||
'show_in_nav_menus' => (bool) $taxonomy->show_in_nav_menus,
|
||||
'show_in_quick_edit' => (bool) $taxonomy->show_in_quick_edit,
|
||||
'show_ui' => (bool) $taxonomy->show_ui,
|
||||
),
|
||||
);
|
||||
|
||||
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
|
||||
|
@ -295,6 +303,39 @@ class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
|||
'context' => array( 'view', 'edit', 'embed' ),
|
||||
'readonly' => true,
|
||||
),
|
||||
'visibility' => array(
|
||||
'description' => __( 'The visibility settings for the taxomonmy.' ),
|
||||
'type' => 'object',
|
||||
'context' => array( 'edit' ),
|
||||
'readonly' => true,
|
||||
'properties' => array(
|
||||
'public' => array(
|
||||
'description' => 'Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.',
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'publicly_queryable' => array(
|
||||
'description' => 'Whether the taxonomy is publicly queryable.',
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_ui' => array(
|
||||
'description' => 'Whether to generate a default UI for managing this taxonomy.',
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_admin_column' => array(
|
||||
'description' => 'Whether to allow automatic creation of taxonomy columns on associated post-types table.',
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_in_nav_menus' => array(
|
||||
'description' => 'Whether to make the taxonomy available for selection in navigation menus.',
|
||||
'type' => 'boolean',
|
||||
),
|
||||
'show_in_quick_edit' => array(
|
||||
'description' => 'Whether to show the taxonomy in the quick/bulk edit panel.',
|
||||
'type' => 'boolean',
|
||||
),
|
||||
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return $this->add_additional_fields_schema( $schema );
|
||||
|
|
|
@ -123,7 +123,7 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas
|
|||
$this->assertErrorResponse( 'rest_forbidden', $response, 401 );
|
||||
}
|
||||
|
||||
public function test_get_non_public_taxonomy_no_permission() {
|
||||
public function test_get_non_public_taxonomy_no_permission() {
|
||||
wp_set_current_user( self::$contributor_id );
|
||||
register_taxonomy( 'api-private', 'post', array( 'public' => false ) );
|
||||
|
||||
|
@ -167,7 +167,7 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas
|
|||
$response = rest_get_server()->dispatch( $request );
|
||||
$data = $response->get_data();
|
||||
$properties = $data['schema']['properties'];
|
||||
$this->assertEquals( 9, count( $properties ) );
|
||||
$this->assertEquals( 10, count( $properties ) );
|
||||
$this->assertArrayHasKey( 'capabilities', $properties );
|
||||
$this->assertArrayHasKey( 'description', $properties );
|
||||
$this->assertArrayHasKey( 'hierarchical', $properties );
|
||||
|
@ -176,6 +176,7 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas
|
|||
$this->assertArrayHasKey( 'slug', $properties );
|
||||
$this->assertArrayHasKey( 'show_cloud', $properties );
|
||||
$this->assertArrayHasKey( 'types', $properties );
|
||||
$this->assertArrayHasKey( 'visibility', $properties );
|
||||
$this->assertArrayHasKey( 'rest_base', $properties );
|
||||
}
|
||||
|
||||
|
@ -209,10 +210,18 @@ class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcas
|
|||
$this->assertEquals( $tax_obj->cap, $data['capabilities'] );
|
||||
$this->assertEquals( $tax_obj->labels, $data['labels'] );
|
||||
$this->assertEquals( $tax_obj->show_tagcloud, $data['show_cloud'] );
|
||||
|
||||
$this->assertEquals( $tax_obj->public, $data['visibility']['public'] );
|
||||
$this->assertEquals( $tax_obj->publicly_queryable, $data['visibility']['publicly_queryable'] );
|
||||
$this->assertEquals( $tax_obj->show_admin_column, $data['visibility']['show_admin_column'] );
|
||||
$this->assertEquals( $tax_obj->show_in_nav_menus, $data['visibility']['show_in_nav_menus'] );
|
||||
$this->assertEquals( $tax_obj->show_in_quick_edit, $data['visibility']['show_in_quick_edit'] );
|
||||
$this->assertEquals( $tax_obj->show_ui, $data['visibility']['show_ui'] );
|
||||
} else {
|
||||
$this->assertFalse( isset( $data['capabilities'] ) );
|
||||
$this->assertFalse( isset( $data['labels'] ) );
|
||||
$this->assertFalse( isset( $data['show_cloud'] ) );
|
||||
$this->assertFalse( isset( $data['visibility'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue