WordPress.org

Make WordPress Core

Ticket #40861: 40861.2.patch

File 40861.2.patch, 983 bytes (added by ocean90, 22 months ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

     
    136136                }
    137137
    138138                $attachment                 = $this->prepare_item_for_database( $request );
    139                 $attachment->file           = $file;
    140139                $attachment->post_mime_type = $type;
    141140                $attachment->guid           = $url;
    142141
     
    144143                        $attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) );
    145144                }
    146145
    147                 $id = wp_insert_post( wp_slash( (array) $attachment ), true );
     146                // $post_parent is inherited from $attachment['post_parent'].
     147                $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true );
    148148
    149149                if ( is_wp_error( $id ) ) {
    150150                        if ( 'db_update_error' === $id->get_error_code() ) {