Add wordpress custom post-type & comments to Buddypress activity record

By default, Buddypress will not record custom post-type posts and comments. To do that, you can add following functions to your theme function.php file.

// Add custom post type to activity record
add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_custom_post_types',1,1 );
// Add custom post type comments to activity record
add_filter ( 'bp_blogs_record_comment_post_types', 'activity_publish_custom_post_types',1,1 );
 
function activity_publish_custom_post_types( $post_types ) {
// add any custom post-type here
$post_types[] = 'videos';
$post_types[] = 'photos';
$post_types[] = 'cheats';
return $post_types;
}
 
//Modify activity records for custom post-type
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 != 'post' ) {
	if ( is_multisite() )
	$activity_action  = sprintf( __( '%1$s wrote a new %2$s post, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ), $post->post_type, '<a href="' . $post_permalink . '">' . $post->post_title . '</a>', get_blog_option( $blog_id, 'blogname' ));
	else
	$activity_action  = sprintf( __( '%1$s wrote a new %2$s post, %3$s', 'buddypress' ), bp_core_get_userlink( (int) $post->post_author ),$post->post_type, '<a href="' . $post_permalink . '">' . $post->post_title . '</a>' );
} 
return $activity_action;
}
 
//Modify activity comment records for custom post-type
add_filter('bp_blogs_activity_new_comment_action', 'record_cpt_comment_activity_action', 1, 3);
function record_cpt_comment_activity_action( $activity_action,  &$recorded_comment, $comment_link ) {
global $bp;
if( $recorded_comment->post->post_type != 'post' ) {
		if ( is_multisite() )
			$activity_action = sprintf( __( '%1$s commented on the %2$s post, %3$s, on the site %4$s', 'buddypress' ), bp_core_get_userlink( $user_id ), $recorded_comment->post->post_type, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>', '<a href="' . get_blog_option( $blog_id, 'home' ) . '">' . get_blog_option( $blog_id, 'blogname' ) . '</a>' );
		else
			$activity_action = sprintf( __( '%1$s commented on the %2$s post, %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ),$recorded_comment->post->post_type, '<a href="' . $post_permalink . '">' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '</a>' );
} 
return $activity_action;
}

Hope this is useful for your project!

3 thoughts on “Add wordpress custom post-type & comments to Buddypress activity record

  1. How is this to be implimented? What I mean is on the Activity Feed (post-form.php) what needs modified to actually POST in a Custom Post Type? I simply am not understanding. I posted this code, you wrote, into my bp-custom.php and modified the three Custom Post Types to meet my needs but nothing changes. It still logs in the database as an activity_update.

Leave a Reply

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