Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b6392f5
Embeds: Fix get_site_icon_url() dropping fallback when attachment URL…
Sukhendu2002 Apr 20, 2026
38f4066
Embeds: Move 2x site icon URL fetch inside if condition
Sukhendu2002 Apr 20, 2026
8548ea9
Embeds: Skip srcset when 1x and 2x site icon URLs are identical
Sukhendu2002 Apr 21, 2026
ee74671
Merge branch 'trunk' into fix/65098-get-site-icon-url-fallback
Sukhendu2002 Apr 21, 2026
df80e51
Merge branch 'trunk' into fix/65098-get-site-icon-url-fallback
Sukhendu2002 Apr 22, 2026
0c97d27
Tests: Add coverage for get_site_icon_url() and the_embed_site_title(…
Sukhendu2002 Apr 22, 2026
f586587
Merge branch 'trunk' into fix/65098-get-site-icon-url-fallback
Sukhendu2002 Apr 23, 2026
0701561
Tests: Use get_echo() helper and remove manual filter cleanup in site…
Sukhendu2002 Apr 23, 2026
fb4b1ef
Merge branch 'trunk' into fix/65098-get-site-icon-url-fallback
Sukhendu2002 Apr 24, 2026
a459518
Embeds: Extract fallback icon URL to variable for reuse
Sukhendu2002 Apr 24, 2026
cef1f4f
Tests: Use WP_HTML_Tag_Processor for img attribute assertions
Sukhendu2002 Apr 24, 2026
8775c72
Improve static analysis for PHPStan
westonruter Apr 24, 2026
d4d3ed0
Add missing typing for get_echo()
westonruter Apr 24, 2026
af352fe
Merge branch 'trunk' into fix/65098-get-site-icon-url-fallback
Sukhendu2002 Apr 27, 2026
4cf89eb
Merge branch 'trunk' into fix/65098-get-site-icon-url-fallback
westonruter Jun 15, 2026
e17e3fa
Assert IMG has class
westonruter Jun 15, 2026
400de20
Add missing void return type hint for the_embed_site_title()
westonruter Jun 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/wp-includes/embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -1232,12 +1232,25 @@ function print_embed_sharing_dialog() {
*
* @since 4.5.0
*/
function the_embed_site_title() {
function the_embed_site_title(): void {
$fallback_icon_url = includes_url( 'images/w-logo-blue.png' );
$site_icon_url = get_site_icon_url( 32, $fallback_icon_url );

$icon_img = '';
if ( $site_icon_url ) {
$site_icon_url_2x = get_site_icon_url( 64, $fallback_icon_url );
$srcset = ( $site_icon_url_2x && $site_icon_url !== $site_icon_url_2x ) ? sprintf( ' srcset="%s 2x"', esc_url( $site_icon_url_2x ) ) : '';
$icon_img = sprintf(
'<img src="%s"%s width="32" height="32" alt="" class="wp-embed-site-icon" />',
esc_url( $site_icon_url ),
$srcset
);
}

$site_title = sprintf(
'<a href="%s" target="_top"><img src="%s" srcset="%s 2x" width="32" height="32" alt="" class="wp-embed-site-icon" /><span>%s</span></a>',
'<a href="%s" target="_top">%s<span>%s</span></a>',
esc_url( home_url() ),
esc_url( get_site_icon_url( 32, includes_url( 'images/w-logo-blue.png' ) ) ),
esc_url( get_site_icon_url( 64, includes_url( 'images/w-logo-blue.png' ) ) ),
$icon_img,
esc_html( get_bloginfo( 'name' ) )
);

Expand Down
5 changes: 4 additions & 1 deletion src/wp-includes/general-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,10 @@ function get_site_icon_url( $size = 512, $url = '', $blog_id = 0 ) {
} else {
$size_data = array( $size, $size );
}
$url = wp_get_attachment_image_url( $site_icon_id, $size_data );
$attachment_url = wp_get_attachment_image_url( $site_icon_id, $size_data );
if ( $attachment_url ) {
$url = $attachment_url;
}
}

if ( $switched_blog ) {
Expand Down
116 changes: 116 additions & 0 deletions tests/phpunit/tests/general/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ public function test_get_site_icon_url() {
$this->assertEmpty( get_site_icon_url(), 'Site icon URL should not be set after removal.' );
}

/**
* @ticket 65098
* @group site_icon
* @covers ::get_site_icon_url
* @requires function imagejpeg
*/
public function test_get_site_icon_url_returns_fallback_when_attachment_url_fails(): void {
$this->set_site_icon();

$fallback = 'https://example.com/fallback-icon.png';
add_filter( 'wp_get_attachment_image_src', '__return_false' );
$url = get_site_icon_url( 32, $fallback );

$this->assertSame( $fallback, $url, 'Fallback URL should be returned when attachment URL lookup fails.' );
}

/**
* @group site_icon
* @covers ::site_icon_url
Expand Down Expand Up @@ -807,4 +823,104 @@ public function test_get_the_archive_title_is_correct_for_author_queries() {
$this->assertSame( $user_with_posts->display_name, $title_when_posts );
$this->assertSame( $user_with_no_posts->display_name, $title_when_no_posts );
}

/**
* @ticket 65098
* @group site_icon
* @covers ::the_embed_site_title
* @requires function imagejpeg
*/
public function test_the_embed_site_title_contains_site_icon_when_set(): void {
$this->set_site_icon();

$url_32 = get_site_icon_url( 32 );
$url_64 = get_site_icon_url( 64 );

$output = get_echo( 'the_embed_site_title' );
$processor = new WP_HTML_Tag_Processor( $output );

$this->assertTrue( $processor->next_tag( 'IMG' ), 'Expected IMG tag.' );
$this->assertTrue( $processor->has_class( 'wp-embed-site-icon' ), 'Expected IMG to have wp-embed-site-icon class.' );
$this->assertSame( $url_32, $processor->get_attribute( 'src' ), 'Output should contain 32px site icon URL in src.' );
$srcset = $processor->get_attribute( 'srcset' );
$this->assertIsString( $srcset, 'Expected srcset to be present.' );
$this->assertStringContainsString( $url_64, $srcset, 'Output should contain 64px site icon URL in srcset.' );
}

/**
* @ticket 65098
* @group site_icon
* @covers ::the_embed_site_title
* @requires function imagejpeg
*/
public function test_the_embed_site_title_uses_fallback_when_attachment_url_fails(): void {
$this->set_site_icon();

// Simulate wp_get_attachment_image_url() failing.
add_filter( 'wp_get_attachment_image_src', '__return_false' );
$output = get_echo( 'the_embed_site_title' );

$fallback = includes_url( 'images/w-logo-blue.png' );
$processor = new WP_HTML_Tag_Processor( $output );

$this->assertTrue( $processor->next_tag( 'IMG' ), 'Expected IMG tag with fallback.' );
$this->assertTrue( $processor->has_class( 'wp-embed-site-icon' ), 'Expected IMG to have wp-embed-site-icon class.' );
$this->assertSame( $fallback, $processor->get_attribute( 'src' ), 'Output should contain fallback URL in src when attachment URL fails.' );
}

/**
* @ticket 65098
* @group site_icon
* @covers ::the_embed_site_title
*/
public function test_the_embed_site_title_omits_img_when_url_is_empty(): void {
// Force get_site_icon_url() to return empty string via filter.
add_filter( 'get_site_icon_url', '__return_empty_string' );
$output = get_echo( 'the_embed_site_title' );

$processor = new WP_HTML_Tag_Processor( $output );

$this->assertFalse( $processor->next_tag( 'IMG' ), 'IMG tag should be omitted when URL is empty.' );
$this->assertStringContainsString( get_bloginfo( 'name' ), $output, 'Site name should still be present.' );
}

/**
* @ticket 65098
* @group site_icon
* @covers ::the_embed_site_title
*/
public function test_the_embed_site_title_omits_srcset_when_1x_and_2x_urls_are_identical(): void {
// Force both sizes to return the same URL.
$svg_url = 'https://example.com/icon.svg';
$filter = static function () use ( $svg_url ) {
return $svg_url;
};

add_filter( 'get_site_icon_url', $filter );
$output = get_echo( 'the_embed_site_title' );

$processor = new WP_HTML_Tag_Processor( $output );

$this->assertTrue( $processor->next_tag( 'IMG' ), 'Expected IMG tag.' );
$this->assertTrue( $processor->has_class( 'wp-embed-site-icon' ), 'Expected IMG to have wp-embed-site-icon class.' );
$this->assertSame( $svg_url, $processor->get_attribute( 'src' ), '1x URL should be present in src.' );
Comment thread
westonruter marked this conversation as resolved.
$this->assertNull( $processor->get_attribute( 'srcset' ), 'srcset should be omitted when 1x and 2x URLs are identical.' );
}

/**
* @ticket 65098
* @group site_icon
* @covers ::the_embed_site_title
*/
public function test_the_embed_site_title_uses_fallback_without_srcset_when_no_site_icon_set(): void {
$output = get_echo( 'the_embed_site_title' );
$fallback = includes_url( 'images/w-logo-blue.png' );

$processor = new WP_HTML_Tag_Processor( $output );

$this->assertTrue( $processor->next_tag( 'IMG' ), 'Expected IMG tag with fallback.' );
$this->assertTrue( $processor->has_class( 'wp-embed-site-icon' ), 'Expected IMG to have wp-embed-site-icon class.' );
$this->assertSame( $fallback, $processor->get_attribute( 'src' ), 'Output should contain fallback icon URL in src.' );
$this->assertNull( $processor->get_attribute( 'srcset' ), 'srcset should be omitted when 1x and 2x fallback URLs are identical.' );
}
}
Loading