Make WordPress Core


Ignore:
Timestamp:
02/11/2020 03:37:17 AM (5 years ago)
Author:
kadamwhite
Message:

REST API: Allow meta to be set when creating a new media record via REST.

Props TimothyBlynJacobs, apermo.
Fixes #44567.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php

    r47122 r47261  
    142142        }
    143143
     144        $schema = $this->get_item_schema();
     145
    144146        // Extract by name.
    145147        $attachment_id = $insert['attachment_id'];
     
    148150        if ( isset( $request['alt_text'] ) ) {
    149151            update_post_meta( $attachment_id, '_wp_attachment_image_alt', sanitize_text_field( $request['alt_text'] ) );
     152        }
     153
     154        if ( ! empty( $schema['properties']['meta'] ) && isset( $request['meta'] ) ) {
     155            $meta_update = $this->meta->update_value( $request['meta'], $attachment_id );
     156
     157            if ( is_wp_error( $meta_update ) ) {
     158                return $meta_update;
     159            }
    150160        }
    151161
Note: See TracChangeset for help on using the changeset viewer.