Custom post types, comments, and the activity stream in BP 1.5
There was a quirk in the way that BuddyPress 1.2.x’s Blogs component recorded posts and comments in the activity stream. With you published a new post, it only got published in the activity stream if $post->post_type == 'post'. In other words, Pages and all custom post types were ignored. On the other hand, no such post_type check took place in the case of comments, with the result that comments on pages and other post types did show up in the stream.
This odd inconsistency was fixed in the BuddyPress trunk with changeset 4959; BuddyPress now checks to make sure that the item being commenting on is a WordPress ‘post’ before adding the comment to the activity stream. However, anointed chimed in to let us know that some BuddyPress admins were taking advantage of the quirk. The result of this discussion is r4971, in which the post type checks are enhanced by turning them into checks against a filterable whitelist.
Plugin authors should be aware of this changed default behavior. If your plugin creates custom post types, and if you want comments on those custom post types to be recorded in the BP activity stream by bp_blogs_record_comment() (if you are using your own function for this purpose, you don’t need to worry about the change), you will have to update your plugin to do something like this:
function bbg_record_my_custom_post_type_comments( $post_types ) {
$post_types[] = 'dolphin'; // Add your custom post type name to the array. If you have a post type called 'dolphin' then you have a weird plugin
return $post_types;
}
add_filter( 'bp_blogs_record_comment_post_types', 'bbg_record_my_custom_post_type_comments' );
Dianakc 4:24 am on August 13, 2011 Permalink |
Newbie question: BP or WordPress plugins should add this filter?
Boone B. Gorges 2:55 pm on August 13, 2011 Permalink |
Any plugin that wants to record comments on custom post types in the BP activity stream using bp_blogs_record_comment(). If any of the following are true about your plugin, then this post does *not* apply to you:
(In short, it really only applies to a small number of existing plugins.)
stevenkword 4:43 pm on December 30, 2011 Permalink
@Boone — Great solution. This helped me out today. Thanks!
Simon 5:47 pm on August 17, 2011 Permalink |
Question for you Boone, so let’s say you have a WP / BP site where your primary “members” can create posts. Does the above functionality (function bbg_record_my_custom_post_type_comments) imply that both post creation and commenting on posts can be integrated into the activity stream?
caus that would be really cool.
Simon 5:49 pm on August 17, 2011 Permalink |
Further to that last question….
Are there any caveats within the new 1.5 framework to tie custom post types to groups?
i.e. create a new post in a group?
landwire 7:01 am on September 11, 2011 Permalink |
Keep me informed on this.
Johan 2:37 pm on September 26, 2011 Permalink |
Hm, I can’t get this working. I’ve tried adding the bit of code above (after replacing “dolphin” with my custom post type) to the plugin files, functions.php and bp-custom.php but no luck.
Comments made on my custom post type pages does not appear in the activity stream. Any ideas?
Thanks
Johan 10:31 am on October 11, 2011 Permalink |
Bump. Anyone have an idea of why my custom post type comments won’t show up in the activity stream? Any suggestions on how to troubleshoot?
Thanks!
Anthony 5:05 pm on January 10, 2012 Permalink |
Same here. Would love to get this working
Mika "Ipstenu" Epstein 1:12 pm on October 11, 2011 Permalink |
Johan – This is the wrong place to post that. You should post in the support forum.