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/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r42578 r43443  
    377377
    378378        $taxonomy_obj = get_taxonomy( $this->taxonomy );
    379         if ( ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) {
     379        if ( ( is_taxonomy_hierarchical( $this->taxonomy )
     380                && ! current_user_can( $taxonomy_obj->cap->edit_terms ) )
     381            || ( ! is_taxonomy_hierarchical( $this->taxonomy )
     382                && ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) {
    380383            return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) );
    381384        }
Note: See TracChangeset for help on using the changeset viewer.