Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Wrapping Secondary avatar with link

  • I’m looking to wrap all of my secondary avatar’s with a link to the destination profile, whether that is a profile, group, event or anything else etc.

    I’ve tired using a hook into the bp_dtheme_activity_secondary_avatar function, however I’m not sure how I get the appropriate url for the avatar. I’m mainly trying to do this with the activity feeds.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    I’m looking over the code, and there’s not a very easy way to make it happen. We have hooks in bp_get_activity_secondary_avatar(), but we’re not passing along enough information to make it possible for filters to make the avatars linkable.

    Could I ask you to open an enhancement ticket at https://buddypress.trac.wordpress.org/ explaining what you’re trying to do? I can make sure that the filters are improved to make what you’re trying to do possible.

    In the meantime, it’s possible to do what you want, though not elegant. Here’s a hint:

    `
    function bbg_turn_secondary_avatars_to_links( $avatar ) {
    global $activities_template;

    // Here you’ll copy the logic in bp_get_activity_secondary_avatar() to switch between types
    switch ( $activities_template->activity->item_id ) {
    // Here’s an example of what to do with groups
    case ‘groups’ :
    $group_id = $activities_template->activity->item_id;
    $group = groups_get_group( $group_id );
    $url = bp_get_group_permalink( $group );
    break;

    // You’ll have to do similar sorts of tricks for different content types
    }

    // Then, wrap the avatar in a URL
    if ( !empty( $url ) ) {
    $avatar = ‘‘ . $avatar . ‘‘;
    }

    return $avatar;
    }
    add_filter( ‘bp_get_activity_secondary_avatar’, ‘bbg_turn_secondary_avatars_to_links’ );
    `

    This may not work as is (it’s off the top of my head) but it should give you a push in the right direction. Good luck!

    Thanks Boone, I’ll have a look at your idea.

    FYI, I’ve submitted a ticket. https://buddypress.trac.wordpress.org/ticket/4436

    For anyone who may find this,and is looking to do what I did here is the code:

    `function bbg_turn_secondary_avatars_to_links( $avatar ) {
    global $activities_template;

    switch ( $activities_template->activity->component ) {
    case ‘groups’ :
    $item_id = $activities_template->activity->item_id;
    $group = groups_get_group( array( ‘group_id’ => $item_id ) );
    $url = apply_filters( ‘bp_get_group_permalink’, trailingslashit( bp_get_root_domain() . ‘/’ . bp_get_groups_root_slug() . ‘/’ . $group->slug . ‘/’ ) );
    break;
    case ‘blogs’ :
    break;
    case ‘friends’ :
    $item_id = $activities_template->activity->secondary_item_id;
    $url = bp_core_get_user_domain($item_id);
    break;
    default :
    break;

    }
    if ( !empty( $url ) ) {
    $avatar = ‘‘ . $avatar . ‘‘;
    }
    return $avatar;
    }
    add_filter( ‘bp_get_activity_secondary_avatar’, ‘bbg_turn_secondary_avatars_to_links’ );`

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] Wrapping Secondary avatar with link’ is closed to new replies.
Skip to toolbar