Changeset 39028
- Timestamp:
- 10/30/2016 05:49:14 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
r38832 r39028 1 1 <?php 2 2 /** 3 * REST API: WP_REST_Revisions_Controller class 4 * 5 * @package WordPress 6 * @subpackage REST_API 7 * @since 4.7.0 8 */ 9 10 /** 11 * Core class used to access revisions via the REST API. 12 * 13 * @since 4.7.0 14 * 15 * @see WP_REST_Controller 16 */ 3 17 class WP_REST_Revisions_Controller extends WP_REST_Controller { 4 18 19 /** 20 * Parent post type. 21 * 22 * @since 4.7.0 23 * @access private 24 * @var string 25 */ 5 26 private $parent_post_type; 27 28 /** 29 * Parent controller. 30 * 31 * @since 4.7.0 32 * @access private 33 * @var WP_REST_Controller 34 */ 6 35 private $parent_controller; 36 37 /** 38 * The base of the parent controller's route. 39 * 40 * @since 4.7.0 41 * @access private 42 * @var string 43 */ 7 44 private $parent_base; 8 45 46 /** 47 * Constructor. 48 * 49 * @since 4.7.0 50 * @access public 51 * 52 * @param string $parent_post_type Post type of the parent. 53 */ 9 54 public function __construct( $parent_post_type ) { 10 55 $this->parent_post_type = $parent_post_type; … … 17 62 18 63 /** 19 * Register routes for revisions based on post types supporting revisions 20 * 21 * @access public 64 * Registers routes for revisions based on post types supporting revisions. 65 * 66 * @since 4.7.0 67 * @access public 68 * 69 * @see register_rest_route() 22 70 */ 23 71 public function register_routes() { … … 25 73 register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base, array( 26 74 array( 27 'methods' => WP_REST_Server::READABLE,28 'callback' => array( $this, 'get_items' ),75 'methods' => WP_REST_Server::READABLE, 76 'callback' => array( $this, 'get_items' ), 29 77 'permission_callback' => array( $this, 'get_items_permissions_check' ), 30 'args' => $this->get_collection_params(),78 'args' => $this->get_collection_params(), 31 79 ), 32 80 'schema' => array( $this, 'get_public_item_schema' ), … … 35 83 register_rest_route( $this->namespace, '/' . $this->parent_base . '/(?P<parent>[\d]+)/' . $this->rest_base . '/(?P<id>[\d]+)', array( 36 84 array( 37 'methods' => WP_REST_Server::READABLE,38 'callback' => array( $this, 'get_item' ),85 'methods' => WP_REST_Server::READABLE, 86 'callback' => array( $this, 'get_item' ), 39 87 'permission_callback' => array( $this, 'get_item_permissions_check' ), 40 'args' => array(41 'context' 88 'args' => array( 89 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 42 90 ), 43 91 ), 44 92 array( 45 'methods' => WP_REST_Server::DELETABLE,46 'callback' => array( $this, 'delete_item' ),93 'methods' => WP_REST_Server::DELETABLE, 94 'callback' => array( $this, 'delete_item' ), 47 95 'permission_callback' => array( $this, 'delete_item_permissions_check' ), 48 96 ), … … 53 101 54 102 /** 55 * Check if a given request has access to get revisions 56 * 103 * Checks if a given request has access to get revisions. 104 * 105 * @since 4.7.0 57 106 * @access public 58 107 * 59 108 * @param WP_REST_Request $request Full data about the request. 60 * @return WP_Error|boolean109 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. 61 110 */ 62 111 public function get_items_permissions_check( $request ) { … … 75 124 76 125 /** 77 * Get a collection of revisions 78 * 126 * Gets a collection of revisions. 127 * 128 * @since 4.7.0 79 129 * @access public 80 130 * 81 131 * @param WP_REST_Request $request Full data about the request. 82 * @return WP_ Error|WP_REST_Response132 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. 83 133 */ 84 134 public function get_items( $request ) { … … 100 150 101 151 /** 102 * Check if a given request has access to get a specific revision 103 * 152 * Checks if a given request has access to get a specific revision. 153 * 154 * @since 4.7.0 104 155 * @access public 105 156 * 106 157 * @param WP_REST_Request $request Full data about the request. 107 * @return WP_Error|boolean158 * @return bool|WP_Error True if the request has read access for the item, WP_Error object otherwise. 108 159 */ 109 160 public function get_item_permissions_check( $request ) { … … 112 163 113 164 /** 114 * Get one revision from the collection 115 * 165 * Retrieves one revision from the collection. 166 * 167 * @since 4.7.0 116 168 * @access public 117 169 * 118 170 * @param WP_REST_Request $request Full data about the request. 119 * @return WP_ Error|array171 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. 120 172 */ 121 173 public function get_item( $request ) { … … 136 188 137 189 /** 138 * Check if a given request has access to delete a revision 139 * 190 * Checks if a given request has access to delete a revision. 191 * 192 * @since 4.7.0 140 193 * @access public 141 194 * 142 195 * @param WP_REST_Request $request Full details about the request. 143 * @return WP_Error|boolean196 * @return bool|WP_Error True if the request has access to delete the item, WP_Error object otherwise. 144 197 */ 145 198 public function delete_item_permissions_check( $request ) { … … 159 212 160 213 /** 161 * Delete a single revision 162 * 214 * Deletes a single revision. 215 * 216 * @since 4.7.0 163 217 * @access public 164 218 * 165 219 * @param WP_REST_Request $request Full details about the request. 166 * @return WP_Error|boolean220 * @return true|WP_Error True on success, or WP_Error object on failure. 167 221 */ 168 222 public function delete_item( $request ) { … … 171 225 /** 172 226 * Fires after a revision is deleted via the REST API. 227 * 228 * @since 4.7.0 173 229 * 174 230 * @param (mixed) $result The revision object (if it was deleted or moved to the trash successfully) … … 187 243 188 244 /** 189 * Prepare the revision for the REST response 190 * 245 * Prepares the revision for the REST response. 246 * 247 * @since 4.7.0 191 248 * @access public 192 249 * 193 250 * @param WP_Post $post Post revision object. 194 251 * @param WP_REST_Request $request Request object. 195 * @return WP_REST_Response $response252 * @return WP_REST_Response Response object. 196 253 */ 197 254 public function prepare_item_for_response( $post, $request ) { … … 274 331 275 332 /** 276 * Filter a revision returned from the API.333 * Filters a revision returned from the API. 277 334 * 278 335 * Allows modification of the revision right before it is returned. 279 336 * 280 * @param WP_REST_Response $response The response object. 281 * @param WP_Post $post The original revision object. 282 * @param WP_REST_Request $request Request used to generate the response. 337 * @since 4.7.0 338 * 339 * @param WP_REST_Response $response The response object. 340 * @param WP_Post $post The original revision object. 341 * @param WP_REST_Request $request Request used to generate the response. 283 342 */ 284 343 return apply_filters( 'rest_prepare_revision', $response, $post, $request ); … … 286 345 287 346 /** 288 * Check the post_date_gmt or modified_gmt and prepare any post or347 * Checks the post_date_gmt or modified_gmt and prepare any post or 289 348 * modified date for single post output. 290 349 * 350 * @since 4.7.0 291 351 * @access protected 292 352 * 293 353 * @param string $date_gmt GMT publication time. 294 * @param string|null $date Optional , default is null. Local publication time.295 * @return string|null ISO8601/RFC3339 formatted datetime .354 * @param string|null $date Optional. Local publication time. Default null. 355 * @return string|null ISO8601/RFC3339 formatted datetime, otherwise null. 296 356 */ 297 357 protected function prepare_date_response( $date_gmt, $date = null ) { … … 308 368 309 369 /** 310 * Get the revision's schema, conforming to JSON Schema 311 * 312 * @access public 313 * 314 * @return array 370 * Retrieves the revision's schema, conforming to JSON Schema. 371 * 372 * @since 4.7.0 373 * @access public 374 * 375 * @return array Item schema data. 315 376 */ 316 377 public function get_item_schema() { … … 319 380 'title' => "{$this->parent_post_type}-revision", 320 381 'type' => 'object', 321 /* 322 * Base properties for every Revision 323 */ 382 // Base properties for every Revision. 324 383 'properties' => array( 325 384 'author' => array( … … 380 439 $schema['properties']['title'] = $parent_schema['properties']['title']; 381 440 } 441 382 442 if ( ! empty( $parent_schema['properties']['content'] ) ) { 383 443 $schema['properties']['content'] = $parent_schema['properties']['content']; 384 444 } 445 385 446 if ( ! empty( $parent_schema['properties']['excerpt'] ) ) { 386 447 $schema['properties']['excerpt'] = $parent_schema['properties']['excerpt']; 387 448 } 449 388 450 if ( ! empty( $parent_schema['properties']['guid'] ) ) { 389 451 $schema['properties']['guid'] = $parent_schema['properties']['guid']; … … 394 456 395 457 /** 396 * Get the query params for collections 397 * 398 * @access public 399 * 400 * @return array 458 * Retrieves the query params for collections. 459 * 460 * @since 4.7.0 461 * @access public 462 * 463 * @return array Collection parameters. 401 464 */ 402 465 public function get_collection_params() { … … 407 470 408 471 /** 409 * Check the post excerpt and prepare it for single post output. 410 * 472 * Checks the post excerpt and prepare it for single post output. 473 * 474 * @since 4.7.0 411 475 * @access protected 412 476 * 413 477 * @param string $excerpt The post excerpt. 414 478 * @param WP_Post $post Post revision object. 415 * @return string |null $excerpt479 * @return string Prepared excerpt or empty string. 416 480 */ 417 481 protected function prepare_excerpt_response( $excerpt, $post ) {
Note: See TracChangeset
for help on using the changeset viewer.