mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
REST API: Allow meta to be set when creating a new media record via REST.
Props TimothyBlynJacobs, apermo. Fixes #44567. git-svn-id: https://develop.svn.wordpress.org/trunk@47261 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user