From f387177ebf2a768c2569482464034ecc6f2f5d93 Mon Sep 17 00:00:00 2001 From: Ben Lubar Date: Sat, 18 Jan 2020 12:36:46 -0600 Subject: [PATCH] Add image alt text to the ActivityStreams attachment property in a format that Mastodon can read. --- includes/model/class-post.php | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/includes/model/class-post.php b/includes/model/class-post.php index 0b2b809..521c7f7 100644 --- a/includes/model/class-post.php +++ b/includes/model/class-post.php @@ -96,32 +96,24 @@ class Post { // get URLs for each image foreach ( $image_ids as $id ) { + $alt = \get_post_meta( $id, '_wp_attachment_image_alt', true ); $thumbnail = \wp_get_attachment_image_src( $id, 'full' ); $mimetype = \get_post_mime_type( $id ); if ( $thumbnail ) { - $images[] = array( - 'url' => $thumbnail[0], - 'type' => $mimetype, - ); - } - } - - $attachments = array(); - - // add attachments - if ( $images ) { - foreach ( $images as $image ) { - $attachment = array( + $image = array( 'type' => 'Image', - 'url' => $image['url'], - 'mediaType' => $image['type'], + 'url' => $thumbnail[0], + 'mediaType' => $mimetype ); - $attachments[] = $attachment; + if ( $alt ) { + $image['name'] = $alt; + } + $images[] = $image; } } - return $attachments; + return $images; } public function get_tags() {