[wp-trac] [WordPress Trac] #58582: XML-RPC API: Add alt field support

WordPress Trac noreply at wordpress.org
Tue Jun 20 21:26:16 UTC 2023


#58582: XML-RPC API: Add alt field support
-----------------------------+-----------------------------
 Reporter:  thomashorta      |      Owner:  (none)
     Type:  feature request  |     Status:  new
 Priority:  normal           |  Milestone:  Awaiting Review
Component:  XML-RPC          |    Version:  trunk
 Severity:  normal           |   Keywords:
  Focuses:  accessibility    |
-----------------------------+-----------------------------
 Currently, the `wp.getMediaItem` ([https://codex.wordpress.org/XML-
 RPC_WordPress_API/Media#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`
 ([https://codex.wordpress.org/XML-RPC_WordPress_API/Posts#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 [https://github.com/WordPress/wordpress-
 develop/blob/12f854cacdea75b244fbd4b5820a508a16c10578/src/wp-includes
 /class-wp-xmlrpc-server.php#L1058-L1068 preparing the media], which holds
 the `alt` field information for attachments/media and is used
 [https://github.com/WordPress/wordpress-
 develop/blob/9bc6b0a0606f27afb47f6e2aee2961c80e5cde01/src/wp-
 includes/media.php#L4193 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:
 {{{#!php
 '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.

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


More information about the wp-trac mailing list