Skip to content

Commit

Permalink
image bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jerome-barbato committed Feb 17, 2025
1 parent 24ba9d8 commit 3e2f538
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/Entity/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,23 @@ protected function get($id)

$attachment_metadata = apply_filters( 'wp_get_attachment_metadata', maybe_unserialize($post_meta['_wp_attachment_metadata'][0]??''), $id );

if( !is_array($attachment_metadata) )
$attachment_metadata = [];
if( !is_array($attachment_metadata) ){

$attachment_metadata['file'] = $post_meta['_wp_attached_file'][0]??'';
$attachment_metadata = [
'width' => 0,
'height' => 0,
'image_meta' => []
];
}

$file = $post_meta['_wp_attached_file'][0]??'';

if( !isset($attachment_metadata['width'], $attachment_metadata['height']) ){

if( $post->post_mime_type != 'image/svg' && $post->post_mime_type != 'image/svg+xml' )
return;

$filename = self::uploadDir('basedir').'/'.$attachment_metadata['file'];
$filename = self::uploadDir('basedir').'/'.$file;

if( !$xmlget = @simplexml_load_file($filename) )
return;
Expand All @@ -256,16 +262,15 @@ protected function get($id)
$this->focus_point = false;
}


$filename = self::uploadDir('basedir').'/'.$attachment_metadata['file'];
$filename = self::uploadDir('basedir').'/'.$file;

if( !is_readable( $filename) )
return;

$this->ID = $post->ID;
$this->caption = $post->post_excerpt;
$this->description = $post->post_content;
$this->file = self::uploadDir('relative').'/'.$attachment_metadata['file'];
$this->file = self::uploadDir('relative').'/'.$file;
$this->src = $filename;
$this->post = $post;

Expand Down

0 comments on commit 3e2f538

Please sign in to comment.