- Timestamp:
- 11/03/2016 03:15:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r39106 r39108 460 460 } 461 461 462 if ( ! $this->check_assign_terms_permission( $request ) ) { 463 return new WP_Error( 'rest_cannot_assign_term', __( 'You do not have permission to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); 464 } 465 462 466 return true; 463 467 } … … 591 595 if ( ! empty( $request['sticky'] ) && ! current_user_can( $post_type->cap->edit_others_posts ) ) { 592 596 return new WP_Error( 'rest_cannot_assign_sticky', __( 'You do not have permission to make posts sticky.' ), array( 'status' => rest_authorization_required_code() ) ); 597 } 598 599 if ( ! $this->check_assign_terms_permission( $request ) ) { 600 return new WP_Error( 'rest_cannot_assign_term', __( 'You do not have permission to assign the provided terms.' ), array( 'status' => rest_authorization_required_code() ) ); 593 601 } 594 602 … … 1204 1212 } 1205 1213 } 1214 } 1215 1216 /** 1217 * Checks whether current user can assign all terms sent with the current request. 1218 * 1219 * @since 4.7.0 1220 * 1221 * @param WP_REST_Request $request The request object with post and terms data. 1222 * @return bool Whether the current user can assign the provided terms. 1223 */ 1224 protected function check_assign_terms_permission( $request ) { 1225 $taxonomies = wp_list_filter( get_object_taxonomies( $this->post_type, 'objects' ), array( 'show_in_rest' => true ) ); 1226 foreach ( $taxonomies as $taxonomy ) { 1227 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 1228 1229 if ( ! isset( $request[ $base ] ) ) { 1230 continue; 1231 } 1232 1233 foreach ( $request[ $base ] as $term_id ) { 1234 // Invalid terms will be rejected later. 1235 if ( ! get_term( $term_id, $taxonomy->name ) ) { 1236 continue; 1237 } 1238 1239 if ( ! current_user_can( 'assign_term', (int) $term_id ) ) { 1240 return false; 1241 } 1242 } 1243 } 1244 1245 return true; 1206 1246 } 1207 1247
Note: See TracChangeset
for help on using the changeset viewer.