- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
r46823 r47122 145 145 public function get_items_permissions_check( $request ) { 146 146 $tax_obj = get_taxonomy( $this->taxonomy ); 147 147 148 if ( ! $tax_obj || ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) { 148 149 return false; 149 150 } 151 150 152 if ( 'edit' === $request['context'] && ! current_user_can( $tax_obj->cap->edit_terms ) ) { 151 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), array( 'status' => rest_authorization_required_code() ) ); 152 } 153 return new WP_Error( 154 'rest_forbidden_context', 155 __( 'Sorry, you are not allowed to edit terms in this taxonomy.' ), 156 array( 'status' => rest_authorization_required_code() ) 157 ); 158 } 159 153 160 return true; 154 161 } … … 259 266 $total_terms = wp_count_terms( $this->taxonomy, $count_args ); 260 267 261 // wp_count_terms can return a falsy value when the term has no children.268 // wp_count_terms() can return a falsy value when the term has no children. 262 269 if ( ! $total_terms ) { 263 270 $total_terms = 0; … … 313 320 */ 314 321 protected function get_term( $id ) { 315 $error = new WP_Error( 'rest_term_invalid', __( 'Term does not exist.' ), array( 'status' => 404 ) ); 322 $error = new WP_Error( 323 'rest_term_invalid', 324 __( 'Term does not exist.' ), 325 array( 'status' => 404 ) 326 ); 316 327 317 328 if ( ! $this->check_is_taxonomy_allowed( $this->taxonomy ) ) { … … 341 352 public function get_item_permissions_check( $request ) { 342 353 $term = $this->get_term( $request['id'] ); 354 343 355 if ( is_wp_error( $term ) ) { 344 356 return $term; … … 346 358 347 359 if ( 'edit' === $request['context'] && ! current_user_can( 'edit_term', $term->term_id ) ) { 348 return new WP_Error( 'rest_forbidden_context', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); 349 } 360 return new WP_Error( 361 'rest_forbidden_context', 362 __( 'Sorry, you are not allowed to edit this term.' ), 363 array( 'status' => rest_authorization_required_code() ) 364 ); 365 } 366 350 367 return true; 351 368 } … … 385 402 386 403 $taxonomy_obj = get_taxonomy( $this->taxonomy ); 404 387 405 if ( ( is_taxonomy_hierarchical( $this->taxonomy ) 388 406 && ! current_user_can( $taxonomy_obj->cap->edit_terms ) ) 389 407 || ( ! is_taxonomy_hierarchical( $this->taxonomy ) 390 408 && ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) ) { 391 return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to create new terms.' ), array( 'status' => rest_authorization_required_code() ) ); 409 return new WP_Error( 410 'rest_cannot_create', 411 __( 'Sorry, you are not allowed to create new terms.' ), 412 array( 'status' => rest_authorization_required_code() ) 413 ); 392 414 } 393 415 … … 406 428 if ( isset( $request['parent'] ) ) { 407 429 if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { 408 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); 430 return new WP_Error( 431 'rest_taxonomy_not_hierarchical', 432 __( 'Cannot set parent term, taxonomy is not hierarchical.' ), 433 array( 'status' => 400 ) 434 ); 409 435 } 410 436 … … 412 438 413 439 if ( ! $parent ) { 414 return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); 440 return new WP_Error( 441 'rest_term_invalid', 442 __( 'Parent term does not exist.' ), 443 array( 'status' => 400 ) 444 ); 415 445 } 416 446 } … … 503 533 public function update_item_permissions_check( $request ) { 504 534 $term = $this->get_term( $request['id'] ); 535 505 536 if ( is_wp_error( $term ) ) { 506 537 return $term; … … 508 539 509 540 if ( ! current_user_can( 'edit_term', $term->term_id ) ) { 510 return new WP_Error( 'rest_cannot_update', __( 'Sorry, you are not allowed to edit this term.' ), array( 'status' => rest_authorization_required_code() ) ); 541 return new WP_Error( 542 'rest_cannot_update', 543 __( 'Sorry, you are not allowed to edit this term.' ), 544 array( 'status' => rest_authorization_required_code() ) 545 ); 511 546 } 512 547 … … 530 565 if ( isset( $request['parent'] ) ) { 531 566 if ( ! is_taxonomy_hierarchical( $this->taxonomy ) ) { 532 return new WP_Error( 'rest_taxonomy_not_hierarchical', __( 'Cannot set parent term, taxonomy is not hierarchical.' ), array( 'status' => 400 ) ); 567 return new WP_Error( 568 'rest_taxonomy_not_hierarchical', 569 __( 'Cannot set parent term, taxonomy is not hierarchical.' ), 570 array( 'status' => 400 ) 571 ); 533 572 } 534 573 … … 536 575 537 576 if ( ! $parent ) { 538 return new WP_Error( 'rest_term_invalid', __( 'Parent term does not exist.' ), array( 'status' => 400 ) ); 577 return new WP_Error( 578 'rest_term_invalid', 579 __( 'Parent term does not exist.' ), 580 array( 'status' => 400 ) 581 ); 539 582 } 540 583 } … … 591 634 public function delete_item_permissions_check( $request ) { 592 635 $term = $this->get_term( $request['id'] ); 636 593 637 if ( is_wp_error( $term ) ) { 594 638 return $term; … … 596 640 597 641 if ( ! current_user_can( 'delete_term', $term->term_id ) ) { 598 return new WP_Error( 'rest_cannot_delete', __( 'Sorry, you are not allowed to delete this term.' ), array( 'status' => rest_authorization_required_code() ) ); 642 return new WP_Error( 643 'rest_cannot_delete', 644 __( 'Sorry, you are not allowed to delete this term.' ), 645 array( 'status' => rest_authorization_required_code() ) 646 ); 599 647 } 600 648 … … 620 668 // We don't support trashing for terms. 621 669 if ( ! $force ) { 622 /* translators: %s: force=true */ 623 return new WP_Error( 'rest_trash_not_supported', sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), array( 'status' => 501 ) ); 670 return new WP_Error( 671 'rest_trash_not_supported', 672 /* translators: %s: force=true */ 673 sprintf( __( "Terms do not support trashing. Set '%s' to delete." ), 'force=true' ), 674 array( 'status' => 501 ) 675 ); 624 676 } 625 677 … … 631 683 632 684 if ( ! $retval ) { 633 return new WP_Error( 'rest_cannot_delete', __( 'The term cannot be deleted.' ), array( 'status' => 500 ) ); 685 return new WP_Error( 686 'rest_cannot_delete', 687 __( 'The term cannot be deleted.' ), 688 array( 'status' => 500 ) 689 ); 634 690 } 635 691 … … 930 986 931 987 $this->schema = $schema; 988 932 989 return $this->add_additional_fields_schema( $this->schema ); 933 990 }
Note: See TracChangeset
for help on using the changeset viewer.