Project

General

Profile

Actions

Feature #1423

open

Show an avatar for pingback comment activity items

Added by Boone Gorges almost 13 years ago. Updated about 8 years ago.

Status:
Assigned
Priority name:
Low
Assignee:
Tahir Butt
Category name:
BuddyPress (misc)
Target version:
Start date:
2011-12-09
Due date:
% Done:

0%

Estimated time:
Deployment actions:

Description

Activity items corresponding to blog pingbacks do not currently have avatars. When it's an internal ping (from the CAC network) we could at least attempt to get the canonical blog or user avatar. And when it's not, we could try doing a Gravatar lookup based on URL or email address.

Actions #1

Updated by Boone Gorges about 9 years ago

  • Assignee changed from Boone Gorges to Daniel Jones

This is a fun one for a rainy day

Actions #2

Updated by Boone Gorges about 8 years ago

  • Assignee changed from Daniel Jones to Tahir Butt

Tahir, this might be a good place to dive into BuddyPress's internals.

The avatars in question are shown in places like http://commons.gc.cuny.edu/activity/. Filter by "Show Blog Comment" and you'll see that some items have a dummy avatar. (There is a related bug, which is that they read "commented on the blog post" - missing a subject.)

For avatars, start by filtering 'bp_get_activity_avatar'. Here's a framework:

function cac_anonymous_activity_avatar( $html, $params ) {
    global $activities_template;

    // We're only concerned with avatar requests where the object ID is empty.
    if ( ! empty( $params['item_id'] ) ) {
        return $html;
    }

    // We'll only have enough information to do the lookup if we're in an activity loop. Here's a clunky but effective way to check whether this is the case.
    if ( empty( $activities_template->activity ) ) {
        return $htmls;
    }

    // Then, use the $activity values to fetch the source comment, and get enough information about the commenter to look for an avatar.
    // Then rebuild the $html using the new avatar URL
    // It'll probably look something like this:
    $activity = $activities_template->activity;

    $blog_id = $activity->item_id;
    $comment_id = $activity->secondary_item_id;

    switch_to_blog( $blog_id );
    $comment = get_comment( $comment_id );

    // $comment should have enough info for you to assemble a Gravatar URL. See especially $comment->comment_author_email

    restore_current_blog();

    // then do something to rebuild the $html markup that must be returned from this callback
}
add_filter( 'bp_core_fetch_avatar', 'cac_anonymous_activity_avatar', 10, 2 ); 

This is pretty rough and untested, but it may be enough for you to get a feel for the WP filter system and some of the fundamentals of BP/WP's internals.

Actions

Also available in: Atom PDF