- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r41731 r42343 49 49 */ 50 50 public function __construct( $parent_post_type ) { 51 $this->parent_post_type = $parent_post_type;51 $this->parent_post_type = $parent_post_type; 52 52 $this->parent_controller = new WP_REST_Posts_Controller( $parent_post_type ); 53 $this->namespace = 'wp/v2';54 $this->rest_base = 'revisions';55 $post_type_object = get_post_type_object( $parent_post_type );56 $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;53 $this->namespace = 'wp/v2'; 54 $this->rest_base = 'revisions'; 55 $post_type_object = get_post_type_object( $parent_post_type ); 56 $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; 57 57 } 58 58 … … 66 66 public function register_routes() { 67 67 68 register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array( 69 'args' => array( 70 'parent' => array( 71 'description' => __( 'The ID for the parent of the object.' ), 72 'type' => 'integer', 73 ), 74 ), 75 array( 76 'methods' => WP_REST_Server::READABLE, 77 'callback' => array( $this, 'get_items' ), 78 'permission_callback' => array( $this, 'get_items_permissions_check' ), 79 'args' => $this->get_collection_params(), 80 ), 81 'schema' => array( $this, 'get_public_item_schema' ), 82 ) ); 83 84 register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array( 85 'args' => array( 86 'parent' => array( 87 'description' => __( 'The ID for the parent of the object.' ), 88 'type' => 'integer', 89 ), 90 'id' => array( 91 'description' => __( 'Unique identifier for the object.' ), 92 'type' => 'integer', 93 ), 94 ), 95 array( 96 'methods' => WP_REST_Server::READABLE, 97 'callback' => array( $this, 'get_item' ), 98 'permission_callback' => array( $this, 'get_item_permissions_check' ), 99 'args' => array( 100 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 101 ), 102 ), 103 array( 104 'methods' => WP_REST_Server::DELETABLE, 105 'callback' => array( $this, 'delete_item' ), 106 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 107 'args' => array( 108 'force' => array( 109 'type' => 'boolean', 110 'default' => false, 111 'description' => __( 'Required to be true, as revisions do not support trashing.' ), 68 register_rest_route( 69 $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array( 70 'args' => array( 71 'parent' => array( 72 'description' => __( 'The ID for the parent of the object.' ), 73 'type' => 'integer', 112 74 ), 113 75 ), 114 ), 115 'schema' => array( $this, 'get_public_item_schema' ), 116 )); 76 array( 77 'methods' => WP_REST_Server::READABLE, 78 'callback' => array( $this, 'get_items' ), 79 'permission_callback' => array( $this, 'get_items_permissions_check' ), 80 'args' => $this->get_collection_params(), 81 ), 82 'schema' => array( $this, 'get_public_item_schema' ), 83 ) 84 ); 85 86 register_rest_route( 87 $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array( 88 'args' => array( 89 'parent' => array( 90 'description' => __( 'The ID for the parent of the object.' ), 91 'type' => 'integer', 92 ), 93 'id' => array( 94 'description' => __( 'Unique identifier for the object.' ), 95 'type' => 'integer', 96 ), 97 ), 98 array( 99 'methods' => WP_REST_Server::READABLE, 100 'callback' => array( $this, 'get_item' ), 101 'permission_callback' => array( $this, 'get_item_permissions_check' ), 102 'args' => array( 103 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 104 ), 105 ), 106 array( 107 'methods' => WP_REST_Server::DELETABLE, 108 'callback' => array( $this, 'delete_item' ), 109 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 110 'args' => array( 111 'force' => array( 112 'type' => 'boolean', 113 'default' => false, 114 'description' => __( 'Required to be true, as revisions do not support trashing.' ), 115 ), 116 ), 117 ), 118 'schema' => array( $this, 'get_public_item_schema' ), 119 ) 120 ); 117 121 118 122 } … … 202 206 $response = array(); 203 207 foreach ( $revisions as $revision ) { 204 $data = $this->prepare_item_for_response( $revision, $request );208 $data = $this->prepare_item_for_response( $revision, $request ); 205 209 $response[] = $this->prepare_response_for_collection( $data ); 206 210 } … … 314 318 315 319 $response = new WP_REST_Response(); 316 $response->set_data( array( 'deleted' => true, 'previous' => $previous->get_data() ) ); 320 $response->set_data( 321 array( 322 'deleted' => true, 323 'previous' => $previous->get_data(), 324 ) 325 ); 317 326 return $response; 318 327 } … … 399 408 } 400 409 401 $context = ! empty( $request['context'] ) ? $request['context'] : 'view';402 $data = $this->add_additional_fields_to_object( $data, $request );403 $data = $this->filter_response_by_context( $data, $context );410 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 411 $data = $this->add_additional_fields_to_object( $data, $request ); 412 $data = $this->filter_response_by_context( $data, $context ); 404 413 $response = rest_ensure_response( $data ); 405 414 … … 458 467 // Base properties for every Revision. 459 468 'properties' => array( 460 'author' 469 'author' => array( 461 470 'description' => __( 'The ID for the author of the object.' ), 462 471 'type' => 'integer', 463 472 'context' => array( 'view', 'edit', 'embed' ), 464 473 ), 465 'date' 474 'date' => array( 466 475 'description' => __( "The date the object was published, in the site's timezone." ), 467 476 'type' => 'string', … … 469 478 'context' => array( 'view', 'edit', 'embed' ), 470 479 ), 471 'date_gmt' 480 'date_gmt' => array( 472 481 'description' => __( 'The date the object was published, as GMT.' ), 473 482 'type' => 'string', … … 475 484 'context' => array( 'view', 'edit' ), 476 485 ), 477 'guid' 486 'guid' => array( 478 487 'description' => __( 'GUID for the object, as it exists in the database.' ), 479 488 'type' => 'string', 480 489 'context' => array( 'view', 'edit' ), 481 490 ), 482 'id' 491 'id' => array( 483 492 'description' => __( 'Unique identifier for the object.' ), 484 493 'type' => 'integer', 485 494 'context' => array( 'view', 'edit', 'embed' ), 486 495 ), 487 'modified' 496 'modified' => array( 488 497 'description' => __( "The date the object was last modified, in the site's timezone." ), 489 498 'type' => 'string', … … 491 500 'context' => array( 'view', 'edit' ), 492 501 ), 493 'modified_gmt' 502 'modified_gmt' => array( 494 503 'description' => __( 'The date the object was last modified, as GMT.' ), 495 504 'type' => 'string', … … 497 506 'context' => array( 'view', 'edit' ), 498 507 ), 499 'parent' 508 'parent' => array( 500 509 'description' => __( 'The ID for the parent of the object.' ), 501 510 'type' => 'integer', 502 511 'context' => array( 'view', 'edit', 'embed' ), 503 504 'slug' 512 ), 513 'slug' => array( 505 514 'description' => __( 'An alphanumeric identifier for the object unique to its type.' ), 506 515 'type' => 'string',
Note: See TracChangeset
for help on using the changeset viewer.