WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 29 hours ago

#44567 assigned defect (bug)

Image creation via Rest API, including additional data/meta data

Reported by: apermo Owned by: TimothyBlynJacobs
Milestone: 5.4 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: has-patch has-unit-tests
Focuses: Cc:
PR Number:

Description

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.

$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,
		] );

Attachments (3)

upload_with_attachment.php (1.4 KB) - added by apermo 19 months ago.
Dummy file for uploading an attachment via rest api including title and a meta value
44567.diff (3.0 KB) - added by TimothyBlynJacobs 3 months ago.
44567.2.diff (2.7 KB) - added by TimothyBlynJacobs 3 weeks ago.

Download all attachments as: .zip

Change History (9)

@apermo
19 months ago

Dummy file for uploading an attachment via rest api including title and a meta value

This ticket was mentioned in Slack in #core-restapi by apermo. View the logs.


17 months ago

This ticket was mentioned in Slack in #core-restapi by apermo. View the logs.


16 months ago

#3 @TimothyBlynJacobs
3 months ago

  • Keywords has-patch has-unit-tests added
  • Milestone changed from Awaiting Review to 5.4
  • Owner set to TimothyBlynJacobs
  • Status changed from new to assigned
  • Version changed from 4.9.7 to 4.7

Thanks for the report @apermo!

I've uploaded a patch to add support for setting meta while creating an attachment. Could you let me know if it fixes your issue?

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


5 weeks ago

#5 @TimothyBlynJacobs
3 weeks ago

Uploaded an additional patch removing the change to an unrelated test.

This ticket was mentioned in Slack in #core-restapi by timothybjacobs. View the logs.


29 hours ago

Note: See TracTickets for help on using tickets.