Need some php help - Custom Post Types and Buddypress

Saunt Valerian Elite
Supreme Deity
Mind-Blowingly Helpful
1060
#74

I've been working to get custom post types working in the BuddyPress activity stream. I was working with another member in this thread: http://premium.wpmudev.org/forums/topic/how-to-add-custom-posts-types-in-buddypress-activity

However, it turns out that the background for the code in that thread is over a year old and BP 1.5 uses a far more elegant solution to adding custom post types to the activity stream http://bpdevel.wordpress.com/2011/08/12/custom-post-types-comments-and-the-activity-stream-in-bp-1-5/

As such, I'm working with wikis and products (from the Wiki plugin and MarketPress)

To get the Wikis to record to activity I created this and added it to bp-custom.php:

// add wiki post types to the activity stream
function activity_publish_wiki_posts($wikiposts) {
   $wikiposts[] = 'incsub_wiki';
   return $wikiposts;
}
add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_wiki_posts' );

For Products, I have this:

// add product post types to the activity stream
function activity_publish_product_posts($productposts) {
   $productposts[] = 'product';
   return $productposts;
}
add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_product_posts' );

Instead of using two separate snippets you can also streamline the code by putting both post types into the array, like this:

// add product post types to the activity stream
function activity_publish_custom_post_types($cpts) {
   $cpts[] = 'product';
   $cpts[] = 'incsub_wiki';
   return $cpts;
}
add_filter ( 'bp_blogs_record_post_post_types', 'activity_publish_custom_post_types' );

These are very efficient ways to add custom post types to the activity stream. I tested this several times and it works great. It also ensures that when a post is updated, the activity record gets updated. I see this as essential behavior, especially with the Wikis.

Help Needed
Now, I separated them into two different snippets because I need to get some customization built into them. I want the activity record to read "John updated a wiki article, Cool Stuff, on the site, My Wiki" for the Wikis, and "John added a new product, My Cool Car, to the site, John's Cars"

I've gone through various bits of code and tried adding a filter to the snippets I post above that would filter $activity_action from BuddyPress core in bp-blogs-function.php. I just can't seem to get that in there and working properly.

Can someone help me modify those snippets to get the correct line of text in the activity update?

Bonus snippet:
Here's a bonus for anyone bothering to read through my wall o' text:
In BP 1.5 comments to custom post types no longer make it into the activity stream. Fix that with some code like this, just change the names of your post types in the array!

// add custom post type comments to the activity stream
function activity_publish_post_type_comments( $types ) {
   $types[] = 'incsub_wiki';
   $types[] = 'product';
   return $types;
}
add_filter( 'bp_blogs_record_comment_post_types', 'activity_publish_post_type_comments' );

Note: according to the BP devs, this method is the beginning of an API they intend to build into future versions. They intend to not degrade it or remove it, but build on it so if you use it in a plugin or in bp-custom.php - it will still work fine in future versions.

(0)