Skip to:
Content

BuddyPress.org

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: ravikhadka's profile ravikhadka 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:

  1. Ensure a blog has a site icon.
  2. Call:
   bp_get_blog_avatar( array(
       'blog_id' => <blog_id>,
       'alt'     => 'Custom alt text',
       'type'    => 'full',
   ) );
  1. Inspect the returned <img> markup.

Actual result:

  • The <img alt=""> uses the default generated text (for example, “Site icon for ...”), not the provided alt value.

Expected result:

  • The <img alt=""> should use the caller-provided alt value ($r['alt']) when present.

Proposed fix:

  • In the site-icon <img> markup, replace
    esc_attr( $alt_attribute )
    
    with
    esc_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 alt arguments.

Tests:

  • Extend the existing blogs template avatar test to assert custom alt is 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

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_attribute instead 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:

  • Extend BP_Tests_Blogs_Template::test_bp_get_blog_avatar_has_site_icon() to assert alt="test" is present.
Note: See TracTickets for help on using tickets.