Ticket #38398: 38398.4.patch
File 38398.4.patch, 82.3 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Attachments_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Access attachments. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 4 16 5 17 /** … … 6 18 * Determine the allowed query_vars for a get_items() response and 7 19 * prepare for WP_Query. 8 20 * 21 * @since 4.7.0 22 * 9 23 * @param array $prepared_args Optional. Array of prepared arguments. 10 24 * @param WP_REST_Request $request Optional. Request to prepare items for. 11 25 * @return array Array of query arguments. … … 31 45 /** 32 46 * Check if a given request has access to create an attachment. 33 47 * 48 * @since 4.7.0 49 * 34 50 * @param WP_REST_Request $request Full details about the request. 35 51 * @return WP_Error|true Boolean true if the attachment may be created, or a WP_Error if not. 36 52 */ … … 59 75 /** 60 76 * Create a single attachment. 61 77 * 78 * @since 4.7.0 79 * 62 80 * @param WP_REST_Request $request Full details about the request. 63 81 * @return WP_Error|WP_REST_Response Response object on success, WP_Error object on failure. 64 82 */ … … 68 86 return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); 69 87 } 70 88 71 // Get the file via $_FILES or raw data 89 // Get the file via $_FILES or raw data. 72 90 $files = $request->get_file_params(); 73 91 $headers = $request->get_headers(); 74 92 if ( ! empty( $files ) ) { … … 146 164 /** 147 165 * Fires after a single attachment is created or updated via the REST API. 148 166 * 167 * @since 4.7.0 168 * 149 169 * @param object $attachment Inserted attachment. 150 170 * @param WP_REST_Request $request The request sent to the API. 151 171 * @param boolean $creating True when creating an attachment, false when updating. … … 159 179 /** 160 180 * Update a single post. 161 181 * 182 * @since 4.7.0 183 * 162 184 * @param WP_REST_Request $request Full details about the request. 163 185 * @return WP_Error|WP_REST_Response Response object on success, WP_Error object on failure. 164 186 */ … … 198 220 /** 199 221 * Prepare a single attachment for create or update. 200 222 * 223 * @since 4.7.0 224 * 201 225 * @param WP_REST_Request $request Request object. 202 226 * @return WP_Error|stdClass $prepared_attachment Post object. 203 227 */ … … 222 246 /** 223 247 * Prepare a single attachment output for response. 224 248 * 249 * @since 4.7.0 250 * 225 251 * @param WP_Post $post Post object. 226 252 * @param WP_REST_Request $request Request object. 227 253 * @return WP_REST_Response Response object. … … 288 314 * 289 315 * Allows modification of the attachment right before it is returned. 290 316 * 317 * @since 4.7.0 318 * 291 319 * @param WP_REST_Response $response The response object. 292 320 * @param WP_Post $post The original attachment post. 293 321 * @param WP_REST_Request $request Request used to generate the response. … … 298 326 /** 299 327 * Get the Attachment's schema, conforming to JSON Schema. 300 328 * 329 * @since 4.7.0 330 * 301 331 * @return array Item schema as an array. 302 332 */ 303 333 public function get_item_schema() { … … 365 395 /** 366 396 * Handle an upload via raw POST data. 367 397 * 398 * @since 4.7.0 399 * 368 400 * @param array $data Supplied file data. 369 401 * @param array $headers HTTP headers from the request. 370 402 * @return array|WP_Error Data from {@see wp_handle_sideload()}. … … 459 491 * | ext-token "=" ext-value 460 492 * ext-token = <the characters in token, followed by "*"> 461 493 * 494 * @since 4.7.0 495 * 462 496 * @see http://tools.ietf.org/html/rfc2388 463 497 * @see http://tools.ietf.org/html/rfc6266 464 498 * … … 506 540 /** 507 541 * Get the query params for collections of attachments. 508 542 * 543 * @since 4.7.0 544 * 509 545 * @return array Query parameters for the attachment collection as an array. 510 546 */ 511 547 public function get_collection_params() { … … 531 567 /** 532 568 * Validate whether the user can query private statuses 533 569 * 570 * @since 4.7.0 571 * 534 572 * @param mixed $value Status value. 535 573 * @param WP_REST_Request $request Request object. 536 574 * @param string $parameter Additional parameter to pass to validation. … … 546 584 /** 547 585 * Handle an upload via multipart/form-data ($_FILES). 548 586 * 587 * @since 4.7.0 588 * 549 589 * @param array $files Data from $_FILES. 550 590 * @param array $headers HTTP headers from the request. 551 591 * @return array|WP_Error Data from {@see wp_handle_upload()}. … … 590 630 * 591 631 * Media types are considered the MIME type category. 592 632 * 633 * @since 4.7.0 634 * 593 635 * @return array 594 636 */ 595 637 protected function get_media_types() { -
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Comments_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 4 * Access comments 11 * Access comments. 12 * 13 * @since 4.7.0 5 14 */ 6 15 class WP_REST_Comments_Controller extends WP_REST_Controller { 7 16 … … 8 17 /** 9 18 * Instance of a comment meta fields object. 10 19 * 20 * @since 4.7.0 11 21 * @access protected 12 22 * @var WP_REST_Comment_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 = 'comments'; … … 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 … … 72 89 } 73 90 74 91 /** 75 * Check if a given request has access to read comments92 * Checks if a given request has access to read comments. 76 93 * 94 * @since 4.7.0 95 * 77 96 * @param WP_REST_Request $request Full details about the request. 78 97 * @return WP_Error|boolean 79 98 */ … … 119 138 } 120 139 121 140 /** 122 * Get a list of comments.141 * Gets a list of comments. 123 142 * 143 * @since 4.7.0 144 * 124 145 * @param WP_REST_Request $request Full details about the request. 125 146 * @return WP_Error|WP_REST_Response 126 147 */ … … 190 211 } 191 212 192 213 /** 193 * Filter arguments, before passing to WP_Comment_Query, when querying comments via the REST API.214 * Filters arguments, before passing to WP_Comment_Query, when querying comments via the REST API. 194 215 * 195 216 * @see https://developer.wordpress.org/reference/classes/wp_comment_query/ 196 217 * … … 215 236 $total_comments = (int) $query->found_comments; 216 237 $max_pages = (int) $query->max_num_pages; 217 238 if ( $total_comments < 1 ) { 218 // Out-of-bounds, run the query again without LIMIT for total count 239 // Out-of-bounds, run the query again without LIMIT for total count. 219 240 unset( $prepared_args['number'], $prepared_args['offset'] ); 220 241 $query = new WP_Comment_Query; 221 242 $prepared_args['count'] = true; … … 247 268 } 248 269 249 270 /** 250 * Check if a given request has access to read the comment271 * Checks if a given request has access to read the comment. 251 272 * 273 * @since 4.7.0 274 * 252 275 * @param WP_REST_Request $request Full details about the request. 253 276 * @return WP_Error|boolean 254 277 */ … … 279 302 } 280 303 281 304 /** 282 * Get a comment.305 * Gets a comment. 283 306 * 307 * @since 4.7.0 308 * 284 309 * @param WP_REST_Request $request Full details about the request. 285 310 * @return WP_Error|WP_REST_Response 286 311 */ … … 306 331 } 307 332 308 333 /** 309 * Check if a given request has access to create a comment334 * Checks if a given request has access to create a comment. 310 335 * 336 * @since 4.7.0 337 * 311 338 * @param WP_REST_Request $request Full details about the request. 312 339 * @return WP_Error|boolean 313 340 */ … … 354 381 } 355 382 356 383 /** 357 * Create a comment.384 * Creates a comment. 358 385 * 386 * @since 4.7.0 387 * 359 388 * @param WP_REST_Request $request Full details about the request. 360 389 * @return WP_Error|WP_REST_Response 361 390 */ … … 384 413 $prepared_comment['comment_date_gmt'] = current_time( 'mysql', true ); 385 414 } 386 415 387 // Set author data if the user's logged in 416 // Set author data if the user's logged in. 388 417 $missing_author = empty( $prepared_comment['user_id'] ) 389 418 && empty( $prepared_comment['comment_author'] ) 390 419 && empty( $prepared_comment['comment_author_email'] ) … … 442 471 * 443 472 * Allows modification of the comment right before it is inserted via `wp_insert_comment`. 444 473 * 474 * @since 4.7.0 475 * 445 476 * @param array $prepared_comment The prepared comment data for `wp_insert_comment`. 446 477 * @param WP_REST_Request $request Request used to insert the comment. 447 478 */ … … 481 512 /** 482 513 * Fires after a comment is created or updated via the REST API. 483 514 * 515 * @since 4.7.0 516 * 484 517 * @param array $comment Comment as it exists in the database. 485 518 * @param WP_REST_Request $request The request sent to the API. 486 519 * @param boolean $creating True when creating a comment, false when updating. … … 491 524 } 492 525 493 526 /** 494 * Check if a given request has access to update a comment527 * Checks if a given request has access to update a comment. 495 528 * 529 * @since 4.7.0 530 * 496 531 * @param WP_REST_Request $request Full details about the request. 497 532 * @return WP_Error|boolean 498 533 */ … … 510 545 } 511 546 512 547 /** 513 * Edit a comment548 * Edits a comment. 514 549 * 550 * @since 4.7.0 551 * 515 552 * @param WP_REST_Request $request Full details about the request. 516 553 * @return WP_Error|WP_REST_Response 517 554 */ … … 579 616 } 580 617 581 618 /** 582 * Check if a given request has access to delete a comment619 * Checks if a given request has access to delete a comment. 583 620 * 621 * @since 4.7.0 622 * 584 623 * @param WP_REST_Request $request Full details about the request. 585 624 * @return WP_Error|boolean 586 625 */ … … 597 636 } 598 637 599 638 /** 600 * Delete a comment.639 * Deletes a comment. 601 640 * 641 * @since 4.7.0 642 * 602 643 * @param WP_REST_Request $request Full details about the request. 603 644 * @return WP_Error|WP_REST_Response 604 645 */ … … 627 668 if ( $force ) { 628 669 $result = wp_delete_comment( $comment->comment_ID, true ); 629 670 } else { 630 // If we don't support trashing for this type, error out 671 // If we don't support trashing for this type, error out. 631 672 if ( ! $supports_trash ) { 632 673 return new WP_Error( 'rest_trash_not_supported', __( 'The comment does not support trashing.' ), array( 'status' => 501 ) ); 633 674 } … … 646 687 /** 647 688 * Fires after a comment is deleted via the REST API. 648 689 * 690 * @since 4.7.0 691 * 649 692 * @param object $comment The deleted comment data. 650 693 * @param WP_REST_Response $response The response returned from the API. 651 694 * @param WP_REST_Request $request The request sent to the API. … … 656 699 } 657 700 658 701 /** 659 * Prepare a single comment output for response.702 * Prepares a single comment output for response. 660 703 * 704 * @since 4.7.0 705 * 661 706 * @param object $comment Comment object. 662 707 * @param WP_REST_Request $request Request object. 663 708 * @return WP_REST_Response $response … … 699 744 $data = $this->add_additional_fields_to_object( $data, $request ); 700 745 $data = $this->filter_response_by_context( $data, $context ); 701 746 702 // Wrap the data in a response object 747 // Wrap the data in a response object. 703 748 $response = rest_ensure_response( $data ); 704 749 705 750 $response->add_links( $this->prepare_links( $comment ) ); 706 751 707 752 /** 708 * Filter a comment returned from the API.753 * Filters a comment returned from the API. 709 754 * 710 755 * Allows modification of the comment right before it is returned. 711 756 * 757 * @since 4.7.0 758 * 712 759 * @param WP_REST_Response $response The response object. 713 760 * @param object $comment The original comment object. 714 761 * @param WP_REST_Request $request Request used to generate the response. … … 717 764 } 718 765 719 766 /** 720 * Prepare links for the request.767 * Prepares links for the request. 721 768 * 769 * @since 4.7.0 770 * 722 771 * @param object $comment Comment object. 723 772 * @return array Links for the given comment. 724 773 */ … … 775 824 } 776 825 777 826 /** 778 * Prepend internal property prefix to query parameters to match our response fields.827 * Prepends internal property prefix to query parameters to match our response fields. 779 828 * 780 * @param string $query_param 829 * @since 4.7.0 830 * 831 * @param string $query_param Query parameter. 781 832 * @return string $normalized 782 833 */ 783 834 protected function normalize_query_param( $query_param ) { … … 805 856 } 806 857 807 858 /** 808 * Check comment_approved to set comment status for single comment output.859 * Checks comment_approved to set comment status for single comment output. 809 860 * 810 * @param string|int $comment_approved 861 * @since 4.7.0 862 * 863 * @param string|int $comment_approved comment status. 811 864 * @return string $status 812 865 */ 813 866 protected function prepare_status_response( $comment_approved ) { … … 834 887 } 835 888 836 889 /** 837 * Prepare a single comment to be inserted into the database.890 * Prepares a single comment to be inserted into the database. 838 891 * 892 * @since 4.7.0 893 * 839 894 * @param WP_REST_Request $request Request object. 840 895 * @return array|WP_Error $prepared_comment 841 896 */ … … 921 976 } 922 977 923 978 /** 924 * Get the Comment's schema, conforming to JSON Schema979 * Gets the Comment's schema, conforming to JSON Schema. 925 980 * 981 * @since 4.7.0 982 * 926 983 * @return array 927 984 */ 928 985 public function get_item_schema() { … … 1082 1139 } 1083 1140 1084 1141 /** 1085 * Get the query params for collections1142 * Gets the query params for collections. 1086 1143 * 1144 * @since 4.7.0 1145 * 1087 1146 * @return array 1088 1147 */ 1089 1148 public function get_collection_params() { … … 1208 1267 } 1209 1268 1210 1269 /** 1211 * Set the comment_status of a given comment object when creating or updating a comment.1270 * Sets the comment_status of a given comment object when creating or updating a comment. 1212 1271 * 1213 * @param string|int $new_status 1214 * @param object $comment 1272 * @since 4.7.0 1273 * 1274 * @param string|int $new_status New comment status. 1275 * @param object $comment Comment data. 1215 1276 * @return boolean $changed 1216 1277 */ 1217 1278 protected function handle_status_param( $new_status, $comment ) { … … 1252 1313 } 1253 1314 1254 1315 /** 1255 * Check if we can read a post.1316 * Checks if we can read a post. 1256 1317 * 1257 1318 * Correctly handles posts with the inherit status. 1258 1319 * 1320 * @since 4.7.0 1321 * 1259 1322 * @param WP_Post $post Post Object. 1260 1323 * @return boolean Can we read it? 1261 1324 */ … … 1266 1329 } 1267 1330 1268 1331 /** 1269 * Check if we can read a comment.1332 * Checks if we can read a comment. 1270 1333 * 1271 * @param object $comment Comment object. 1334 * @since 4.7.0 1335 * 1336 * @param object $comment Comment object. 1272 1337 * @return boolean Can we read it? 1273 1338 */ 1274 1339 protected function check_read_permission( $comment ) { … … 1297 1362 } 1298 1363 1299 1364 /** 1300 * Check if we can edit or delete a comment.1365 * Checks if we can edit or delete a comment. 1301 1366 * 1302 * @param object $comment Comment object. 1367 * @since 4.7.0 1368 * 1369 * @param object $comment Comment object. 1303 1370 * @return boolean Can we edit or delete it? 1304 1371 */ 1305 1372 protected function check_edit_permission( $comment ) { -
src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 11 * Core base class extended to access via REST API. 12 * 13 * @since 4.7.0 14 */ 4 15 abstract class WP_REST_Controller { 5 16 6 17 /** 7 18 * The namespace of this controller's route. 8 19 * 20 * @since 4.7.0 21 * @access protected 9 22 * @var string 10 23 */ 11 24 protected $namespace; … … 13 26 /** 14 27 * The base of this controller's route. 15 28 * 29 * @since 4.7.0 30 * @access protected 16 31 * @var string 17 32 */ 18 33 protected $rest_base; 19 34 20 35 /** 21 * Register the routes for the objects of the controller. 36 * Registers the routes for the objects of the controller. 37 * 38 * @since 4.7.0 22 39 */ 23 40 public function register_routes() { 24 41 _doing_it_wrong( 'WP_REST_Controller::register_routes', __( 'The register_routes() method must be overridden' ), 'WPAPI-2.0' ); … … 25 42 } 26 43 27 44 /** 28 * Check if a given request has access to get items.45 * Checks if a given request has access to get items. 29 46 * 47 * @since 4.7.0 48 * 30 49 * @param WP_REST_Request $request Full data about the request. 31 50 * @return WP_Error|boolean 32 51 */ … … 35 54 } 36 55 37 56 /** 38 * Get a collection of items.57 * Gets a collection of items. 39 58 * 59 * @since 4.7.0 60 * 40 61 * @param WP_REST_Request $request Full data about the request. 41 62 * @return WP_Error|WP_REST_Response 42 63 */ … … 45 66 } 46 67 47 68 /** 48 * Check if a given request has access to get a specific item.69 * Checks if a given request has access to get a specific item. 49 70 * 71 * @since 4.7.0 72 * 50 73 * @param WP_REST_Request $request Full data about the request. 51 74 * @return WP_Error|boolean 52 75 */ … … 55 78 } 56 79 57 80 /** 58 * Get one item from the collection.81 * Gets one item from the collection. 59 82 * 83 * @since 4.7.0 84 * 60 85 * @param WP_REST_Request $request Full data about the request. 61 86 * @return WP_Error|WP_REST_Response 62 87 */ … … 65 90 } 66 91 67 92 /** 68 * Check if a given request has access to create items.93 * Checks if a given request has access to create items. 69 94 * 95 * @since 4.7.0 96 * 70 97 * @param WP_REST_Request $request Full data about the request. 71 98 * @return WP_Error|boolean 72 99 */ … … 75 102 } 76 103 77 104 /** 78 * Create one item from the collection.105 * Creates one item from the collection. 79 106 * 107 * @since 4.7.0 108 * 80 109 * @param WP_REST_Request $request Full data about the request. 81 110 * @return WP_Error|WP_REST_Response 82 111 */ … … 85 114 } 86 115 87 116 /** 88 * Check if a given request has access to update a specific item.117 * Checks if a given request has access to update a specific item. 89 118 * 119 * @since 4.7.0 120 * 90 121 * @param WP_REST_Request $request Full data about the request. 91 122 * @return WP_Error|boolean 92 123 */ … … 95 126 } 96 127 97 128 /** 98 * Update one item from the collection.129 * Updates one item from the collection. 99 130 * 131 * @since 4.7.0 132 * 100 133 * @param WP_REST_Request $request Full data about the request. 101 134 * @return WP_Error|WP_REST_Response 102 135 */ … … 105 138 } 106 139 107 140 /** 108 * Check if a given request has access to delete a specific item.141 * Checks if a given request has access to delete a specific item. 109 142 * 143 * @since 4.7.0 144 * 110 145 * @param WP_REST_Request $request Full data about the request. 111 146 * @return WP_Error|boolean 112 147 */ … … 115 150 } 116 151 117 152 /** 118 * Delete one item from the collection.153 * Deletes one item from the collection. 119 154 * 155 * @since 4.7.0 156 * 120 157 * @param WP_REST_Request $request Full data about the request. 121 158 * @return WP_Error|WP_REST_Response 122 159 */ … … 125 162 } 126 163 127 164 /** 128 * Prepare the item for create or update operation.165 * Prepares the item for create or update operation. 129 166 * 167 * @since 4.7.0 168 * 130 169 * @param WP_REST_Request $request Request object. 131 170 * @return WP_Error|object $prepared_item 132 171 */ … … 135 174 } 136 175 137 176 /** 138 * Prepare the item for the REST response.177 * Prepares the item for the REST response. 139 178 * 140 * @param mixed $item WordPress representation of the item. 179 * @since 4.7.0 180 * 181 * @param mixed $item WordPress representation of the item. 141 182 * @param WP_REST_Request $request Request object. 142 183 * @return WP_Error|WP_REST_Response $response 143 184 */ … … 146 187 } 147 188 148 189 /** 149 * Prepare a response for inserting into a collection.190 * Prepares a response for inserting into a collection. 150 191 * 192 * @since 4.7.0 193 * 151 194 * @param WP_REST_Response $response Response object. 152 195 * @return array Response data, ready for insertion into collection data. 153 196 */ … … 173 216 } 174 217 175 218 /** 176 * Filter a response based on the context defined in the schema.219 * Filters a response based on the context defined in the schema. 177 220 * 178 * @param array $data 179 * @param string $context 221 * @since 4.7.0 222 * 223 * @param array $data Response data to fiter. 224 * @param string $context Context defined in the schema. 180 225 * @return array 181 226 */ 182 227 public function filter_response_by_context( $data, $context ) { … … 210 255 } 211 256 212 257 /** 213 * Get the item's schema, conforming to JSON Schema.258 * Gets the item's schema, conforming to JSON Schema. 214 259 * 260 * @since 4.7.0 261 * 215 262 * @return array 216 263 */ 217 264 public function get_item_schema() { … … 219 266 } 220 267 221 268 /** 222 * Get the item's schema for display / public consumption purposes.269 * Gets the item's schema for display / public consumption purposes. 223 270 * 271 * @since 4.7.0 272 * 224 273 * @return array 225 274 */ 226 275 public function get_public_item_schema() { … … 235 284 } 236 285 237 286 /** 238 * Get the query params for collections.287 * Gets the query params for collections. 239 288 * 289 * @since 4.7.0 290 * 240 291 * @return array 241 292 */ 242 293 public function get_collection_params() { … … 269 320 } 270 321 271 322 /** 272 * Get the magical context param.323 * Gets the magical context param. 273 324 * 274 325 * Ensures consistent description between endpoints, and populates enum from schema. 275 326 * 276 * @param array $args 327 * @since 4.7.0 328 * 329 * @param array $args Additional arguments for context parameter. 277 330 * @return array 278 331 */ 279 332 public function get_context_param( $args = array() ) { … … 301 354 } 302 355 303 356 /** 304 * Add the values from additional fields to a data object.357 * Adds the values from additional fields to a data object. 305 358 * 306 * @param array $object 307 * @param WP_REST_Request $request 359 * @since 4.7.0 360 * 361 * @param array $object data object. 362 * @param WP_REST_Request $request Full details about the request. 308 363 * @return array modified object with additional fields. 309 364 */ 310 365 protected function add_additional_fields_to_object( $object, $request ) { … … 324 379 } 325 380 326 381 /** 327 * Update the values of additional fields added to a data object.382 * Updates the values of additional fields added to a data object. 328 383 * 329 * @param array $object 330 * @param WP_REST_Request $request 384 * @since 4.7.0 385 * 386 * @param array $object data Object. 387 * @param WP_REST_Request $request Full details about the request. 331 388 * @return bool|WP_Error True on success, WP_Error object if a field cannot be updated. 332 389 */ 333 390 protected function update_additional_fields_for_object( $object, $request ) { … … 353 410 } 354 411 355 412 /** 356 * Add the schema from additional fields to an schema array.413 * Adds the schema from additional fields to an schema array. 357 414 * 358 415 * The type of object is inferred from the passed schema. 359 416 * 417 * @since 4.7.0 418 * 360 419 * @param array $schema Schema array. 361 420 * @return array Modified Schema array. 362 421 */ … … 384 443 } 385 444 386 445 /** 387 * Get all the registered additional fields for a given object-type.446 * Gets all the registered additional fields for a given object-type. 388 447 * 389 * @param string $object_type 448 * @since 4.7.0 449 * 450 * @param string $object_type Optional, default is null. Type of the Object. 390 451 * @return array 391 452 */ 392 453 protected function get_additional_fields( $object_type = null ) { … … 409 470 } 410 471 411 472 /** 412 * Get the object type this controller is responsible for managing.473 * Gets the object type this controller is responsible for managing. 413 474 * 475 * @since 4.7.0 476 * 414 477 * @return string 415 478 */ 416 479 protected function get_object_type() { … … 424 487 } 425 488 426 489 /** 427 * Get an array of endpoint arguments from the item schema for the controller.490 * Gets an array of endpoint arguments from the item schema for the controller. 428 491 * 492 * @since 4.7.0 493 * 429 494 * @param string $method HTTP method of the request. The arguments 430 495 * for `CREATABLE` requests are checked for required 431 496 * values and may fall-back to a given default, this … … 492 557 * resultant post object. This is done so that plugins may manipulate the 493 558 * post that is used in the REST API. 494 559 * 560 * @since 4.7.0 561 * 495 562 * @see get_post() 496 563 * @global WP_Query $wp_query 497 564 * … … 502 569 $post_obj = get_post( $post ); 503 570 504 571 /** 505 * Filter the post.572 * Filters the post. 506 573 * 507 574 * Allows plugins to filter the post object as returned by `\WP_REST_Controller::get_post()`. 508 575 * … … 515 582 } 516 583 517 584 /** 518 * Sanitize the slug value.585 * Sanitizes the slug value. 519 586 * 587 * @since 4.7.0 588 * 520 589 * @internal We can't use {@see sanitize_title} directly, as the second 521 590 * parameter is the fallback title, which would end up being set to the 522 591 * request object. -
src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Post_Statuses_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Access post statuses. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Post_Statuses_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 = 'statuses'; … … 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 post statuses.58 * Checks whether a given request has permission to read post statuses. 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 */ … … 55 76 } 56 77 57 78 /** 58 * Get all post statuses, depending on user context79 * Gets all post statuses, depending on user context. 59 80 * 60 * @param WP_REST_Request $request 81 * @since 4.7.0 82 * 83 * @param WP_REST_Request $request Full details about the request. 61 84 * @return array|WP_Error 62 85 */ 63 86 public function get_items( $request ) { … … 78 101 /** 79 102 * Check if a given request has access to read a post status. 80 103 * 104 * @since 4.7.0 105 * 81 106 * @param WP_REST_Request $request Full details about the request. 82 107 * @return WP_Error|boolean 83 108 */ … … 94 119 } 95 120 96 121 /** 97 * Check whether a given post status should be visible122 * Checks whether a given post status should be visible. 98 123 * 99 * @param object $status 124 * @since 4.7.0 125 * 126 * @param object $status Post status. 100 127 * @return boolean 101 128 */ 102 129 protected function check_read_permission( $status ) { … … 115 142 } 116 143 117 144 /** 118 * Get a specific post status145 * Gets a specific post status. 119 146 * 120 * @param WP_REST_Request $request 147 * @since 4.7.0 148 * 149 * @param WP_REST_Request $request Full details about the request. 121 150 * @return array|WP_Error 122 151 */ 123 152 public function get_item( $request ) { … … 130 159 } 131 160 132 161 /** 133 * Prepare a post status object for serialization162 * Prepares a post status object for serialization. 134 163 * 135 * @param stdClass $status Post status data 136 * @param WP_REST_Request $request 164 * @since 4.7.0 165 * 166 * @param stdClass $status Post status data. 167 * @param WP_REST_Request $request Full details about the request. 137 168 * @return WP_REST_Response Post status data 138 169 */ 139 170 public function prepare_item_for_response( $status, $request ) { … … 161 192 } 162 193 163 194 /** 164 * Filter a status returned from the API.195 * Filters a status returned from the API. 165 196 * 166 197 * Allows modification of the status data right before it is returned. 167 198 * 199 * @since 4.7.0 200 * 168 201 * @param WP_REST_Response $response The response object. 169 202 * @param object $status The original status object. 170 203 * @param WP_REST_Request $request Request used to generate the response. … … 173 206 } 174 207 175 208 /** 176 * Get the Post status' schema, conforming to JSON Schema209 * Gets the Post status' schema, conforming to JSON Schema. 177 210 * 211 * @since 4.7.0 212 * 178 213 * @return array 179 214 */ 180 215 public function get_item_schema() { … … 231 266 } 232 267 233 268 /** 234 * Get the query params for collections269 * Gets the query params for collections. 235 270 * 271 * @since 4.7.0 272 * 236 273 * @return array 237 274 */ 238 275 public function get_collection_params() { -
src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Post_Types_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Access post types. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Post_Types_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 = 'types'; … … 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 … … 35 54 } 36 55 37 56 /** 38 * Check whether a given request has permission to read types.57 * Checks whether a given request has permission to read types. 39 58 * 59 * @since 4.7.0 60 * 40 61 * @param WP_REST_Request $request Full details about the request. 41 62 * @return WP_Error|boolean 42 63 */ … … 53 74 } 54 75 55 76 /** 56 * Get all public post types77 * Gets all public post types. 57 78 * 58 * @param WP_REST_Request $request 79 * @since 4.7.0 80 * 81 * @param WP_REST_Request $request Full details about the request. 59 82 * @return array|WP_Error 60 83 */ 61 84 public function get_items( $request ) { … … 71 94 } 72 95 73 96 /** 74 * Get a specific post type97 * Gets a specific post type. 75 98 * 76 * @param WP_REST_Request $request 99 * @since 4.7.0 100 * 101 * @param WP_REST_Request $request Full details about the request. 77 102 * @return array|WP_Error 78 103 */ 79 104 public function get_item( $request ) { … … 92 117 } 93 118 94 119 /** 95 * Prepare a post type object for serialization120 * Prepares a post type object for serialization. 96 121 * 97 * @param stdClass $post_type Post type data 98 * @param WP_REST_Request $request 122 * @since 4.7.0 123 * 124 * @param stdClass $post_type Post type data. 125 * @param WP_REST_Request $request Full details about the request. 99 126 * @return WP_REST_Response $response 100 127 */ 101 128 public function prepare_item_for_response( $post_type, $request ) { … … 125 152 ) ); 126 153 127 154 /** 128 * Filter a post type returned from the API.155 * Filters a post type returned from the API. 129 156 * 130 157 * Allows modification of the post type data right before it is returned. 131 158 * 159 * @since 4.7.0 160 * 132 161 * @param WP_REST_Response $response The response object. 133 162 * @param object $item The original post type object. 134 163 * @param WP_REST_Request $request Request used to generate the response. … … 137 166 } 138 167 139 168 /** 140 * Get the Post type's schema, conforming to JSON Schema169 * Gets the Post type's schema, conforming to JSON Schema. 141 170 * 171 * @since 4.7.0 172 * 142 173 * @return array 143 174 */ 144 175 public function get_item_schema() { … … 189 220 } 190 221 191 222 /** 192 * Get the query params for collections223 * Gets the query params for collections. 193 224 * 225 * @since 4.7.0 226 * 194 227 * @return array 195 228 */ 196 229 public function get_collection_params() { -
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Posts_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Access Post. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Posts_Controller extends WP_REST_Controller { 4 16 5 17 /** 6 18 * Post type. 7 19 * 20 * @since 4.7.0 8 21 * @access protected 9 22 * @var string 10 23 */ … … 13 26 /** 14 27 * Instance of a post meta fields object. 15 28 * 29 * @since 4.7.0 16 30 * @access protected 17 31 * @var WP_REST_Post_Meta_Fields 18 32 */ … … 21 35 /** 22 36 * Constructor. 23 37 * 38 * @since 4.7.0 24 39 * @param string $post_type Post type. 25 40 */ 26 41 public function __construct( $post_type ) { … … 33 48 } 34 49 35 50 /** 36 * Register the routes for the objects of the controller. 51 * Registers the routes for the objects of the controller. 52 * 53 * @since 4.7.0 37 54 */ 38 55 public function register_routes() { 39 56 … … 86 103 } 87 104 88 105 /** 89 * Check if a given request has access to read /posts.106 * Checks if a given request has access to read /posts. 90 107 * 108 * @since 4.7.0 109 * 91 110 * @param WP_REST_Request $request Full details about the request. 92 111 * @return WP_Error|boolean 93 112 */ … … 103 122 } 104 123 105 124 /** 106 * Get a collection of posts.125 * Gets a collection of posts. 107 126 * 127 * @since 4.7.0 128 * 108 129 * @param WP_REST_Request $request Full details about the request. 109 130 * @return WP_Error|WP_REST_Response 110 131 */ … … 140 161 'status' => 'post_status', 141 162 ); 142 163 143 // For each known parameter which is both registered and present in the request, 144 // set the parameter's value on the query $args. 164 /* 165 * For each known parameter which is both registered and present 166 * in the request, set the parameter's value on the query $args. 167 */ 145 168 foreach ( $parameter_mappings as $api_param => $wp_param ) { 146 169 if ( isset( $registered[ $api_param ], $request[ $api_param ] ) ) { 147 170 $args[ $wp_param ] = $request[ $api_param ]; … … 197 220 $args['post_type'] = $this->post_type; 198 221 199 222 /** 200 * Filter the query arguments for a request.223 * Filters the query arguments for a request. 201 224 * 202 225 * Enables adding extra arguments or setting defaults for a post 203 226 * collection request. 204 227 * 228 * @since 4.7.0 229 * 205 230 * @see https://developer.wordpress.org/reference/classes/wp_query/ 206 231 * 207 232 * @param array $args Key value array of query var to query value. … … 300 325 } 301 326 302 327 /** 303 * Check if a given request has access to read a post.328 * Checks if a given request has access to read a post. 304 329 * 330 * @since 4.7.0 331 * 305 332 * @param WP_REST_Request $request Full details about the request. 306 333 * @return WP_Error|boolean 307 334 */ … … 333 360 } 334 361 335 362 /** 336 * C an the user access password-protected content?363 * Checks if the user can access password-protected content. 337 364 * 338 365 * This method determines whether we need to override the regular password 339 366 * check in core with a filter. 340 367 * 368 * @since 4.7.0 369 * 341 370 * @param WP_Post $post Post to check against. 342 371 * @param WP_REST_Request $request Request data to check. 343 372 * @return bool True if the user can access password-protected content, false otherwise. … … 363 392 } 364 393 365 394 /** 366 * Get a single post.395 * Gets a single post. 367 396 * 397 * @since 4.7.0 398 * 368 399 * @param WP_REST_Request $request Full details about the request. 369 400 * @return WP_Error|WP_REST_Response 370 401 */ … … 387 418 } 388 419 389 420 /** 390 * Check if a given request has access to create a post.421 * Checks if a given request has access to create a post. 391 422 * 423 * @since 4.7.0 424 * 392 425 * @param WP_REST_Request $request Full details about the request. 393 426 * @return WP_Error|boolean 394 427 */ … … 411 444 } 412 445 413 446 /** 414 * Create a single post.447 * Creates a single post. 415 448 * 449 * @since 4.7.0 450 * 416 451 * @param WP_REST_Request $request Full details about the request. 417 452 * @return WP_Error|WP_REST_Response 418 453 */ … … 498 533 } 499 534 500 535 /** 501 * Check if a given request has access to update a post.536 * Checks if a given request has access to update a post. 502 537 * 538 * @since 4.7.0 539 * 503 540 * @param WP_REST_Request $request Full details about the request. 504 541 * @return WP_Error|boolean 505 542 */ … … 524 561 } 525 562 526 563 /** 527 * Update a single post.564 * Updates a single post. 528 565 * 566 * @since 4.7.0 567 * 529 568 * @param WP_REST_Request $request Full details about the request. 530 569 * @return WP_Error|WP_REST_Response 531 570 */ … … 602 641 } 603 642 604 643 /** 605 * Check if a given request has access to delete a post.644 * Checks if a given request has access to delete a post. 606 645 * 646 * @since 4.7.0 647 * 607 648 * @param WP_REST_Request $request Full details about the request. 608 649 * @return bool|WP_Error 609 650 */ … … 619 660 } 620 661 621 662 /** 622 * Delete a single post.663 * Deletes a single post. 623 664 * 665 * @since 4.7.0 666 * 624 667 * @param WP_REST_Request $request Full details about the request. 625 668 * @return WP_REST_Response|WP_Error 626 669 */ … … 640 683 } 641 684 642 685 /** 643 * Filter whether a post is trashable.686 * Filters whether a post is trashable. 644 687 * 645 688 * Return false to disable trash support for the post. 646 689 * 690 * @since 4.7.0 691 * 647 692 * @param boolean $supports_trash Whether the post type support trashing. 648 693 * @param WP_Post $post The Post object being considered for trashing support. 649 694 */ … … 692 737 } 693 738 694 739 /** 695 * Determine the allowed query_vars for a get_items() response and740 * Determines the allowed query_vars for a get_items() response and 696 741 * prepare for WP_Query. 697 742 * 743 * @since 4.7.0 744 * 698 745 * @param array $prepared_args Prepared WP_Query arguments. 699 746 * @param WP_REST_Request $request Full details about the request. 700 747 * @return array $query_args … … 706 753 foreach ( $valid_vars as $var => $index ) { 707 754 if ( isset( $prepared_args[ $var ] ) ) { 708 755 /** 709 * Filter the query_vars used in `get_items` for the constructed query.756 * Filters the query_vars used in `get_items` for the constructed query. 710 757 * 711 758 * The dynamic portion of the hook name, $var, refers to the query_var key. 712 759 * 760 * @since 4.7.0 761 * 713 762 * @param mixed $prepared_args[ $var ] The query_var value. 714 763 */ 715 764 $query_args[ $var ] = apply_filters( "rest_query_var-{$var}", $prepared_args[ $var ] ); … … 728 777 } 729 778 730 779 /** 731 * Get all the WP Query vars that are allowed for the API request.780 * Gets all the WP Query vars that are allowed for the API request. 732 781 * 782 * @since 4.7.0 783 * 733 784 * @param WP_REST_Request $request Full details about the request. 734 785 * @return array 735 786 */ … … 737 788 global $wp; 738 789 739 790 /** 740 * Filter the publicly allowed query vars.791 * Filters the publicly allowed query vars. 741 792 * 742 793 * Allows adjusting of the default query vars that are made public. 743 794 * 795 * @since 4.7.0 796 * 744 797 * @param array Array of allowed WP_Query query vars. 745 798 */ 746 799 $valid_vars = apply_filters( 'query_vars', $wp->public_query_vars ); … … 748 801 $post_type_obj = get_post_type_object( $this->post_type ); 749 802 if ( current_user_can( $post_type_obj->cap->edit_posts ) ) { 750 803 /** 751 * Filter the allowed 'private' query vars for authorized users.804 * Filters the allowed 'private' query vars for authorized users. 752 805 * 753 806 * If the user has the `edit_posts` capability, we also allow use of 754 807 * private query parameters, which are only undesirable on the … … 757 810 * To disable anyway, use 758 811 * `add_filter( 'rest_private_query_vars', '__return_empty_array' );` 759 812 * 813 * @since 4.7.0 814 * 760 815 * @param array $private_query_vars Array of allowed query vars for authorized users. 761 816 * } 762 817 */ … … 781 836 $valid_vars = array_merge( $valid_vars, $rest_valid ); 782 837 783 838 /** 784 * Filter allowed query vars for the REST API.839 * Filters allowed query vars for the REST API. 785 840 * 786 841 * This filter allows you to add or remove query vars from the final allowed 787 842 * list for all requests, including unauthenticated ones. To alter the 788 843 * vars for editors only, {@see rest_private_query_vars}. 789 844 * 845 * @since 4.7.0 846 * 790 847 * @param array { 791 848 * Array of allowed WP_Query query vars. 792 849 * … … 800 857 } 801 858 802 859 /** 803 * Check the post_date_gmt or modified_gmt and prepare any post or860 * Checks the post_date_gmt or modified_gmt and prepare any post or 804 861 * modified date for single post output. 805 862 * 863 * @since 4.7.0 864 * 806 865 * @param string $date_gmt GMT publication time. 807 866 * @param string|null $date Optional, default is null. Local publication time. 808 867 * @return string|null ISO8601/RFC3339 formatted datetime. … … 823 882 } 824 883 825 884 /** 826 * Prepare a single post for create or update.885 * Prepares a single post for create or update. 827 886 * 887 * @since 4.7.0 888 * 828 889 * @param WP_REST_Request $request Request object. 829 890 * @return WP_Error|stdClass $prepared_post Post object. 830 891 */ … … 960 1021 $prepared_post->ping_status = $request['ping_status']; 961 1022 } 962 1023 /** 963 * Filter a post before it is inserted via the REST API.1024 * Filters a post before it is inserted via the REST API. 964 1025 * 965 1026 * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being 966 1027 * prepared for insertion. 967 1028 * 1029 * @since 4.7.0 1030 * 968 1031 * @param stdClass $prepared_post An object representing a single post prepared 969 1032 * for inserting or updating the database. 970 1033 * @param WP_REST_Request $request Request object. … … 974 1037 } 975 1038 976 1039 /** 977 * Determine validity and normalize provided status param.1040 * Determines validity and normalize provided status param. 978 1041 * 1042 * @since 4.7.0 1043 * 979 1044 * @param string $post_status Post status. 980 1045 * @param object $post_type Post type. 981 1046 * @return WP_Error|string $post_status … … 1008 1073 } 1009 1074 1010 1075 /** 1011 * Determine the featured media based on a request param.1076 * Determines the featured media based on a request param. 1012 1077 * 1078 * @since 4.7.0 1079 * 1013 1080 * @param int $featured_media Featured Media ID. 1014 1081 * @param int $post_id Post ID. 1015 1082 * @return bool|WP_Error … … 1031 1098 } 1032 1099 1033 1100 /** 1034 * Set the template for a page.1101 * Sets the template for a page. 1035 1102 * 1103 * @since 4.7.0 1104 * 1036 1105 * @param string $template Page template filename. 1037 1106 * @param integer $post_id Post ID. 1038 1107 */ … … 1045 1114 } 1046 1115 1047 1116 /** 1048 * Update the post's terms from a REST request.1117 * Updates the post's terms from a REST request. 1049 1118 * 1119 * @since 4.7.0 1120 * 1050 1121 * @param int $post_id The post ID to update the terms form. 1051 1122 * @param WP_REST_Request $request The request object with post and terms data. 1052 1123 * @return null|WP_Error WP_Error on an error assigning any of the terms. … … 1068 1139 } 1069 1140 1070 1141 /** 1071 * Check if a given post type should be viewed or managed.1142 * Checks if a given post type should be viewed or managed. 1072 1143 * 1144 * @since 4.7.0 1145 * 1073 1146 * @param object|string $post_type Post type name or object. 1074 1147 * @return boolean Is post type allowed? 1075 1148 */ … … 1086 1159 } 1087 1160 1088 1161 /** 1089 * Check if we can read a post.1162 * Checks if we can read a post. 1090 1163 * 1091 1164 * Correctly handles posts with the inherit status. 1092 1165 * 1166 * @since 4.7.0 1167 * 1093 1168 * @param object $post Post object. 1094 1169 * @return boolean Can we read it? 1095 1170 */ … … 1125 1200 } 1126 1201 1127 1202 /** 1128 * Check if we can edit a post.1203 * Checks if we can edit a post. 1129 1204 * 1205 * @since 4.7.0 1206 * 1130 1207 * @param object $post Post object. 1131 1208 * @return boolean Can we edit it? 1132 1209 */ … … 1141 1218 } 1142 1219 1143 1220 /** 1144 * Check if we can create a post.1221 * Checks if we can create a post. 1145 1222 * 1223 * @since 4.7.0 1224 * 1146 1225 * @param object $post Post object. 1147 1226 * @return boolean Can we create it?. 1148 1227 */ … … 1157 1236 } 1158 1237 1159 1238 /** 1160 * Check if we can delete a post.1239 * Checks if we can delete a post. 1161 1240 * 1241 * @since 4.7.0 1242 * 1162 1243 * @param object $post Post object. 1163 1244 * @return boolean Can we delete it? 1164 1245 */ … … 1173 1254 } 1174 1255 1175 1256 /** 1176 * Prepare a single post output for response.1257 * Prepares a single post output for response. 1177 1258 * 1259 * @since 4.7.0 1260 * 1178 1261 * @param WP_Post $post Post object. 1179 1262 * @param WP_REST_Request $request Request object. 1180 1263 * @return WP_REST_Response $data … … 1343 1426 $response->add_links( $this->prepare_links( $post ) ); 1344 1427 1345 1428 /** 1346 * Filter the post data for a response.1429 * Filters the post data for a response. 1347 1430 * 1348 1431 * The dynamic portion of the hook name, $this->post_type, refers to post_type of the post being 1349 1432 * prepared for the response. 1350 1433 * 1434 * @since 4.7.0 1435 * 1351 1436 * @param WP_REST_Response $response The response object. 1352 1437 * @param WP_Post $post Post object. 1353 1438 * @param WP_REST_Request $request Request object. … … 1356 1441 } 1357 1442 1358 1443 /** 1359 * Overwrite the default protected title format.1444 * Overwrites the default protected title format. 1360 1445 * 1361 1446 * By default WordPress will show password protected posts with a title of 1362 1447 * "Protected: %s", as the REST API communicates the protected status of a post … … 1369 1454 } 1370 1455 1371 1456 /** 1372 * Prepare links for the request.1457 * Prepares links for the request. 1373 1458 * 1459 * @since 4.7.0 1460 * 1374 1461 * @param WP_Post $post Post object. 1375 1462 * @return array Links for the given post. 1376 1463 */ … … 1466 1553 } 1467 1554 1468 1555 /** 1469 * Get the Post's schema, conforming to JSON Schema.1556 * Gets the Post's schema, conforming to JSON Schema. 1470 1557 * 1471 1558 * @return array 1472 1559 */ … … 1476 1563 '$schema' => 'http://json-schema.org/draft-04/schema#', 1477 1564 'title' => $this->post_type, 1478 1565 'type' => 'object', 1479 /* 1480 * Base properties for every Post. 1481 */ 1566 // Base properties for every Post. 1482 1567 'properties' => array( 1483 1568 'date' => array( 1484 1569 'description' => __( "The date the object was published, in the site's timezone." ), … … 1795 1880 } 1796 1881 1797 1882 /** 1798 * Get the query params for collections of attachments.1883 * Gets the query params for collections of attachments. 1799 1884 * 1800 1885 * @return array 1801 1886 */ … … 1938 2023 } 1939 2024 1940 2025 /** 1941 * Validate whether the user can query private statuses.2026 * Validates whether the user can query private statuses. 1942 2027 * 2028 * @since 4.7.0 2029 * 1943 2030 * @param mixed $value Post status. 1944 2031 * @param WP_REST_Request $request Full details about the request. 1945 2032 * @param string $parameter -
src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Revisions_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Access revisions. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Revisions_Controller extends WP_REST_Controller { 4 16 17 /** 18 * Parent post type. 19 * 20 * @since 4.7.0 21 * @access private 22 * @var string 23 */ 5 24 private $parent_post_type; 25 26 /** 27 * Parent controller. 28 * 29 * @since 4.7.0 30 * @access private 31 * @var WP_REST_Controller 32 */ 6 33 private $parent_controller; 34 35 /** 36 * The base of the parent controller's route. 37 * 38 * @since 4.7.0 39 * @access private 40 * @var string 41 */ 7 42 private $parent_base; 8 43 44 /** 45 * Constructor. 46 * 47 * @since 4.7.0 48 * 49 * @param string $parent_post_type Post type of the parent. 50 */ 9 51 public function __construct( $parent_post_type ) { 10 52 $this->parent_post_type = $parent_post_type; 11 53 $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type ); … … 16 58 } 17 59 18 60 /** 19 * Register routes for revisions based on post types supporting revisions61 * Registers routes for revisions based on post types supporting revisions. 20 62 * 21 * @ access public63 * @since 4.7.0 22 64 */ 23 65 public function register_routes() { 24 66 … … 52 94 } 53 95 54 96 /** 55 * Check if a given request has access to get revisions97 * Checks if a given request has access to get revisions. 56 98 * 57 * @ access public99 * @since 4.7.0 58 100 * 59 101 * @param WP_REST_Request $request Full data about the request. 60 102 * @return WP_Error|boolean … … 74 116 } 75 117 76 118 /** 77 * Get a collection of revisions119 * Gets a collection of revisions. 78 120 * 79 * @ access public121 * @since 4.7.0 80 122 * 81 123 * @param WP_REST_Request $request Full data about the request. 82 124 * @return WP_Error|WP_REST_Response … … 99 141 } 100 142 101 143 /** 102 * Check if a given request has access to get a specific revision144 * Checks if a given request has access to get a specific revision. 103 145 * 104 * @ access public146 * @since 4.7.0 105 147 * 106 148 * @param WP_REST_Request $request Full data about the request. 107 149 * @return WP_Error|boolean … … 111 153 } 112 154 113 155 /** 114 * Get one revision from the collection156 * Gets one revision from the collection. 115 157 * 116 * @ access public158 * @since 4.7.0 117 159 * 118 160 * @param WP_REST_Request $request Full data about the request. 119 161 * @return WP_Error|array … … 135 177 } 136 178 137 179 /** 138 * Check if a given request has access to delete a revision180 * Checks if a given request has access to delete a revision. 139 181 * 140 * @ access public182 * @since 4.7.0 141 183 * 142 184 * @param WP_REST_Request $request Full details about the request. 143 185 * @return WP_Error|boolean … … 158 200 } 159 201 160 202 /** 161 * Delete a single revision203 * Deletes a single revision. 162 204 * 163 * @ access public205 * @since 4.7.0 164 206 * 165 207 * @param WP_REST_Request $request Full details about the request. 166 208 * @return WP_Error|boolean … … 171 213 /** 172 214 * Fires after a revision is deleted via the REST API. 173 215 * 216 * @since 4.7.0 217 * 174 218 * @param (mixed) $result The revision object (if it was deleted or moved to the trash successfully) 175 219 * or false (failure). If the revision was moved to to the trash, $result represents 176 220 * its new state; if it was deleted, $result represents its state before deletion. … … 186 230 } 187 231 188 232 /** 189 * Prepare the revision for the REST response233 * Prepares the revision for the REST response. 190 234 * 191 * @ access public235 * @since 4.7.0 192 236 * 193 237 * @param WP_Post $post Post revision object. 194 238 * @param WP_REST_Request $request Request object. … … 273 317 } 274 318 275 319 /** 276 * Filter a revision returned from the API.320 * Filters a revision returned from the API. 277 321 * 278 322 * Allows modification of the revision right before it is returned. 279 323 * … … 285 329 } 286 330 287 331 /** 288 * Check the post_date_gmt or modified_gmt and prepare any post or332 * Checks the post_date_gmt or modified_gmt and prepare any post or 289 333 * modified date for single post output. 290 334 * 291 335 * @access protected … … 307 351 } 308 352 309 353 /** 310 * Get the revision's schema, conforming to JSON Schema354 * Gets the revision's schema, conforming to JSON Schema. 311 355 * 312 * @ access public356 * @since 4.7.0 313 357 * 314 358 * @return array 315 359 */ … … 318 362 '$schema' => 'http://json-schema.org/draft-04/schema#', 319 363 'title' => "{$this->parent_post_type}-revision", 320 364 'type' => 'object', 321 /* 322 * Base properties for every Revision 323 */ 365 // Base properties for every Revision. 324 366 'properties' => array( 325 367 'author' => array( 326 368 'description' => __( 'The id for the author of the object.' ), … … 393 435 } 394 436 395 437 /** 396 * Get the query params for collections438 * Gets the query params for collections. 397 439 * 398 * @ access public440 * @since 4.7.0 399 441 * 400 442 * @return array 401 443 */ … … 406 448 } 407 449 408 450 /** 409 * Check the post excerpt and prepare it for single post output.451 * Checks the post excerpt and prepare it for single post output. 410 452 * 411 453 * @access protected 412 454 * -
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. 12 * 13 * @since 4.7.0 5 14 */ 6 7 15 class WP_REST_Settings_Controller extends WP_REST_Controller { 8 16 9 17 protected $rest_base = 'settings'; … … 10 18 protected $namespace = 'wp/v2'; 11 19 12 20 /** 13 * Register the routes for the objects of the controller. 21 * Registers the routes for the objects of the controller. 22 * 23 * @since 4.7.0 14 24 */ 15 25 public function register_routes() { 16 26 register_rest_route( $this->namespace, '/' . $this->rest_base, array( … … 31 41 } 32 42 33 43 /** 34 * Check if a given request has access to read and manage settings.44 * Checks if a given request has access to read and manage settings. 35 45 * 46 * @since 4.7.0 47 * 36 48 * @param WP_REST_Request $request Full details about the request. 37 49 * @return boolean 38 50 */ … … 41 53 } 42 54 43 55 /** 44 * Get the settings.56 * Gets the settings. 45 57 * 58 * @since 4.7.0 59 * 46 60 * @param WP_REST_Request $request Full details about the request. 47 61 * @return WP_Error|array 48 62 */ … … 81 95 } 82 96 83 97 /** 84 * Prepare a value for output based off a schema array.98 * Prepares a value for output based off a schema array. 85 99 * 86 * @param mixed $value 87 * @param array $schema 100 * @since 4.7.0 101 * 102 * @param mixed $value Value to prepare. 103 * @param array $schema Schema to match. 88 104 * @return mixed 89 105 */ 90 106 protected function prepare_value( $value, $schema ) { … … 101 117 } 102 118 103 119 /** 104 * Update settings for the settings object.120 * Updates settings for the settings object. 105 121 * 122 * @since 4.7.0 123 * 106 124 * @param WP_REST_Request $request Full detail about the request. 107 125 * @return WP_Error|array 108 126 */ … … 147 165 } 148 166 149 167 /** 150 * Get all the registered options for the Settings API168 * Gets all the registered options for the Settings API. 151 169 * 170 * @since 4.7.0 171 * 152 172 * @return array 153 173 */ 154 174 protected function get_registered_options() { … … 197 217 } 198 218 199 219 /** 200 * Get the site setting schema, conforming to JSON Schema.220 * Gets the site setting schema, conforming to JSON Schema. 201 221 * 222 * @since 4.7.0 223 * 202 224 * @return array 203 225 */ 204 226 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() { -
src/wp-includes/rest-api/fields/class-wp-rest-comment-meta-fields.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Comment_Meta_Fields class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Manage meta values for comments. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Comment_Meta_Fields extends WP_REST_Meta_Fields { 16 4 17 /** 5 18 * Get the object type for meta. 6 19 * 20 * @since 4.7.0 21 * 7 22 * @return string 8 23 */ 9 24 protected function get_meta_type() { … … 13 28 /** 14 29 * Get the type for `register_rest_field`. 15 30 * 31 * @since 4.7.0 32 * 16 33 * @return string 17 34 */ 18 35 public function get_rest_field_type() { -
src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Meta_Fields class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 4 11 * Manage meta values for an object. 12 * 13 * @since 4.7.0 5 14 */ 6 15 abstract class WP_REST_Meta_Fields { 7 16 … … 8 17 /** 9 18 * Get the object type for meta. 10 19 * 20 * @since 4.7.0 21 * 11 22 * @return string One of 'post', 'comment', 'term', 'user', or anything 12 23 * else supported by `_get_meta_table()`. 13 24 */ … … 16 27 /** 17 28 * Get the object type for `register_rest_field`. 18 29 * 30 * @since 4.7.0 31 * 19 32 * @return string Custom post type, 'taxonomy', 'comment', or `user`. 20 33 */ 21 34 abstract protected function get_rest_field_type(); … … 22 35 23 36 /** 24 37 * Register the meta field. 38 * 39 * @since 4.7.0 25 40 */ 26 41 public function register_field() { 27 42 register_rest_field( $this->get_rest_field_type(), 'meta', array( … … 34 49 /** 35 50 * Get the `meta` field value. 36 51 * 52 * @since 4.7.0 53 * 37 54 * @param int $object_id Object ID to fetch meta for. 38 55 * @param WP_REST_Request $request Full details about the request. 39 56 * @return WP_Error|object … … 71 88 * the database, such as booleans. We need to cast back to the relevant 72 89 * type before passing back to JSON. 73 90 * 91 * @since 4.7.0 92 * 74 93 * @param mixed $value Value to prepare. 75 94 * @param WP_REST_Request $request Current request object. 76 95 * @param array $args Options for the field. … … 87 106 /** 88 107 * Update meta values. 89 108 * 109 * @since 4.7.0 110 * 90 111 * @param WP_REST_Request $request Full details about the request. 91 112 * @param int $object_id Object ID to fetch meta for. 92 113 * @return WP_Error|null Error if one occurs, null on success. … … 120 141 /** 121 142 * Delete meta value for an object. 122 143 * 144 * @since 4.7.0 145 * 123 146 * @param int $object_id Object ID the field belongs to. 124 147 * @param string $name Key for the field. 125 148 * @return bool|WP_Error True if meta field is deleted, error otherwise. … … 149 172 * 150 173 * Alters the list of values in the database to match the list of provided values. 151 174 * 175 * @since 4.7.0 176 * 152 177 * @param int $object_id Object ID to update. 153 178 * @param string $name Key for the custom field. 154 179 * @param array $values List of values to update to. … … 211 236 /** 212 237 * Update meta value for an object. 213 238 * 239 * @since 4.7.0 240 * 214 241 * @param int $object_id Object ID to update. 215 242 * @param string $name Key for the custom field. 216 243 * @param mixed $value Updated value. … … 251 278 /** 252 279 * Get all the registered meta fields. 253 280 * 281 * @since 4.7.0 282 * 254 283 * @return array 255 284 */ 256 285 protected function get_registered_fields() { … … 305 334 /** 306 335 * Get the object's `meta` schema, conforming to JSON Schema. 307 336 * 337 * @since 4.7.0 338 * 308 339 * @return array 309 340 */ 310 341 public function get_field_schema() { … … 330 361 * Default preparation for meta fields. Override by passing the 331 362 * `prepare_callback` in your `show_in_rest` options. 332 363 * 364 * @since 4.7.0 365 * 333 366 * @param mixed $value Meta value from the database. 334 367 * @param WP_REST_Request $request Request object. 335 368 * @param array $args REST-specific options for the meta key. -
src/wp-includes/rest-api/fields/class-wp-rest-post-meta-fields.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Post_Meta_Fields class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Manage meta values for posts. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_Post_Meta_Fields extends WP_REST_Meta_Fields { 16 4 17 /** 5 18 * Post type to register fields for. 6 19 * 20 * @since 4.7.0 21 * @access protected 7 22 * @var string 8 23 */ 9 24 protected $post_type; … … 11 26 /** 12 27 * Constructor. 13 28 * 29 * @since 4.7.0 30 * 14 31 * @param string $post_type Post type to register fields for. 15 32 */ 16 33 public function __construct( $post_type ) { … … 20 37 /** 21 38 * Get the object type for meta. 22 39 * 40 * @since 4.7.0 41 * 23 42 * @return string 24 43 */ 25 44 protected function get_meta_type() { … … 29 48 /** 30 49 * Get the type for `register_rest_field`. 31 50 * 51 * @since 4.7.0 52 * 32 53 * @return string Custom post type slug. 33 54 */ 34 55 public function get_rest_field_type() { -
src/wp-includes/rest-api/fields/class-wp-rest-term-meta-fields.php
1 1 <?php 2 /** 3 * REST API: WP_REST_Term_Meta_Fields class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 3 10 /** 4 11 * Manage meta values for terms. 12 * 13 * @since 4.7.0 5 14 */ 6 15 class WP_REST_Term_Meta_Fields extends WP_REST_Meta_Fields { 16 7 17 /** 8 18 * Taxonomy to register fields for. 9 19 * 20 * @since 4.7.0 21 * @access protected 10 22 * @var string 11 23 */ 12 24 protected $taxonomy; 25 13 26 /** 14 27 * Constructor. 15 28 * 29 * @since 4.7.0 30 * 16 31 * @param string $taxonomy Taxonomy to register fields for. 17 32 */ 18 33 public function __construct( $taxonomy ) { … … 22 37 /** 23 38 * Get the object type for meta. 24 39 * 40 * @since 4.7.0 41 * 25 42 * @return string 26 43 */ 27 44 protected function get_meta_type() { … … 31 48 /** 32 49 * Get the type for `register_rest_field`. 33 50 * 51 * @since 4.7.0 52 * 34 53 * @return string 35 54 */ 36 55 public function get_rest_field_type() { -
src/wp-includes/rest-api/fields/class-wp-rest-user-meta-fields.php
1 1 <?php 2 /** 3 * REST API: WP_REST_User_Meta_Fields class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 2 9 10 /** 11 * Manage meta values for users. 12 * 13 * @since 4.7.0 14 */ 3 15 class WP_REST_User_Meta_Fields extends WP_REST_Meta_Fields { 16 4 17 /** 5 18 * Get the object type for meta. 6 19 * 20 * @since 4.7.0 21 * 7 22 * @return string 8 23 */ 9 24 protected function get_meta_type() { … … 13 28 /** 14 29 * Get the type for `register_rest_field`. 15 30 * 31 * @since 4.7.0 32 * 16 33 * @return string 17 34 */ 18 35 public function get_rest_field_type() {