Skip to:
Content
Pages
Categories
Search
Top
Bottom

BP avatars missing special classes


  • ewafford
    Participant

    @ewafford

    I have some code for my theme that adds some extra classes to avatars on blog post comments.

    function bt_get_avatar($avatar, $type) {
      if (!is_object($type)) { return $avatar; }
    
      $avatar = str_replace("class='avatar", "class='avatar pull-left media-object", $avatar);
      return $avatar;
    }
    add_filter('get_avatar', 'bt_get_avatar', 10, 2);

    But for some reason anyone that is a “member” of the buddypress plugin doesn’t get these applied to their comments. Ive had some success with hooking bp_core_avatar_class but it seems to now add those classes to all instances of the get_avatar everywhere, and thats not what I want exactly. For example, it adds these to the toolbar/admin bar avatar also. Disabling BP restores the classes back to all comments on the blog. Using the comment form while not logged in posts a comment with the classes added. The result is a mixture of comments, some with the avatar classes, some without.

    Is there a way to make the above code function as expected with BP enable?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hmm. Using get_avatar to change the class for blog comments is an interesting approach, though I guess it has pitfalls like this. BuddyPress customises the entire string, so your str_replace is probably not matching.

    How about hooking at priority 12 instead of 10, and doing some debugging so you can fix up your str_replace for when BuddyPress is active? You might need two str_replace statements to handle BP and no BP, or you might want to switch to a preg_replace or something like that.


    ewafford
    Participant

    @ewafford

    reevaluating my str_replace revealed the error:

    str_replace("class='avatar", "class='avatar pull-left media-object", $avatar);

    Should have been:

    str_replace("class=\"avatar", "class=\"avatar pull-left media-object", $avatar);

    Thanks for being a sounding board. Late night.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘BP avatars missing special classes’ is closed to new replies.
Skip to toolbar