Code Snippets

Adding a new Activity Stream entry when a user changes his avatar

Here’s a quick tip straight from the BP-Trac created by R-A-Y. Put the snippet below in your child theme’s functions.php or in your bp-custom.php:

/* Add a new activity stream item for when people change their Profile Picute */
function xprofile_new_avatar_activity() {
global $bp;

if ( !function_exists( ‘bp_activity_add’ ) )
return false;

$user_id = apply_filters( ‘xprofile_new_avatar_user_id’, $bp->displayed_user->id );

$userlink = bp_core_get_userlink( $user_id );

bp_activity_add( array(
‘user_id’ => $user_id,
‘action’ => apply_filters( ‘xprofile_new_avatar_action’, sprintf( __( ‘%s uploaded a new profile picture’, ‘buddypress’ ), $userlink ), $user_id ),
‘component’ => ‘profile’,
‘type’ => ‘new_avatar’
) );
add_action( ‘xprofile_avatar_uploaded’, ‘xprofile_new_avatar_activity’ );

Now when a user changes his avatar a new entry gets added to the stream notifying everyone of the new profile picture. Awesome!

This functionality will probably be added to BP 1.3 so keep an eye out when you update to 1.3 in the future. It might cause a conflict!

Source: R-A-Y his patch on BP-Trac

Tired of having a slow BuddyPress site?

I'm constantly updating my BuddyPress Hosting Guide to help you get the most out of your hosting. SiteGround and WPEngine have proven to be fast and reliable but see my BuddyPress Hosting guide for a full overview of your options


40% Discount on the first year of BuddyPress hosting on WPEngine!

Currently WP Engine is running a promotion where they give 40% discount for the first year of hosting on any of their plans. Use code SSL40OFF on Personal, Professional, or Business plans on WP

About Bowe Frankema

Building communities on BuddyPress is something I am very passionate about. The decision to focus exclusively on BuddyPress projects over the last few years inspired me to share back some of the things I've learned here on BP-Tricks! You can find me on WordCamps & BuddyCamps across the globe and on Twitter! Follow me on Twitter


7 responses to ‘Adding a new Activity Stream entry when a user changes his avatar

  1. Hi! amazing trick! Will this add the custom filter for selection? or how can I create that, let’s suppose I ‘m recording a custom activity (type => ‘custom_name’ ) can I add a filter somehow for the users to do that or show only that kind of updates in a custom activity loop somewhere? Thanks for all!!!

  2. Oh, I’ve achieved it :D thanks anyway!

    * bpfb_activity_links_filter()
    * Adds 'Enlaces' and 'Wall Photos' to activity stream filters.
    function bpfb_activity_links_filter() {
    echo 'Enlaces';
    echo 'Fotos del muro';
    add_action( 'bp_activity_filter_options', 'bpfb_activity_links_filter' );
    add_action( 'bp_member_activity_filter_options', 'bpfb_activity_links_filter' );
    add_action( 'bp_group_activity_filter_options', 'bpfb_activity_links_filter' );

    PS: It’s still a bit hardcoded but anyone can tweak it if needed

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">