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.

git-svn-id: https://develop.svn.wordpress.org/trunk@56637 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Dolson 2023-09-20 19:29:30 +00:00
parent 107c730164
commit 5b79a4cd49
2 changed files with 3 additions and 0 deletions

View File

@ -1067,6 +1067,7 @@ class wp_xmlrpc_server extends IXR_Server {
'description' => $media_item->post_content,
'metadata' => wp_get_attachment_metadata( $media_item->ID ),
'type' => $media_item->post_mime_type,
'alt' => get_post_meta( $media_item->ID, '_wp_attachment_image_alt', true ),
);
$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size );

View File

@ -25,6 +25,7 @@ class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
$this->attachment_id = $this->_make_attachment( $upload, self::$post_id );
$this->attachment_data = get_post( $this->attachment_id, ARRAY_A );
update_post_meta( $this->attachment_id, '_wp_attachment_image_alt', 'Waffle has alt text' );
set_post_thumbnail( self::$post_id, $this->attachment_id );
}
@ -60,6 +61,7 @@ class Tests_XMLRPC_wp_getMediaItem extends WP_XMLRPC_UnitTestCase {
$this->assertIsString( $result['link'] );
$this->assertIsString( $result['thumbnail'] );
$this->assertIsArray( $result['metadata'] );
$this->assertIsString( $result['alt'] );
// Check expected values.
$this->assertStringMatchesFormat( '%d', $result['attachment_id'] );