WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/13/2018 04:23:35 AM (18 months 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.

Props danielbachhuber.
Fixes #44096.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r43087 r43440  
    5050    public function test_get_items() {
    5151        $request    = new WP_REST_Request( 'GET', '/wp/v2/taxonomies' );
     52        $response   = rest_get_server()->dispatch( $request );
     53        $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' );
    5269        $response   = rest_get_server()->dispatch( $request );
    5370        $data       = $response->get_data();
Note: See TracChangeset for help on using the changeset viewer.