From 4c11410c586c62ae6289059a5413cc58a3c8834f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 24 Jul 2018 16:54:26 +0000 Subject: [PATCH] REST API: Ensure attachments created with `WP_REST_Attachments_Controller::create_item()` on Windows have a relative path. Props ocean90, SergeyBiryukov, redcastor. Merges [43529] to the 4.9 branch. Fixes #40861. Built from https://develop.svn.wordpress.org/branches/4.9@43530 git-svn-id: http://core.svn.wordpress.org/branches/4.9@43359 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-attachments-controller.php | 4 ++-- wp-includes/version.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 273a848f10..ac357a0ef1 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -136,7 +136,6 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } $attachment = $this->prepare_item_for_database( $request ); - $attachment->file = $file; $attachment->post_mime_type = $type; $attachment->guid = $url; @@ -144,7 +143,8 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { $attachment->post_title = preg_replace( '/\.[^.]+$/', '', basename( $file ) ); } - $id = wp_insert_post( wp_slash( (array) $attachment ), true ); + // $post_parent is inherited from $attachment['post_parent']. + $id = wp_insert_attachment( wp_slash( (array) $attachment ), $file, 0, true ); if ( is_wp_error( $id ) ) { if ( 'db_update_error' === $id->get_error_code() ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 96966c5265..ca185229b1 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.9.8-beta2-43528'; +$wp_version = '4.9.8-beta2-43530'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.