Skip to content

Commit

Permalink
Merge pull request #196 from 10up/fix/fatal-error-when-filter-called-…
Browse files Browse the repository at this point in the history
…with-less-args

Fix fatal error when "admin_post_thumbnail_html" filter is applied with null "$thumbnail_id" param
  • Loading branch information
dkotter authored Apr 25, 2024
2 parents 55772cf + 81bb90e commit 3a3313c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
/**
* If the featured image is an SVG we wrap it in an SVG class so we can apply our CSS fix.
*
* @param string $content Admin post thumbnail HTML markup.
* @param int $post_id Post ID.
* @param int $thumbnail_id Thumbnail ID.
* @param string $content Admin post thumbnail HTML markup.
* @param int $post_id Post ID.
* @param int|null $thumbnail_id Thumbnail attachment ID, or null if there isn't one.
*
* @return string
*/
public function featured_image_fix( $content, $post_id, $thumbnail_id ) {
public function featured_image_fix( $content, $post_id, $thumbnail_id = null ) {
$mime = get_post_mime_type( $thumbnail_id );

if ( 'image/svg+xml' === $mime ) {
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test-safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,16 @@ public function test_featured_image_fix() {

$response = $this->instance->featured_image_fix( 'test', 1, 1 );
$this->assertSame( '<span class="svg">test</span>', $response );

\WP_Mock::userFunction(
'get_post_mime_type',
array(
'args' => null,
'return' => false,
)
);

$response = $this->instance->featured_image_fix( 'test', 1 );
$this->assertSame( 'test', $response );
}
}

0 comments on commit 3a3313c

Please sign in to comment.