Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r41727 r42343  
    7676        // Attaching media to a post requires ability to edit said post.
    7777        if ( ! empty( $request['post'] ) ) {
    78             $parent = get_post( (int) $request['post'] );
     78            $parent           = get_post( (int) $request['post'] );
    7979            $post_parent_type = get_post_type_object( $parent->post_type );
    8080
     
    102102
    103103        // Get the file via $_FILES or raw data.
    104         $files = $request->get_file_params();
     104        $files   = $request->get_file_params();
    105105        $headers = $request->get_headers();
    106106
     
    117117        $name       = basename( $file['file'] );
    118118        $name_parts = pathinfo( $name );
    119         $name       = trim( substr( $name, 0, -(1 + strlen( $name_parts['extension'] ) ) ) );
    120 
    121         $url     = $file['url'];
    122         $type    = $file['type'];
    123         $file    = $file['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'];
    124124
    125125        // use image exif/iptc data for title and caption defaults if possible
     
    136136        }
    137137
    138         $attachment = $this->prepare_item_for_database( $request );
    139         $attachment->file = $file;
     138        $attachment                 = $this->prepare_item_for_database( $request );
     139        $attachment->file           = $file;
    140140        $attachment->post_mime_type = $type;
    141         $attachment->guid = $url;
     141        $attachment->guid           = $url;
    142142
    143143        if ( empty( $attachment->post_title ) ) {
     
    214214
    215215        $response = rest_ensure_response( $response );
    216         $data = $response->get_data();
     216        $data     = $response->get_data();
    217217
    218218        if ( isset( $request['alt_text'] ) ) {
     
    285285    public function prepare_item_for_response( $post, $request ) {
    286286        $response = parent::prepare_item_for_response( $post, $request );
    287         $data = $response->get_data();
     287        $data     = $response->get_data();
    288288
    289289        $data['description'] = array(
    290             'raw'       => $post->post_content,
     290            'raw'      => $post->post_content,
    291291            /** This filter is documented in wp-includes/post-template.php */
    292             'rendered'  => apply_filters( 'the_content', $post->post_content ),
     292            'rendered' => apply_filters( 'the_content', $post->post_content ),
    293293        );
    294294
    295295        /** 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 ) );
    297297        $data['caption'] = array(
    298             'raw'       => $post->post_excerpt,
    299             'rendered'  => $caption,
     298            'raw'      => $post->post_excerpt,
     299            'rendered' => $caption,
    300300        );
    301301
     
    378378
    379379        $schema['properties']['alt_text'] = array(
    380             'description'     => __( 'Alternative text to display when attachment is not displayed.' ),
    381             'type'            => 'string',
    382             'context'         => array( 'view', 'edit', 'embed' ),
    383             'arg_options'     => array(
     380            'description' => __( 'Alternative text to display when attachment is not displayed.' ),
     381            'type'        => 'string',
     382            'context'     => array( 'view', 'edit', 'embed' ),
     383            'arg_options' => array(
    384384                'sanitize_callback' => 'sanitize_text_field',
    385385            ),
     
    395395            ),
    396396            'properties'  => array(
    397                 'raw' => array(
     397                'raw'      => array(
    398398                    'description' => __( 'Caption for the attachment, as it exists in the database.' ),
    399399                    'type'        => 'string',
     
    418418            ),
    419419            'properties'  => array(
    420                 'raw' => array(
     420                'raw'      => array(
    421421                    'description' => __( 'Description for the object, as it exists in the database.' ),
    422422                    'type'        => 'string',
     
    433433
    434434        $schema['properties']['media_type'] = array(
    435             'description'     => __( 'Attachment type.' ),
    436             'type'            => 'string',
    437             'enum'            => array( 'image', 'file' ),
    438             'context'         => array( 'view', 'edit', 'embed' ),
    439             'readonly'        => true,
     435            'description' => __( 'Attachment type.' ),
     436            'type'        => 'string',
     437            'enum'        => array( 'image', 'file' ),
     438            'context'     => array( 'view', 'edit', 'embed' ),
     439            'readonly'    => true,
    440440        );
    441441
    442442        $schema['properties']['mime_type'] = array(
    443             'description'     => __( 'The attachment MIME type.' ),
    444             'type'            => 'string',
    445             'context'         => array( 'view', 'edit', 'embed' ),
    446             'readonly'        => true,
     443            'description' => __( 'The attachment MIME type.' ),
     444            'type'        => 'string',
     445            'context'     => array( 'view', 'edit', 'embed' ),
     446            'readonly'    => true,
    447447        );
    448448
    449449        $schema['properties']['media_details'] = array(
    450             'description'     => __( 'Details about the media file, specific to its type.' ),
    451             'type'            => 'object',
    452             'context'         => array( 'view', 'edit', 'embed' ),
    453             'readonly'        => true,
     450            'description' => __( 'Details about the media file, specific to its type.' ),
     451            'type'        => 'object',
     452            'context'     => array( 'view', 'edit', 'embed' ),
     453            'readonly'    => true,
    454454        );
    455455
    456456        $schema['properties']['post'] = array(
    457             'description'     => __( 'The ID for the associated post of the attachment.' ),
    458             'type'            => 'integer',
    459             'context'         => array( 'view', 'edit' ),
     457            'description' => __( 'The ID for the associated post of the attachment.' ),
     458            'type'        => 'integer',
     459            'context'     => array( 'view', 'edit' ),
    460460        );
    461461
    462462        $schema['properties']['source_url'] = array(
    463             'description'     => __( 'URL to the original attachment file.' ),
    464             'type'            => 'string',
    465             'format'          => 'uri',
    466             'context'         => array( 'view', 'edit', 'embed' ),
    467             'readonly'        => true,
     463            'description' => __( 'URL to the original attachment file.' ),
     464            'type'        => 'string',
     465            'format'      => 'uri',
     466            'context'     => array( 'view', 'edit', 'embed' ),
     467            'readonly'    => true,
    468468        );
    469469
     
    630630     */
    631631    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';
    634634        $params['status']['items']['enum'] = array( 'inherit', 'private', 'trash' );
    635         $media_types = $this->get_media_types();
     635        $media_types                       = $this->get_media_types();
    636636
    637637        $params['media_type'] = array(
    638             'default'           => null,
    639             'description'       => __( 'Limit result set to attachments of a particular media type.' ),
    640             'type'              => 'string',
    641             'enum'              => array_keys( $media_types ),
     638            'default'     => null,
     639            'description' => __( 'Limit result set to attachments of a particular media type.' ),
     640            'type'        => 'string',
     641            'enum'        => array_keys( $media_types ),
    642642        );
    643643
     
    696696        // Pass off to WP to handle the actual upload.
    697697        $overrides = array(
    698             'test_form'   => false,
     698            'test_form' => false,
    699699        );
    700700
Note: See TracChangeset for help on using the changeset viewer.