I’m pretty sure you can use the bp_blogs_format_activity_action_new_blog_comment
filter to do that.
@henrywright
Thanks for your reply. Can you help me out with a few more details? This is what I’m using to get the title of the new post in the activity feed. It works fine for the new posts but doesn’t seem to work for comments:
function dailies_comments_include_post_type_title( $action, $activity ) {
if ( empty( $activity->id ) ) {
return $action;
}
if ( 'new_dailies_comment' != $activity->type ) {
return $action;
}
preg_match_all( '/<a.*?>([^>]*)<\/a>/', $action, $matches );
if ( empty( $matches[1][1] ) || '[Title]' != $matches[1][1] ) {
return $action;
}
$post_type_title = bp_activity_get_meta( $activity->id, 'post_title' );
if ( empty( $post_type_title ) ) {
switch_to_blog( $activity->item_id );
$post_type_title = get_post_field( 'post_title', $activity->secondary_item_id );
// We have a title save it in activity meta to avoid switching blogs too much
if ( ! empty( $post_type_title ) ) {
bp_activity_update_meta( $activity->id, 'post_title', $post_type_title );
}
restore_current_blog();
}
return str_replace( $matches[1][1], esc_html( $post_type_title ), $action );
}
add_filter( 'bp_activity_custom_post_type_post_action', 'dailies_comments_include_post_type_title', 10, 2 );
Here’s an example of how to use the filter:
add_filter( 'bp_blogs_format_activity_action_new_blog_comment', function( $action, $activity ) {
// Do what you wish with $activity here.
$action = __( 'Your text here.', 'text-domain' );
return $action;
} );
bigkahunaburger
@bigkahunaburger
8 years, 4 months ago
I’m trying to add the comment post title in the activity update:
I got it working for the post itself thanks to this topic:
And by using @imath gist as a guide:
https://gist.github.com/imath/dce8426f686da1727f82
However I can’t seem to figure it out for comments. Anyone have any ideas?
Thanks