[wp-trac] [WordPress Trac] #44567: Image creation via Rest API, including additional data/meta data

WordPress Trac noreply at wordpress.org
Wed Jul 11 12:08:22 UTC 2018


#44567: Image creation via Rest API, including additional data/meta data
--------------------------+-----------------------------
 Reporter:  apermo        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.9.7
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When creating a new attachment with the Rest API, that also includes data,
 normal data like the title will be handled, but additional data, like meta
 data for example are not handled.

 When adding this code near the end of the method `create_item() ` on the
 file `class-wp-rest-attachments-controller.php` the issue is solved.

 {{{#!php
 $request->set_url_params( [ 'id' => $id ] );

 $response = parent::update_item( $request );

 if ( is_wp_error( $response ) ) {
         return $response;
 }
 }}}

 I added it prior `$fields_update...`

 Note: Since this requires an upload with data and registered meta, I've
 added an example file. And you need to register the meta on the website
 too.

 {{{
 register_meta( 'post', 'my_meta', [
                         'type' => 'string',
                         'description' => '',
                         'single' => true,
                         'show_in_rest' => true,
                 ] );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44567>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list