BuddyPress provides a filter to let you do this.
If you look through the code for recording a post (hooked on save_post) in the bp-blogs component, you should be able to figure out how to use it.
Still no luck using the code for bp-blogs in my functions.php:
http://pastebin.com/evuFQE5H
Edit: nvm, got it working, figured it out. Need to have BuddyPress aware of new content.
Hello , can you please publish here your solution ? I would be glad to see my new custom post types in activity too, to create new custom post type “portfolio” I use gravity forms
Your solution: copying the whole BuddyPress function and changing one line is not the best way to do this.
As I suggested earlier — that BuddyPress function has a filter for the post types it works with: bp_blogs_record_post_post_types
All you need to do is register a filter that adds your custom post types to the array of post types.
Here’s a better solution then: http://pastebin.com/VJ6pR9az
@azizmb
This approach might be safer for most people.
It adds to the recorded post_types instead of replacing them.
`
add_filter ( ‘bp_blogs_record_post_post_types’, ‘activity_publish_custom_post_types’,1,1 );
function activity_publish_custom_post_types( $post_types ) {
$post_types[] = ‘videos’;
$post_types[] = ‘pictures’;
return $post_types;
}
`
And if you go thru the trouble of creating a CPT, why not filter the activity action so it isn’t the generic ‘…wrote a new post’. For example:
`
add_filter(‘bp_blogs_activity_new_post_action’, ‘record_cpt_activity_action’, 1, 3);
function record_cpt_activity_action( $activity_action, $post, $post_permalink ) {
global $bp;
if( $post->post_type == ‘videos’ ) {
if ( is_multisite() )
$activity_action = sprintf( __( ‘%1$s created a new Videos post, %2$s, on the site %3$s’, ‘buddypress’ ), bp_core_get_userlink( (int) $post->post_author ), ‘‘ . $post->post_title . ‘‘, ‘‘ . get_blog_option( $blog_id, ‘blogname’ ) . ‘‘ );
else
$activity_action = sprintf( __( ‘%1$s created a new Videos post, %2$s’, ‘buddypress’ ), bp_core_get_userlink( (int) $post->post_author ), ‘‘ . $post->post_title . ‘‘ );
}
return $activity_action;
}
`
Thanks. You’re right, the first approach would be safer for most people. I kept my approach because I didn’t want anything else besides videos and pictures showing in the stream. As for the second snippet, already got one working but didn’t get a chance to post it, so thanks a lot for sharing!
I’m curious, how can we add a sort option like the “mentions” tab for this custom activity?
A way to view view strictly the activity for this custom post type.
I hate to have to ask, but where does the above code need to be inserted? Will it work in 1.7?
Put it in bp-custom.php – after you remove all the ‘br’ tags.
http://codex.buddypress.org/developer/customizing/bp-custom-php/
Should be fine in 1.7