Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r46696 r47122  
    9595
    9696        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            );
    98102        }
    99103
     
    104108
    105109            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                );
    107115            }
    108116        }
     
    120128     */
    121129    public function create_item( $request ) {
    122 
    123130        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            );
    125136        }
    126137
     
    214225        require_once ABSPATH . 'wp-admin/includes/image.php';
    215226
    216         // use image exif/iptc data for title and caption defaults if possible
     227        // Use image exif/iptc data for title and caption defaults if possible.
    217228        $image_meta = wp_read_image_metadata( $file );
    218229
     
    279290    public function update_item( $request ) {
    280291        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            );
    282297        }
    283298
     
    358373        $prepared_attachment = parent::prepare_item_for_database( $request );
    359374
    360         // Attachment caption (post_excerpt internally)
     375        // Attachment caption (post_excerpt internally).
    361376        if ( isset( $request['caption'] ) ) {
    362377            if ( is_string( $request['caption'] ) ) {
     
    367382        }
    368383
    369         // Attachment description (post_content internally)
     384        // Attachment description (post_content internally).
    370385        if ( isset( $request['description'] ) ) {
    371386            if ( is_string( $request['description'] ) ) {
     
    540555            'context'     => array( 'view', 'edit', 'embed' ),
    541556            '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().
    544559            ),
    545560            'properties'  => array(
     
    563578            'context'     => array( 'view', 'edit' ),
    564579            '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().
    567582            ),
    568583            'properties'  => array(
     
    628643
    629644        $this->schema = $schema;
     645
    630646        return $this->add_additional_fields_schema( $this->schema );
    631647    }
     
    642658    protected function upload_from_data( $data, $headers ) {
    643659        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            );
    645665        }
    646666
    647667        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            );
    649673        }
    650674
    651675        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            );
    653681        }
    654682
     
    656684
    657685        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            );
    659691        }
    660692
     
    665697
    666698            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                );
    668704            }
    669705        }
     
    681717
    682718        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            );
    684724        }
    685725
     
    709749            @unlink( $tmpfname );
    710750
    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            );
    712756        }
    713757
     
    825869    protected function upload_from_file( $files, $headers ) {
    826870        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            );
    828876        }
    829877
     
    835883
    836884            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                );
    838890            }
    839891        }
     
    860912
    861913        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            );
    863919        }
    864920
     
    913969
    914970        $file_size = filesize( $file['tmp_name'] );
     971
    915972        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            );
    918979        }
    919980
    920981        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            );
    923988        }
    924989
     
    927992
    928993        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
    9311001        return true;
    9321002    }
Note: See TracChangeset for help on using the changeset viewer.