Skip to content

Commit

Permalink
Fixed: Missing attachement-type for enclosures (#1021)
Browse files Browse the repository at this point in the history
* * Fixed: Missing attachement-type for enclosures

* simplify code
  • Loading branch information
pfefferle authored Nov 27, 2024
1 parent 276027f commit f1244e7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Fediverse preview showing `preferredUsername` instead of `name`
* Fixed a potential fatal error in Enable Mastodon Apps
* Fixed missing attachement-type for enclosures
* Prevention against self pings

## 4.2.1 - 2024-11-20
Expand Down
4 changes: 2 additions & 2 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1014,8 +1014,8 @@ function ( $enclosure ) {

return array(
'url' => $attributes[0],
'length' => isset( $attributes[1] ) ? trim( $attributes[1] ) : null,
'mediaType' => isset( $attributes[2] ) ? trim( $attributes[2] ) : null,
'length' => $attributes[1] ?? null,
'mediaType' => $attributes[2] ?? 'application/octet-stream',
);
},
$enclosures
Expand Down
6 changes: 4 additions & 2 deletions includes/transformer/class-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,16 @@ public function get_enclosures( $media ) {
foreach ( $enclosures as $enclosure ) {
// Check if URL is an attachment.
$attachment_id = \attachment_url_to_postid( $enclosure['url'] );

if ( $attachment_id ) {
$enclosure['id'] = $attachment_id;
$enclosure['url'] = \wp_get_attachment_url( $attachment_id );
$enclosure['mediaType'] = \get_post_mime_type( $attachment_id );
}

$mime_type = $enclosure['mediaType'];
$mime_type_parts = \explode( '/', $mime_type );
$mime_type = $enclosure['mediaType'];
$mime_type_parts = \explode( '/', $mime_type );
$enclosure['type'] = \ucfirst( $mime_type_parts[0] );

switch ( $mime_type_parts[0] ) {
case 'image':
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ For reasons of data protection, it is not possible to see the followers of other
* Improved: Better handling of `readme.txt` and `README.md`
* Fixed: Fediverse preview showing `preferredUsername` instead of `name`
* Fixed: Potential fatal error in Enable Mastodon Apps
* Fixed: Missing attachement-type for enclosures
* Fixed: Prevention against self pings

= 4.2.1 =
Expand Down

0 comments on commit f1244e7

Please sign in to comment.