Ticket #38398: 38398.2.patch
File 38398.2.patch, 22.8 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Settings_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 4 11 * Manage a WordPress site's settings. 5 12 */ 6 7 13 class WP_REST_Settings_Controller extends WP_REST_Controller { 8 14 9 15 protected $rest_base = 'settings'; … … 10 16 protected $namespace = 'wp/v2'; 11 17 12 18 /** 13 * Register the routes for the objects of the controller. 19 * Registers the routes for the objects of the controller. 20 * 21 * @since 4.7.0 14 22 */ 15 23 public function register_routes() { 16 24 register_rest_route( $this->namespace, '/' . $this->rest_base, array( … … 31 39 } 32 40 33 41 /** 34 * Check if a given request has access to read and manage settings.42 * Checks if a given request has access to read and manage settings. 35 43 * 44 * @since 4.7.0 45 * 36 46 * @param WP_REST_Request $request Full details about the request. 37 47 * @return boolean 38 48 */ … … 41 51 } 42 52 43 53 /** 44 * Get the settings.54 * Gets the settings. 45 55 * 56 * @since 4.7.0 57 * 46 58 * @param WP_REST_Request $request Full details about the request. 47 59 * @return WP_Error|array 48 60 */ … … 81 93 } 82 94 83 95 /** 84 * Prepare a value for output based off a schema array.96 * Prepares a value for output based off a schema array. 85 97 * 86 * @param mixed $value 87 * @param array $schema 98 * @since 4.7.0 99 * 100 * @param mixed $value Value to prepare. 101 * @param array $schema Schema to match. 88 102 * @return mixed 89 103 */ 90 104 protected function prepare_value( $value, $schema ) { … … 101 115 } 102 116 103 117 /** 104 * Update settings for the settings object.118 * Updates settings for the settings object. 105 119 * 120 * @since 4.7.0 121 * 106 122 * @param WP_REST_Request $request Full detail about the request. 107 123 * @return WP_Error|array 108 124 */ … … 147 163 } 148 164 149 165 /** 150 * Get all the registered options for the Settings API166 * Gets all the registered options for the Settings API. 151 167 * 168 * @since 4.7.0 169 * 152 170 * @return array 153 171 */ 154 172 protected function get_registered_options() { … … 197 215 } 198 216 199 217 /** 200 * Get the site setting schema, conforming to JSON Schema.218 * Gets the site setting schema, conforming to JSON Schema. 201 219 * 220 * @since 4.7.0 221 * 202 222 * @return array 203 223 */ 204 224 public function get_item_schema() { -
src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Taxonomies_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Access taxonomies. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Taxonomies_Controller extends WP_REST_Controller { 4 16 17 /** 18 * Constructor. 19 * 20 * @since 4.7.0 21 */ 5 22 public function __construct() { 6 23 $this->namespace = 'wp/v2'; 7 24 $this->rest_base = 'taxonomies'; … … 8 25 } 9 26 10 27 /** 11 * Register the routes for the objects of the controller. 28 * Registers the routes for the objects of the controller. 29 * 30 * @since 4.7.0 12 31 */ 13 32 public function register_routes() { 14 33 … … 36 55 } 37 56 38 57 /** 39 * Check whether a given request has permission to read taxonomies.58 * Checks whether a given request has permission to read taxonomies. 40 59 * 60 * @since 4.7.0 61 * 41 62 * @param WP_REST_Request $request Full details about the request. 42 63 * @return WP_Error|boolean 43 64 */ … … 59 80 } 60 81 61 82 /** 62 * Get all public taxonomies83 * Gets all public taxonomies. 63 84 * 64 * @param WP_REST_Request $request 85 * @since 4.7.0 86 * 87 * @param WP_REST_Request $request Full details about the request. 65 88 * @return array 66 89 */ 67 90 public function get_items( $request ) { … … 93 116 } 94 117 95 118 /** 96 * Check if a given request has access a taxonomy119 * Checks if a given request has access a taxonomy. 97 120 * 121 * @since 4.7.0 122 * 98 123 * @param WP_REST_Request $request Full details about the request. 99 124 * @return WP_Error|boolean 100 125 */ … … 115 140 } 116 141 117 142 /** 118 * Get a specific taxonomy143 * Gets a specific taxonomy. 119 144 * 120 * @param WP_REST_Request $request 145 * @since 4.7.0 146 * 147 * @param WP_REST_Request $request Full details about the request. 121 148 * @return array|WP_Error 122 149 */ 123 150 public function get_item( $request ) { … … 130 157 } 131 158 132 159 /** 133 * Prepare a taxonomy object for serialization160 * Prepares a taxonomy object for serialization. 134 161 * 135 * @param stdClass $taxonomy Taxonomy data 136 * @param WP_REST_Request $request 162 * @since 4.7.0 163 * 164 * @param stdClass $taxonomy Taxonomy data. 165 * @param WP_REST_Request $request Full details about the request. 137 166 * @return WP_REST_Response $response 138 167 */ 139 168 public function prepare_item_for_response( $taxonomy, $request ) { … … 167 196 ) ); 168 197 169 198 /** 170 * Filter a taxonomy returned from the API.199 * Filters a taxonomy returned from the API. 171 200 * 172 201 * Allows modification of the taxonomy data right before it is returned. 173 202 * 203 * @since 4.7.0 204 * 174 205 * @param WP_REST_Response $response The response object. 175 206 * @param object $item The original taxonomy object. 176 207 * @param WP_REST_Request $request Request used to generate the response. … … 179 210 } 180 211 181 212 /** 182 * Get the taxonomy's schema, conforming to JSON Schema213 * Gets the taxonomy's schema, conforming to JSON Schema. 183 214 * 215 * @since 4.7.0 216 * 184 217 * @return array 185 218 */ 186 219 public function get_item_schema() { … … 243 276 } 244 277 245 278 /** 246 * Get the query params for collections279 * Gets the query params for collections. 247 280 * 281 * @since 4.7.0 282 * 248 283 * @return array 249 284 */ 250 285 public function get_collection_params() { -
src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Terms_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 4 11 * Access terms associated with a taxonomy. 12 * 13 * @since 4.7.0 5 14 */ 6 15 class WP_REST_Terms_Controller extends WP_REST_Controller { 7 16 … … 8 17 /** 9 18 * Taxonomy key. 10 19 * 20 * @since 4.7.0 11 21 * @access protected 12 22 * @var string 13 23 */ … … 16 26 /** 17 27 * Instance of a term meta fields object. 18 28 * 29 * @since 4.7.0 19 30 * @access protected 20 31 * @var WP_REST_Term_Meta_Fields 21 32 */ … … 24 35 /** 25 36 * Column to have the terms be sorted by. 26 37 * 38 * @since 4.7.0 27 39 * @access protected 28 40 * @var string 29 41 */ … … 32 44 /** 33 45 * Number of terms that were found. 34 46 * 47 * @since 4.7.0 35 48 * @access protected 36 49 * @var int 37 50 */ … … 40 53 /** 41 54 * Constructor. 42 55 * 56 * @since 4.7.0 57 * 43 58 * @param string $taxonomy Taxonomy key. 44 59 */ 45 60 public function __construct( $taxonomy ) { … … 53 68 54 69 /** 55 70 * Registers the routes for the objects of the controller. 71 * 72 * @since 4.7.0 56 73 */ 57 74 public function register_routes() { 58 75 … … 104 121 /** 105 122 * Checks if a request has access to read terms in the specified taxonomy. 106 123 * 124 * @since 4.7.0 125 * 107 126 * @param WP_REST_Request $request Full details about the request. 108 127 * @return WP_Error|boolean 109 128 */ … … 121 140 /** 122 141 * Gets terms associated with a taxonomy. 123 142 * 143 * @since 4.7.0 144 * 124 145 * @param WP_REST_Request $request Full details about the request. 125 146 * @return WP_REST_Response|WP_Error 126 147 */ … … 198 219 unset( $count_args['number'], $count_args['offset'] ); 199 220 $total_terms = wp_count_terms( $this->taxonomy, $count_args ); 200 221 201 // wp_count_terms can return a falsy value when the term has no children 222 // wp_count_terms can return a falsy value when the term has no children. 202 223 if ( ! $total_terms ) { 203 224 $total_terms = 0; 204 225 } … … 245 266 * supported, notably `include`, `exclude`. In `self::get_items()` these 246 267 * are instead treated as a full query. 247 268 * 269 * @since 4.7.0 270 * 248 271 * @param array $prepared_args Arguments for get_terms(). 249 272 * @return array List of term objects. (Total count in `$this->total_terms`) 250 273 */ … … 286 309 } 287 310 288 311 /** 289 * Compar ison function for sorting termsby a column.312 * Compares terms for sorting by a column. 290 313 * 291 314 * Uses `$this->sort_column` to determine field to sort by. 292 315 * 293 * @ access protected316 * @since 4.7.0 294 317 * 295 318 * @param stdClass $left Term object. 296 319 * @param stdClass $right Term object. … … 311 334 /** 312 335 * Checks if a request has access to read the specified term. 313 336 * 337 * @since 4.7.0 338 * 314 339 * @param WP_REST_Request $request Full details about the request. 315 340 * @return WP_Error|boolean 316 341 */ … … 328 353 /** 329 354 * Gets a single term from a taxonomy. 330 355 * 331 * @param WP_REST_Request $request Full details about the request 356 * @since 4.7.0 357 * 358 * @param WP_REST_Request $request Full details about the request. 332 359 * @return WP_REST_Request|WP_Error 333 360 */ 334 361 public function get_item( $request ) { … … 349 376 /** 350 377 * Checks if a request has access to create a term. 351 378 * 379 * @since 4.7.0 380 * 352 381 * @param WP_REST_Request $request Full details about the request. 353 382 * @return WP_Error|boolean 354 383 */ … … 369 398 /** 370 399 * Creates a single term in a taxonomy. 371 400 * 372 * @param WP_REST_Request $request Full details about the request 401 * @since 4.7.0 402 * 403 * @param WP_REST_Request $request Full details about the request. 373 404 * @return WP_REST_Request|WP_Error 374 405 */ 375 406 public function create_item( $request ) { … … 389 420 390 421 $term = wp_insert_term( $prepared_term->name, $this->taxonomy, $prepared_term ); 391 422 if ( is_wp_error( $term ) ) { 392 393 423 /* 394 424 * If we're going to inform the client that the term already exists, 395 425 * give them the identifier for future use. … … 407 437 /** 408 438 * Fires after a single term is created or updated via the REST API. 409 439 * 440 * @since 4.7.0 441 * 410 442 * @param WP_Term $term Inserted Term object. 411 443 * @param WP_REST_Request $request Request object. 412 444 * @param boolean $creating True when creating term, false when updating. … … 437 469 /** 438 470 * Checks if a request has access to update the specified term. 439 471 * 472 * @since 4.7.0 473 * 440 474 * @param WP_REST_Request $request Full details about the request. 441 475 * @return WP_Error|boolean 442 476 */ … … 462 496 /** 463 497 * Updates a single term from a taxonomy. 464 498 * 465 * @param WP_REST_Request $request Full details about the request 499 * @since 4.7.0 500 * 501 * @param WP_REST_Request $request Full details about the request. 466 502 * @return WP_REST_Request|WP_Error 467 503 */ 468 504 public function update_item( $request ) { … … 516 552 /** 517 553 * Checks if a request has access to delete the specified term. 518 554 * 555 * @since 4.7.0 556 * 519 557 * @param WP_REST_Request $request Full details about the request. 520 558 * @return WP_Error|boolean 521 559 */ … … 537 575 /** 538 576 * Deletes a single term from a taxonomy. 539 577 * 540 * @param WP_REST_Request $request Full details about the request 578 * @since 4.7.0 579 * 580 * @param WP_REST_Request $request Full details about the request. 541 581 * @return WP_REST_Response|WP_Error 542 582 */ 543 583 public function delete_item( $request ) { … … 573 613 /** 574 614 * Prepares a single term for create or update. 575 615 * 616 * @since 4.7.0 617 * 576 618 * @param WP_REST_Request $request Request object. 577 619 * @return object $prepared_term Term object. 578 620 */ … … 610 652 /** 611 653 * Filters term data before inserting term via the REST API. 612 654 * 655 * @since 4.7.0 656 * 613 657 * @param object $prepared_term Term object. 614 658 * @param WP_REST_Request $request Request object. 615 659 */ … … 619 663 /** 620 664 * Prepares a single term output for response. 621 665 * 666 * @since 4.7.0 667 * 622 668 * @param obj $item Term object. 623 669 * @param WP_REST_Request $request Request object. 624 670 * @return WP_REST_Response $response … … 668 714 * 669 715 * Allows modification of the term data right before it is returned. 670 716 * 717 * @since 4.7.0 718 * 671 719 * @param WP_REST_Response $response The response object. 672 720 * @param object $item The original term object. 673 721 * @param WP_REST_Request $request Request used to generate the response. … … 678 726 /** 679 727 * Prepares links for the request. 680 728 * 729 * @since 4.7.0 730 * 681 731 * @param object $term Term object. 682 732 * @return array Links for the given term. 683 733 */ … … 731 781 /** 732 782 * Gets the term's schema, conforming to JSON Schema. 733 783 * 784 * @since 4.7.0 785 * 734 786 * @return array 735 787 */ 736 788 public function get_item_schema() { … … 808 860 /** 809 861 * Gets the query params for collections. 810 862 * 863 * @since 4.7.0 864 * 811 865 * @return array 812 866 */ 813 867 public function get_collection_params() { … … 894 948 /** 895 949 * Checks that the taxonomy is valid. 896 950 * 951 * @since 4.7.0 952 * 897 953 * @param string $taxonomy Taxonomy to check. 898 954 * @return WP_Error|boolean 899 955 */ -
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Users_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 4 * Access users 11 * Access users. 12 * 13 * @since 4.7.0 5 14 */ 6 15 class WP_REST_Users_Controller extends WP_REST_Controller { 7 16 … … 8 17 /** 9 18 * Instance of a user meta fields object. 10 19 * 20 * @since 4.7.0 11 21 * @access protected 12 22 * @var WP_REST_User_Meta_Fields 13 23 */ 14 24 protected $meta; 15 25 26 /** 27 * Constructor. 28 * 29 * @since 4.7.0 30 */ 16 31 public function __construct() { 17 32 $this->namespace = 'wp/v2'; 18 33 $this->rest_base = 'users'; … … 21 36 } 22 37 23 38 /** 24 * Register the routes for the objects of the controller. 39 * Registers the routes for the objects of the controller. 40 * 41 * @since 4.7.0 25 42 */ 26 43 public function register_routes() { 27 44 … … 83 100 /** 84 101 * Permissions check for getting all users. 85 102 * 103 * @since 4.7.0 104 * 86 105 * @param WP_REST_Request $request Full details about the request. 87 106 * @return WP_Error|boolean 88 107 */ … … 104 123 } 105 124 106 125 /** 107 * Get all users126 * Gets all users. 108 127 * 128 * @since 4.7.0 129 * 109 130 * @param WP_REST_Request $request Full details about the request. 110 131 * @return WP_Error|WP_REST_Response 111 132 */ … … 170 191 } 171 192 172 193 /** 173 * Filter arguments, before passing to WP_User_Query, when querying users via the REST API.194 * Filters arguments, before passing to WP_User_Query, when querying users via the REST API. 174 195 * 196 * @since 4.7.0 197 * 175 198 * @see https://developer.wordpress.org/reference/classes/wp_user_query/ 176 199 * 177 200 * @param array $prepared_args Array of arguments for WP_User_Query. … … 197 220 198 221 $total_users = $query->get_total(); 199 222 if ( $total_users < 1 ) { 200 // Out-of-bounds, run the query again without LIMIT for total count 223 // Out-of-bounds, run the query again without LIMIT for total count. 201 224 unset( $prepared_args['number'], $prepared_args['offset'] ); 202 225 $count_query = new WP_User_Query( $prepared_args ); 203 226 $total_users = $count_query->get_total(); … … 225 248 } 226 249 227 250 /** 228 * Check if a given request has access to read a user251 * Checks if a given request has access to read a user. 229 252 * 253 * @since 4.7.0 254 * 230 255 * @param WP_REST_Request $request Full details about the request. 231 256 * @return WP_Error|boolean 232 257 */ … … 254 279 } 255 280 256 281 /** 257 * Get a single user282 * Gets a single user. 258 283 * 284 * @since 4.7.0 285 * 259 286 * @param WP_REST_Request $request Full details about the request. 260 287 * @return WP_Error|WP_REST_Response 261 288 */ … … 274 301 } 275 302 276 303 /** 277 * Get the current user304 * Gets the current user. 278 305 * 306 * @since 4.7.0 307 * 279 308 * @param WP_REST_Request $request Full details about the request. 280 309 * @return WP_Error|WP_REST_Response 281 310 */ … … 295 324 } 296 325 297 326 /** 298 * Check if a given request has access create users327 * Checks if a given request has access create users. 299 328 * 329 * @since 4.7.0 330 * 300 331 * @param WP_REST_Request $request Full details about the request. 301 332 * @return WP_Error|boolean 302 333 */ … … 310 341 } 311 342 312 343 /** 313 * Create a single user344 * Creates a single user. 314 345 * 346 * @since 4.7.0 347 * 315 348 * @param WP_REST_Request $request Full details about the request. 316 349 * @return WP_Error|WP_REST_Response 317 350 */ … … 375 408 /** 376 409 * Fires after a user is created or updated via the REST API. 377 410 * 411 * @since 4.7.0 412 * 378 413 * @param WP_User $user Data used to create the user. 379 414 * @param WP_REST_Request $request Request object. 380 415 * @param boolean $creating True when creating user, false when updating user. … … 391 426 } 392 427 393 428 /** 394 * Check if a given request has access update a user429 * Checks if a given request has access update a user. 395 430 * 431 * @since 4.7.0 432 * 396 433 * @param WP_REST_Request $request Full details about the request. 397 434 * @return WP_Error|boolean 398 435 */ … … 412 449 } 413 450 414 451 /** 415 * Update a single user452 * Updates a single user. 416 453 * 454 * @since 4.7.0 455 * 417 456 * @param WP_REST_Request $request Full details about the request. 418 457 * @return WP_Error|WP_REST_Response 419 458 */ … … 446 485 447 486 $user = $this->prepare_item_for_database( $request ); 448 487 449 // Ensure we're operating on the same user we already checked 488 // Ensure we're operating on the same user we already checked. 450 489 $user->ID = $id; 451 490 452 491 $user_id = wp_update_user( $user ); … … 482 521 } 483 522 484 523 /** 485 * Check if a given request has access delete a user524 * Checks if a given request has access delete a user. 486 525 * 526 * @since 4.7.0 527 * 487 528 * @param WP_REST_Request $request Full details about the request. 488 529 * @return WP_Error|boolean 489 530 */ … … 499 540 } 500 541 501 542 /** 502 * Delete a single user543 * Deletes a single user. 503 544 * 545 * @since 4.7.0 546 * 504 547 * @param WP_REST_Request $request Full details about the request. 505 548 * @return WP_Error|WP_REST_Response 506 549 */ … … 509 552 $reassign = isset( $request['reassign'] ) ? absint( $request['reassign'] ) : null; 510 553 $force = isset( $request['force'] ) ? (bool) $request['force'] : false; 511 554 512 // We don't support trashing for this type, error out 555 // We don't support trashing for this type, error out. 513 556 if ( ! $force ) { 514 557 return new WP_Error( 'rest_trash_not_supported', __( 'Users do not support trashing.' ), array( 'status' => 501 ) ); 515 558 } … … 540 583 /** 541 584 * Fires after a user is deleted via the REST API. 542 585 * 586 * @since 4.7.0 587 * 543 588 * @param WP_User $user The user data. 544 589 * @param WP_REST_Response $response The response returned from the API. 545 590 * @param WP_REST_Request $request The request sent to the API. … … 550 595 } 551 596 552 597 /** 553 * Prepare a single user output for response598 * Prepares a single user output for response. 554 599 * 555 * @param object $user User object. 600 * @since 4.7.0 601 * 602 * @param object $user User object. 556 603 * @param WP_REST_Request $request Request object. 557 604 * @return WP_REST_Response $response Response data. 558 605 */ … … 634 681 $data = $this->add_additional_fields_to_object( $data, $request ); 635 682 $data = $this->filter_response_by_context( $data, $context ); 636 683 637 // Wrap the data in a response object 684 // Wrap the data in a response object. 638 685 $response = rest_ensure_response( $data ); 639 686 640 687 $response->add_links( $this->prepare_links( $user ) ); 641 688 642 689 /** 643 * Filter user data returned from the REST API.690 * Filters user data returned from the REST API. 644 691 * 692 * @since 4.7.0 693 * 645 694 * @param WP_REST_Response $response The response object. 646 695 * @param object $user User object used to create response. 647 696 * @param WP_REST_Request $request Request object. … … 650 699 } 651 700 652 701 /** 653 * Prepare links for the request.702 * Prepares links for the request. 654 703 * 704 * @since 4.7.0 705 * 655 706 * @param WP_Post $user User object. 656 707 * @return array Links for the given user. 657 708 */ … … 669 720 } 670 721 671 722 /** 672 * Prepare a single user for create or update723 * Prepares a single user for create or update. 673 724 * 725 * @since 4.7.0 726 * 674 727 * @param WP_REST_Request $request Request object. 675 728 * @return object $prepared_user User object. 676 729 */ … … 723 776 } 724 777 725 778 /** 726 * Filter user data before inserting user via the REST API.779 * Filters user data before inserting user via the REST API. 727 780 * 781 * @since 4.7.0 782 * 728 783 * @param object $prepared_user User object. 729 784 * @param WP_REST_Request $request Request object. 730 785 */ … … 732 787 } 733 788 734 789 /** 735 * Determine if the current user is allowed to make the desired roles change.790 * Determines if the current user is allowed to make the desired roles change. 736 791 * 792 * @since 4.7.0 793 * 737 794 * @param integer $user_id User ID. 738 795 * @param array $roles New user roles. 739 796 * @return WP_Error|boolean … … 754 811 return new WP_Error( 'rest_user_invalid_role', __( 'You cannot give resource that role.' ), array( 'status' => rest_authorization_required_code() ) ); 755 812 } 756 813 757 // The new role must be editable by the logged-in user.758 759 814 /** Include admin functions to get access to get_editable_roles() */ 760 815 require_once ABSPATH . 'wp-admin/includes/admin.php'; 761 816 817 // The new role must be editable by the logged-in user. 762 818 $editable_roles = get_editable_roles(); 763 819 if ( empty( $editable_roles[ $role ] ) ) { 764 820 return new WP_Error( 'rest_user_invalid_role', __( 'You cannot give resource that role.' ), array( 'status' => 403 ) ); … … 766 822 } 767 823 768 824 return true; 769 770 825 } 771 826 772 827 /** 773 * Get the User's schema, conforming to JSON Schema828 * Gets the User's schema, conforming to JSON Schema. 774 829 * 830 * @since 4.7.0 831 * 775 832 * @return array 776 833 */ 777 834 public function get_item_schema() { … … 878 935 'password' => array( 879 936 'description' => __( 'Password for the resource (never included).' ), 880 937 'type' => 'string', 881 'context' => array(), // Password is never displayed 938 'context' => array(), // Password is never displayed. 882 939 'required' => true, 883 940 ), 884 941 'capabilities' => array( … … 924 981 } 925 982 926 983 /** 927 * Get the query params for collections984 * Gets the query params for collections. 928 985 * 986 * @since 4.7.0 987 * 929 988 * @return array 930 989 */ 931 990 public function get_collection_params() {