Make WordPress Core


Ignore:
Timestamp:
07/13/2018 06:28:29 AM (8 years ago)
Author:
pento
Message:

REST API: Tweak permission checks for taxonomy and term endpoints

To match behaviour in the Classic Editor, we need to slightly loosen permissions on taxonomy and term endpoints. This allows users to create terms to assign to a post that they're editing.

Merges [43440] to the 4.9 branch.

Props danielbachhuber.
Fixes #44096.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r42427 r43443  
    5252        $response = $this->server->dispatch( $request );
    5353        $data = $response->get_data();
     54        $taxonomies = $this->get_public_taxonomies( get_taxonomies( '', 'objects' ) );
     55        $this->assertEquals( count( $taxonomies ), count( $data ) );
     56        $this->assertEquals( 'Categories', $data['category']['name'] );
     57        $this->assertEquals( 'category', $data['category']['slug'] );
     58        $this->assertEquals( true, $data['category']['hierarchical'] );
     59        $this->assertEquals( 'Tags', $data['post_tag']['name'] );
     60        $this->assertEquals( 'post_tag', $data['post_tag']['slug'] );
     61        $this->assertEquals( false, $data['post_tag']['hierarchical'] );
     62        $this->assertEquals( 'tags', $data['post_tag']['rest_base'] );
     63    }
     64
     65    public function test_get_items_context_edit() {
     66        wp_set_current_user( self::$contributor_id );
     67        $request    = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
     68        $request->set_param( 'context', 'edit' );
     69        $response   = rest_get_server()->dispatch( $request );
     70        $data       = $response->get_data();
    5471        $taxonomies = $this->get_public_taxonomies( get_taxonomies( '', 'objects' ) );
    5572        $this->assertEquals( count( $taxonomies ), count( $data ) );
Note: See TracChangeset for help on using the changeset viewer.