Skip to content

Commit

Permalink
Merge pull request #21797 from Yoast/allow-for-og-image-w-h-type-to-b…
Browse files Browse the repository at this point in the history
…e-null

Allow for og image width, height and type to be null
  • Loading branch information
pls78 authored Nov 5, 2024
2 parents 713c115 + 5af15d8 commit a85c7d6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/presenters/open-graph/image-presenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ protected function filter( $image ) {
if ( ! empty( $image_type ) && \is_string( $image_type ) ) {
$image['type'] = \trim( $image_type );
}
else {
$image['type'] = '';
}

$image_width = ( $image['width'] ?? '' );
/**
Expand All @@ -127,6 +130,9 @@ protected function filter( $image ) {
if ( ! empty( $image_width ) && $image_width > 0 ) {
$image['width'] = $image_width;
}
else {
$image['width'] = '';
}

$image_height = ( $image['height'] ?? '' );
/**
Expand All @@ -139,6 +145,9 @@ protected function filter( $image ) {
if ( ! empty( $image_height ) && $image_height > 0 ) {
$image['height'] = $image_height;
}
else {
$image['height'] = '';
}

return $image;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/Unit/Presenters/Open_Graph/Image_Presenter_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,17 @@ public function test_filter_wrong_image_url_returned() {
->with( 'https://example.com/image.jpg', $this->presentation )
->andReturn( false );

$this->assertEquals( [ [ 'url' => 'https://example.com/image.jpg' ] ], $this->instance->get() );
$this->assertEquals(
[
[
'url' => 'https://example.com/image.jpg',
'type' => '',
'width' => '',
'height' => '',
],
],
$this->instance->get()
);
}

/**
Expand Down Expand Up @@ -180,6 +190,7 @@ public function test_get() {
'url' => 'https://example.com/image.jpg',
'width' => 100,
'height' => 100,
'type' => '',
];

$this->presentation->open_graph_images = [ $raw_image ];
Expand Down

0 comments on commit a85c7d6

Please sign in to comment.