WordPress.org

Make WordPress Core

Ticket #44789: 44789.diff

File 44789.diff, 1.5 KB (added by iCaleb, 3 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
    index 90ab5185fd..b283d9fab5 100644
    a b class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 
    106106
    107107                if ( ! empty( $files ) ) {
    108108                        $file = $this->upload_from_file( $files, $headers );
     109                        $name = $files['file']['name'];
     110                        $ext  = pathinfo( $name, PATHINFO_EXTENSION );
     111                        $name = wp_basename( $name, ".$ext" );
    109112                } else {
    110113                        $file = $this->upload_from_data( $request->get_body(), $headers );
     114                        $name = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
    111115                }
    112116
    113117                if ( is_wp_error( $file ) ) {
    114118                        return $file;
    115119                }
    116120
    117                 $name       = basename( $file['file'] );
    118                 $name_parts = pathinfo( $name );
    119                 $name       = trim( substr( $name, 0, -( 1 + strlen( $name_parts['extension'] ) ) ) );
    120 
    121121                $url  = $file['url'];
    122122                $type = $file['type'];
    123123                $file = $file['file'];
    class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { 
    140140                $attachment->guid           = $url;
    141141
    142142                if ( empty( $attachment->post_title ) ) {
    143                         $attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
     143                        $attachment->post_title = sanitize_text_field( $name );
    144144                }
    145145
    146146                // $post_parent is inherited from $attachment['post_parent'].