Make WordPress Core

Changeset 42729


Ignore:
Timestamp:
02/22/2018 12:24:00 AM (9 years ago)
Author:
pento
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r42343 r42729  
    192192                        'hierarchical' => $taxonomy->hierarchical,
    193193                        'rest_base'    => $base,
     194                        'visibility'   => array(
     195                                'public'             => (bool) $taxonomy->public,
     196                                'publicly_queryable' => (bool) $taxonomy->publicly_queryable,
     197                                'show_admin_column'  => (bool) $taxonomy->show_admin_column,
     198                                'show_in_nav_menus'  => (bool) $taxonomy->show_in_nav_menus,
     199                                'show_in_quick_edit' => (bool) $taxonomy->show_in_quick_edit,
     200                                'show_ui'            => (bool) $taxonomy->show_ui,
     201                        ),
    194202                );
    195203
     
    296304                                        'readonly'    => true,
    297305                                ),
     306                                'visibility'   => array(
     307                                        'description' => __( 'The visibility settings for the taxomonmy.' ),
     308                                        'type'        => 'object',
     309                                        'context'     => array( 'edit' ),
     310                                        'readonly'    => true,
     311                                        'properties'  => array(
     312                                                'public'             => array(
     313                                                        'description' => 'Whether a taxonomy is intended for use publicly either via the admin interface or by front-end users.',
     314                                                        'type'        => 'boolean',
     315                                                ),
     316                                                'publicly_queryable' => array(
     317                                                        'description' => 'Whether the taxonomy is publicly queryable.',
     318                                                        'type'        => 'boolean',
     319                                                ),
     320                                                'show_ui'            => array(
     321                                                        'description' => 'Whether to generate a default UI for managing this taxonomy.',
     322                                                        'type'        => 'boolean',
     323                                                ),
     324                                                'show_admin_column'  => array(
     325                                                        'description' => 'Whether to allow automatic creation of taxonomy columns on associated post-types table.',
     326                                                        'type'        => 'boolean',
     327                                                ),
     328                                                'show_in_nav_menus'  => array(
     329                                                        'description' => 'Whether to make the taxonomy available for selection in navigation menus.',
     330                                                        'type'        => 'boolean',
     331                                                ),
     332                                                'show_in_quick_edit' => array(
     333                                                        'description' => 'Whether to show the taxonomy in the quick/bulk edit panel.',
     334                                                        'type'        => 'boolean',
     335                                                ),
     336
     337                                        ),
     338                                ),
    298339                        ),
    299340                );
  • trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r42724 r42729  
    124124        }
    125125
    126                 public function test_get_non_public_taxonomy_no_permission() {
     126        public function test_get_non_public_taxonomy_no_permission() {
    127127                wp_set_current_user( self::$contributor_id );
    128128                register_taxonomy( 'api-private', 'post', array( 'public' => false ) );
     
    168168                $data       = $response->get_data();
    169169                $properties = $data['schema']['properties'];
    170                 $this->assertEquals( 9, count( $properties ) );
     170                $this->assertEquals( 10, count( $properties ) );
    171171                $this->assertArrayHasKey( 'capabilities', $properties );
    172172                $this->assertArrayHasKey( 'description', $properties );
     
    177177                $this->assertArrayHasKey( 'show_cloud', $properties );
    178178                $this->assertArrayHasKey( 'types', $properties );
     179                $this->assertArrayHasKey( 'visibility', $properties );
    179180                $this->assertArrayHasKey( 'rest_base', $properties );
    180181        }
     
    210211                        $this->assertEquals( $tax_obj->labels, $data['labels'] );
    211212                        $this->assertEquals( $tax_obj->show_tagcloud, $data['show_cloud'] );
     213
     214                        $this->assertEquals( $tax_obj->public, $data['visibility']['public'] );
     215                        $this->assertEquals( $tax_obj->publicly_queryable, $data['visibility']['publicly_queryable'] );
     216                        $this->assertEquals( $tax_obj->show_admin_column, $data['visibility']['show_admin_column'] );
     217                        $this->assertEquals( $tax_obj->show_in_nav_menus, $data['visibility']['show_in_nav_menus'] );
     218                        $this->assertEquals( $tax_obj->show_in_quick_edit, $data['visibility']['show_in_quick_edit'] );
     219                        $this->assertEquals( $tax_obj->show_ui, $data['visibility']['show_ui'] );
    212220                } else {
    213221                        $this->assertFalse( isset( $data['capabilities'] ) );
    214222                        $this->assertFalse( isset( $data['labels'] ) );
    215223                        $this->assertFalse( isset( $data['show_cloud'] ) );
     224                        $this->assertFalse( isset( $data['visibility'] ) );
    216225                }
    217226        }
Note: See TracChangeset for help on using the changeset viewer.