Make WordPress Core

Opened 18 months ago

Closed 15 months ago

Last modified 15 months ago

#58582 closed defect (bug) (fixed)

XML-RPC API: Add alt field support

Reported by: thomashorta's profile thomashorta Owned by: joedolson's profile joedolson
Milestone: 6.4 Priority: normal
Severity: normal Version:
Component: XML-RPC Keywords: has-patch dev-reviewed has-unit-tests commit
Focuses: accessibility Cc:

Description

Currently, the wp.getMediaItem (codex) method of the XML-RPC API does not retrieve the alt field associated with the media item.

Updating MediaItems through the XML-RPC API is also done directly by the Posts API, more specifically through wp.editPost (codex), which also doesn't support an alt field. This makes sense, as this API is more generic, but at the same time, there are no specific updateMedia methods in the Media API.

I did some investigation and the XML-RPC Media API does not have the alt field properly connected to the post meta field (_wp_attachment_image_alt) when preparing the media, which holds the alt field information for attachments/media and is used here for instance.

Would it be possible to add support to the alt field both when fetching and when updating Media items through the XML-RPC API?

Suggestion for fetching
I believe adding something like this to _prepare_media_item would work:

'alt' => get_post_meta( $media_item->ID, '_wp_attachment_image_alt', true ),

Suggestion for updating
I'm not sure about this one, but I think a new method in the Media API would be needed (e.g.: wp.updateMediaItem) to properly manipulate a specific input struct and call the Post update functions internally.

Change History (25)

#1 @antonvlasenko
18 months ago

  • Focuses rest-api added

#2 @antonvlasenko
18 months ago

  • Focuses rest-api removed

#3 @thomashorta
18 months ago

@markoheijnen, I see you are the maintainer for the XML-RPC component. Do you think this request is feasible?

This ticket was mentioned in Slack in #mobile by thomashorta. View the logs.


17 months ago

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


17 months ago

#6 @joedolson
17 months ago

  • Keywords needs-patch added
  • Owner set to joedolson
  • Status changed from new to accepted
  • Type changed from feature request to defect (bug)

We can't support good accessibility if some of our remote methods don't make it possible, so I'd actually consider this a significant bug, rather than a feature request. It's going to impact any XML RPC clients. As much as that's not the primary mechanism for editing content remotely anymore, this prevents best practices for any client still using XML RPC.

I'm not quite ready to milestone this for 6.4, because I'm not personally very familiar with the XML RPC apis, but I'm going to take ownership of it to do some research.

This is something where I wish we could tag multiple components; this is also a Media issue.

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


17 months ago

#8 @joedolson
17 months ago

  • Milestone changed from Awaiting Review to 6.4

Discussed in accessibility bug scrub, and we think that this is important to investigate and try to get fixed.

This ticket was mentioned in PR #5084 on WordPress/wordpress-develop by steveerdelyi.


16 months ago
#9

  • Keywords has-patch added; needs-patch removed

Updated _prepare_media_item to include user-provided attachment alt text

Add alt text to _premare_media_item in class-wp-xmlrpc-server.php

Trac ticket: https://core.trac.wordpress.org/ticket/58582
props: thomashorta, jivygraphics

@mukesh27 commented on PR #5084:


16 months ago
#10

Question: We already have the xmlrpc_prepare_media_item filter at the end of the function, so if anyone wants any additional data, they can extend it. Therefore, why do we need to add it? I'm curious to know the answer.

#11 @mukesh27
16 months ago

  • Keywords needs-testing added
  • Type changed from defect (bug) to enhancement
  • Version 6.3 deleted

#12 @whyisjake
16 months ago

  • Keywords dev-reviewed added

The PR looks great, thanks for the contribution.

@stephenerdelyi commented on PR #5084:


16 months ago
#13

I think it's important for accessibility purposes that this is included by default. I would expect a media object to always contain an alt without additional modifications required 🙂

steveerdelyi commented on PR #5084:


16 months ago
#14

Hey @mukeshpanchal27 what do you think, should we merge this in or would you still prefer to require manual registration for alts delivered via XMLRPC?

@mukesh27 commented on PR #5084:


16 months ago
#15

Thank you, @steveerdelyi. I would appreciate incorporating these changes into the core itself, eliminating the need for using a filter. Thank you.

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


15 months ago

#17 @joedolson
15 months ago

  • Keywords needs-testing-info added

#18 @joedolson
15 months ago

  • Type changed from enhancement to defect (bug)

@stephenerdelyi commented on PR #5084:


15 months ago
#19

Hi @joedolson , just looking to see when you might have a moment to review this? Thanks!

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


15 months ago

#21 @joedolson
15 months ago

  • Keywords has-unit-tests commit added; needs-testing needs-testing-info removed

#22 @joedolson
15 months ago

The original issue calls for a new updateMedia method, but that would be only marginally different from the existing editPost method, since passing custom fields via that method is already supported.

In the interest of getting this fix done in 6.4, I'm going to commit the existing PR - adding alt text to the output, which fixes a bug.

Adding a new method, however, would be an enhancement; I'll open a new ticket to track that after I finish this.

#23 @joedolson
15 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 56637:

XML-RPC: Add alt attribute value to media item API.

Add alt text to the wp.getMediaItem method in the XML-RPC API. Allows users to fetch alt text as a first-class member of a media object.

Props thomashorta, joedolson, jivygraphics, stephenerdelyi, mukesh27, whyisjake.
Fixes #58582.

#25 @joedolson
15 months ago

New ticket opened for adding an update media endpoint: #59414.

Note: See TracTickets for help on using tickets.