Add image alt text to the ActivityStreams attachment property in a format that Mastodon can read.
This commit is contained in:
parent
85db6f2d7e
commit
f387177ebf
1 changed files with 9 additions and 17 deletions
|
@ -96,32 +96,24 @@ class Post {
|
||||||
|
|
||||||
// get URLs for each image
|
// get URLs for each image
|
||||||
foreach ( $image_ids as $id ) {
|
foreach ( $image_ids as $id ) {
|
||||||
|
$alt = \get_post_meta( $id, '_wp_attachment_image_alt', true );
|
||||||
$thumbnail = \wp_get_attachment_image_src( $id, 'full' );
|
$thumbnail = \wp_get_attachment_image_src( $id, 'full' );
|
||||||
$mimetype = \get_post_mime_type( $id );
|
$mimetype = \get_post_mime_type( $id );
|
||||||
|
|
||||||
if ( $thumbnail ) {
|
if ( $thumbnail ) {
|
||||||
$images[] = array(
|
$image = array(
|
||||||
'url' => $thumbnail[0],
|
|
||||||
'type' => $mimetype,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$attachments = array();
|
|
||||||
|
|
||||||
// add attachments
|
|
||||||
if ( $images ) {
|
|
||||||
foreach ( $images as $image ) {
|
|
||||||
$attachment = array(
|
|
||||||
'type' => 'Image',
|
'type' => 'Image',
|
||||||
'url' => $image['url'],
|
'url' => $thumbnail[0],
|
||||||
'mediaType' => $image['type'],
|
'mediaType' => $mimetype
|
||||||
);
|
);
|
||||||
$attachments[] = $attachment;
|
if ( $alt ) {
|
||||||
|
$image['name'] = $alt;
|
||||||
|
}
|
||||||
|
$images[] = $image;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $attachments;
|
return $images;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_tags() {
|
public function get_tags() {
|
||||||
|
|
Loading…
Reference in a new issue