Changeset 42343 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
- Timestamp:
- 11/30/2017 11:09:33 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r41727 r42343 76 76 // Attaching media to a post requires ability to edit said post. 77 77 if ( ! empty( $request['post'] ) ) { 78 $parent = get_post( (int) $request['post'] );78 $parent = get_post( (int) $request['post'] ); 79 79 $post_parent_type = get_post_type_object( $parent->post_type ); 80 80 … … 102 102 103 103 // Get the file via $_FILES or raw data. 104 $files = $request->get_file_params();104 $files = $request->get_file_params(); 105 105 $headers = $request->get_headers(); 106 106 … … 117 117 $name = basename( $file['file'] ); 118 118 $name_parts = pathinfo( $name ); 119 $name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );120 121 $url 122 $type 123 $file 119 $name = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) ); 120 121 $url = $file['url']; 122 $type = $file['type']; 123 $file = $file['file']; 124 124 125 125 // use image exif/iptc data for title and caption defaults if possible … … 136 136 } 137 137 138 $attachment = $this->prepare_item_for_database( $request );139 $attachment->file = $file;138 $attachment = $this->prepare_item_for_database( $request ); 139 $attachment->file = $file; 140 140 $attachment->post_mime_type = $type; 141 $attachment->guid = $url;141 $attachment->guid = $url; 142 142 143 143 if ( empty( $attachment->post_title ) ) { … … 214 214 215 215 $response = rest_ensure_response( $response ); 216 $data = $response->get_data();216 $data = $response->get_data(); 217 217 218 218 if ( isset( $request['alt_text'] ) ) { … … 285 285 public function prepare_item_for_response( $post, $request ) { 286 286 $response = parent::prepare_item_for_response( $post, $request ); 287 $data = $response->get_data();287 $data = $response->get_data(); 288 288 289 289 $data['description'] = array( 290 'raw' 290 'raw' => $post->post_content, 291 291 /** This filter is documented in wp-includes/post-template.php */ 292 'rendered' 292 'rendered' => apply_filters( 'the_content', $post->post_content ), 293 293 ); 294 294 295 295 /** This filter is documented in wp-includes/post-template.php */ 296 $caption = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) );296 $caption = apply_filters( 'the_excerpt', apply_filters( 'get_the_excerpt', $post->post_excerpt, $post ) ); 297 297 $data['caption'] = array( 298 'raw' 299 'rendered' 298 'raw' => $post->post_excerpt, 299 'rendered' => $caption, 300 300 ); 301 301 … … 378 378 379 379 $schema['properties']['alt_text'] = array( 380 'description' 381 'type' 382 'context' 383 'arg_options' 380 'description' => __( 'Alternative text to display when attachment is not displayed.' ), 381 'type' => 'string', 382 'context' => array( 'view', 'edit', 'embed' ), 383 'arg_options' => array( 384 384 'sanitize_callback' => 'sanitize_text_field', 385 385 ), … … 395 395 ), 396 396 'properties' => array( 397 'raw' => array(397 'raw' => array( 398 398 'description' => __( 'Caption for the attachment, as it exists in the database.' ), 399 399 'type' => 'string', … … 418 418 ), 419 419 'properties' => array( 420 'raw' => array(420 'raw' => array( 421 421 'description' => __( 'Description for the object, as it exists in the database.' ), 422 422 'type' => 'string', … … 433 433 434 434 $schema['properties']['media_type'] = array( 435 'description' 436 'type' 437 'enum' 438 'context' 439 'readonly' 435 'description' => __( 'Attachment type.' ), 436 'type' => 'string', 437 'enum' => array( 'image', 'file' ), 438 'context' => array( 'view', 'edit', 'embed' ), 439 'readonly' => true, 440 440 ); 441 441 442 442 $schema['properties']['mime_type'] = array( 443 'description' 444 'type' 445 'context' 446 'readonly' 443 'description' => __( 'The attachment MIME type.' ), 444 'type' => 'string', 445 'context' => array( 'view', 'edit', 'embed' ), 446 'readonly' => true, 447 447 ); 448 448 449 449 $schema['properties']['media_details'] = array( 450 'description' 451 'type' 452 'context' 453 'readonly' 450 'description' => __( 'Details about the media file, specific to its type.' ), 451 'type' => 'object', 452 'context' => array( 'view', 'edit', 'embed' ), 453 'readonly' => true, 454 454 ); 455 455 456 456 $schema['properties']['post'] = array( 457 'description' 458 'type' 459 'context' 457 'description' => __( 'The ID for the associated post of the attachment.' ), 458 'type' => 'integer', 459 'context' => array( 'view', 'edit' ), 460 460 ); 461 461 462 462 $schema['properties']['source_url'] = array( 463 'description' 464 'type' 465 'format' 466 'context' 467 'readonly' 463 'description' => __( 'URL to the original attachment file.' ), 464 'type' => 'string', 465 'format' => 'uri', 466 'context' => array( 'view', 'edit', 'embed' ), 467 'readonly' => true, 468 468 ); 469 469 … … 630 630 */ 631 631 public function get_collection_params() { 632 $params = parent::get_collection_params();633 $params['status']['default'] = 'inherit';632 $params = parent::get_collection_params(); 633 $params['status']['default'] = 'inherit'; 634 634 $params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' ); 635 $media_types = $this->get_media_types();635 $media_types = $this->get_media_types(); 636 636 637 637 $params['media_type'] = array( 638 'default' 639 'description' 640 'type' 641 'enum' 638 'default' => null, 639 'description' => __( 'Limit result set to attachments of a particular media type.' ), 640 'type' => 'string', 641 'enum' => array_keys( $media_types ), 642 642 ); 643 643 … … 696 696 // Pass off to WP to handle the actual upload. 697 697 $overrides = array( 698 'test_form' 698 'test_form' => false, 699 699 ); 700 700
Note: See TracChangeset
for help on using the changeset viewer.