[Resolved] Adding custom post types in the activity stream – need php help
-
I’ve been working to get custom post types working in the BuddyPress activity stream. I found this post by Boone on the Dev blog and it is a pretty 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 across multisite (from the Wiki plugin and MarketPress from WPMU DEV), though what the plugins isn’t important to this request, its more about getting custom post types in activity stream, with a customized $activity_action line (see below for specifics about what I want to edit/filter)
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, including some older code that predates the 1.5 fix (http://pastebin.com/qrfjCat8 based off of http://pastebin.com/kNqTrRzc) 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?
- The topic ‘[Resolved] Adding custom post types in the activity stream – need php help’ is closed to new replies.