From 12709269c19d435de019b54d2bda7e4bd1ad664e Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Tue, 11 Feb 2020 03:39:06 +0000 Subject: [PATCH] REST API: Allow meta to be set when creating a new media record via REST. Props TimothyBlynJacobs, apermo. Fixes #44567. Built from https://develop.svn.wordpress.org/trunk@47261 git-svn-id: http://core.svn.wordpress.org/trunk@47061 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-attachments-controller.php | 10 ++++++++++ wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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 1d78928fc4..91b21587b1 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 @@ -141,6 +141,8 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { return $insert; } + $schema = $this->get_item_schema(); + // Extract by name. $attachment_id = $insert['attachment_id']; $file = $insert['file']; @@ -149,6 +151,14 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { update_post_meta( $attachment_id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) ); } + if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) { + $meta_update = $this->meta->update_value( $request['meta'], $attachment_id ); + + if ( is_wp_error( $meta_update ) ) { + return $meta_update; + } + } + $attachment = get_post( $attachment_id ); $fields_update = $this->update_additional_fields_for_object( $attachment, $request ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 4e95425bd5..87e861ea90 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.4-alpha-47260'; +$wp_version = '5.4-alpha-47261'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.