Opened 12 days ago
Last modified 12 days ago
#9331 new defect (bug)
Blogs: bp_get_blog_avatar() ignores custom alt text when a site icon is used
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Blogs | Keywords: | has-patch needs-testing has-unit-tests |
| Cc: |
Description
In
bp_get_blog_avatar()
, when a blog has a site icon, the generated <img> uses $alt_attribute instead of the parsed $r['alt'].
This makes custom alt text passed by callers ineffective in the site-icon code path, while the fallback avatar code path respects custom alt values.
File: src/bp-blogs/bp-blogs-template.php (site-icon markup branch in bp_get_blog_avatar()).
Steps to reproduce:
- Ensure a blog has a site icon.
- Call:
bp_get_blog_avatar( array(
'blog_id' => <blog_id>,
'alt' => 'Custom alt text',
'type' => 'full',
) );
- Inspect the returned
<img>markup.
Actual result:
- The
<img alt="">uses the default generated text (for example, “Site icon for ...”), not the providedaltvalue.
Expected result:
- The
<img alt="">should use the caller-providedaltvalue ($r['alt']) when present.
Proposed fix:
- In the site-icon
<img>markup, replaceesc_attr( $alt_attribute )
withesc_attr( $r['alt'] )
Why this is safe:
$r['alt']already defaults to$alt_attribute, so default behavior remains unchanged.- This only restores expected behavior for explicit custom
altarguments.
Tests:
- Extend the existing blogs template avatar test to assert custom
altis present when the site-icon branch is used.
Change History (1)
This ticket was mentioned in PR #440 on buddypress/buddypress by @ravikhadka.
12 days ago
#1
- Keywords has-unit-tests added
Note: See
TracTickets for help on using
tickets.
Fixes [](https://buddypress.trac.wordpress.org/ticket/9331)
When a blog has a site icon,
bp_get_blog_avatar()generated the<img>alt attribute from$alt_attributeinstead of parsed args ($r['alt']), so custom alt text passed by callers was ignored in the site-icon path.This change switches the site-icon markup to use
$r['alt']. Default behavior is unchanged because$r['alt']already defaults to$alt_attribute.Tests:
BP_Tests_Blogs_Template::test_bp_get_blog_avatar_has_site_icon()to assertalt="test"is present.