Changeset 47122 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
- Timestamp:
- 01/29/2020 12:43:23 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
r46696 r47122 95 95 96 96 if ( ! current_user_can( 'upload_files' ) ) { 97 return new WP_Error( 'rest_cannot_create', __( 'Sorry, you are not allowed to upload media on this site.' ), array( 'status' => 400 ) ); 97 return new WP_Error( 98 'rest_cannot_create', 99 __( 'Sorry, you are not allowed to upload media on this site.' ), 100 array( 'status' => 400 ) 101 ); 98 102 } 99 103 … … 104 108 105 109 if ( ! current_user_can( $post_parent_type->cap->edit_post, $request['post'] ) ) { 106 return new WP_Error( 'rest_cannot_edit', __( 'Sorry, you are not allowed to upload media to this post.' ), array( 'status' => rest_authorization_required_code() ) ); 110 return new WP_Error( 111 'rest_cannot_edit', 112 __( 'Sorry, you are not allowed to upload media to this post.' ), 113 array( 'status' => rest_authorization_required_code() ) 114 ); 107 115 } 108 116 } … … 120 128 */ 121 129 public function create_item( $request ) { 122 123 130 if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { 124 return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); 131 return new WP_Error( 132 'rest_invalid_param', 133 __( 'Invalid parent type.' ), 134 array( 'status' => 400 ) 135 ); 125 136 } 126 137 … … 214 225 require_once ABSPATH . 'wp-admin/includes/image.php'; 215 226 216 // use image exif/iptc data for title and caption defaults if possible227 // Use image exif/iptc data for title and caption defaults if possible. 217 228 $image_meta = wp_read_image_metadata( $file ); 218 229 … … 279 290 public function update_item( $request ) { 280 291 if ( ! empty( $request['post'] ) && in_array( get_post_type( $request['post'] ), array( 'revision', 'attachment' ), true ) ) { 281 return new WP_Error( 'rest_invalid_param', __( 'Invalid parent type.' ), array( 'status' => 400 ) ); 292 return new WP_Error( 293 'rest_invalid_param', 294 __( 'Invalid parent type.' ), 295 array( 'status' => 400 ) 296 ); 282 297 } 283 298 … … 358 373 $prepared_attachment = parent::prepare_item_for_database( $request ); 359 374 360 // Attachment caption (post_excerpt internally) 375 // Attachment caption (post_excerpt internally). 361 376 if ( isset( $request['caption'] ) ) { 362 377 if ( is_string( $request['caption'] ) ) { … … 367 382 } 368 383 369 // Attachment description (post_content internally) 384 // Attachment description (post_content internally). 370 385 if ( isset( $request['description'] ) ) { 371 386 if ( is_string( $request['description'] ) ) { … … 540 555 'context' => array( 'view', 'edit', 'embed' ), 541 556 'arg_options' => array( 542 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database() 543 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() 557 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database(). 558 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database(). 544 559 ), 545 560 'properties' => array( … … 563 578 'context' => array( 'view', 'edit' ), 564 579 'arg_options' => array( 565 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database() 566 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database() 580 'sanitize_callback' => null, // Note: sanitization implemented in self::prepare_item_for_database(). 581 'validate_callback' => null, // Note: validation implemented in self::prepare_item_for_database(). 567 582 ), 568 583 'properties' => array( … … 628 643 629 644 $this->schema = $schema; 645 630 646 return $this->add_additional_fields_schema( $this->schema ); 631 647 } … … 642 658 protected function upload_from_data( $data, $headers ) { 643 659 if ( empty( $data ) ) { 644 return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); 660 return new WP_Error( 661 'rest_upload_no_data', 662 __( 'No data supplied.' ), 663 array( 'status' => 400 ) 664 ); 645 665 } 646 666 647 667 if ( empty( $headers['content_type'] ) ) { 648 return new WP_Error( 'rest_upload_no_content_type', __( 'No Content-Type supplied.' ), array( 'status' => 400 ) ); 668 return new WP_Error( 669 'rest_upload_no_content_type', 670 __( 'No Content-Type supplied.' ), 671 array( 'status' => 400 ) 672 ); 649 673 } 650 674 651 675 if ( empty( $headers['content_disposition'] ) ) { 652 return new WP_Error( 'rest_upload_no_content_disposition', __( 'No Content-Disposition supplied.' ), array( 'status' => 400 ) ); 676 return new WP_Error( 677 'rest_upload_no_content_disposition', 678 __( 'No Content-Disposition supplied.' ), 679 array( 'status' => 400 ) 680 ); 653 681 } 654 682 … … 656 684 657 685 if ( empty( $filename ) ) { 658 return new WP_Error( 'rest_upload_invalid_disposition', __( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), array( 'status' => 400 ) ); 686 return new WP_Error( 687 'rest_upload_invalid_disposition', 688 __( 'Invalid Content-Disposition supplied. Content-Disposition needs to be formatted as `attachment; filename="image.png"` or similar.' ), 689 array( 'status' => 400 ) 690 ); 659 691 } 660 692 … … 665 697 666 698 if ( $expected !== $actual ) { 667 return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); 699 return new WP_Error( 700 'rest_upload_hash_mismatch', 701 __( 'Content hash did not match expected.' ), 702 array( 'status' => 412 ) 703 ); 668 704 } 669 705 } … … 681 717 682 718 if ( ! $fp ) { 683 return new WP_Error( 'rest_upload_file_error', __( 'Could not open file handle.' ), array( 'status' => 500 ) ); 719 return new WP_Error( 720 'rest_upload_file_error', 721 __( 'Could not open file handle.' ), 722 array( 'status' => 500 ) 723 ); 684 724 } 685 725 … … 709 749 @unlink( $tmpfname ); 710 750 711 return new WP_Error( 'rest_upload_sideload_error', $sideloaded['error'], array( 'status' => 500 ) ); 751 return new WP_Error( 752 'rest_upload_sideload_error', 753 $sideloaded['error'], 754 array( 'status' => 500 ) 755 ); 712 756 } 713 757 … … 825 869 protected function upload_from_file( $files, $headers ) { 826 870 if ( empty( $files ) ) { 827 return new WP_Error( 'rest_upload_no_data', __( 'No data supplied.' ), array( 'status' => 400 ) ); 871 return new WP_Error( 872 'rest_upload_no_data', 873 __( 'No data supplied.' ), 874 array( 'status' => 400 ) 875 ); 828 876 } 829 877 … … 835 883 836 884 if ( $expected !== $actual ) { 837 return new WP_Error( 'rest_upload_hash_mismatch', __( 'Content hash did not match expected.' ), array( 'status' => 412 ) ); 885 return new WP_Error( 886 'rest_upload_hash_mismatch', 887 __( 'Content hash did not match expected.' ), 888 array( 'status' => 412 ) 889 ); 838 890 } 839 891 } … … 860 912 861 913 if ( isset( $file['error'] ) ) { 862 return new WP_Error( 'rest_upload_unknown_error', $file['error'], array( 'status' => 500 ) ); 914 return new WP_Error( 915 'rest_upload_unknown_error', 916 $file['error'], 917 array( 'status' => 500 ) 918 ); 863 919 } 864 920 … … 913 969 914 970 $file_size = filesize( $file['tmp_name'] ); 971 915 972 if ( $space_left < $file_size ) { 916 /* translators: %s: Required disk space in kilobytes. */ 917 return new WP_Error( 'rest_upload_limited_space', sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ), array( 'status' => 400 ) ); 973 return new WP_Error( 974 'rest_upload_limited_space', 975 /* translators: %s: Required disk space in kilobytes. */ 976 sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) ), 977 array( 'status' => 400 ) 978 ); 918 979 } 919 980 920 981 if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) { 921 /* translators: %s: Maximum allowed file size in kilobytes. */ 922 return new WP_Error( 'rest_upload_file_too_big', sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) ), array( 'status' => 400 ) ); 982 return new WP_Error( 983 'rest_upload_file_too_big', 984 /* translators: %s: Maximum allowed file size in kilobytes. */ 985 sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) ), 986 array( 'status' => 400 ) 987 ); 923 988 } 924 989 … … 927 992 928 993 if ( upload_is_user_over_quota( false ) ) { 929 return new WP_Error( 'rest_upload_user_quota_exceeded', __( 'You have used your space quota. Please delete files before uploading.' ), array( 'status' => 400 ) ); 930 } 994 return new WP_Error( 995 'rest_upload_user_quota_exceeded', 996 __( 'You have used your space quota. Please delete files before uploading.' ), 997 array( 'status' => 400 ) 998 ); 999 } 1000 931 1001 return true; 932 1002 }
Note: See TracChangeset
for help on using the changeset viewer.