Create a gist now

Instantly share code, notes, and snippets.

@jonasnick /bca.php
Last active Jan 7, 2018

Embed
What would you like to do?
Blog Comments in Activity (bca) Shows blog post comments in buddypress' activity stream. Does currently not keep track of editing or removing comments.
<?php
/*
* Blog Comments in Buddypress Activity
* WARNING: Test thoroughly if it works in your environment before using in production code.
* LICENSE: Public domain
*/
/*
* When a new comment gets added to the database, add this comment to the
* activity stream
*/
function bca_record_activity($comment_id, $approval) {
if($approval == 1) {
$comment = get_comment($comment_id);
$userlink = bp_core_get_userlink($comment->user_id);
$postlink = '<a href="' . get_permalink($comment->comment_post_ID) . '">'
. get_the_title($comment->comment_post_ID) . '</a>';
bp_activity_add(array(
'action' => sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ),
$userlink, $postlink),
'content' => $comment->comment_content,
'component' => 'bp_plugin',
'user_id' => $comment->user_id,
'type' => 'new_blog_comment',
));
}
}
//comment_post is triggered "just after a comment is saved in the database".
add_action('comment_post', 'bca_record_activity', 10, 2);
/*
* We want activity entries of blog comments to be shown as "mini"-entries
*/
function bca_minify_activity($array) {
$array[] = 'new_blog_comment';
return $array;
}
add_filter('bp_activity_mini_activity_types', 'bca_minify_activity');
/*
* Disables comments on this type of activity entry
*/
function bca_remove_commenting($can_comment) {
if($can_comment == true) {
$can_comment = ! ('new_blog_comment' == bp_get_activity_action_name());
}
return $can_comment;
}
add_filter('bp_activity_can_comment', 'bca_remove_commenting');
?>
@shuffless

This comment has been minimized.

Show comment
Hide comment
@shuffless

shuffless Dec 29, 2014

Where do you put this piece of code?

Where do you put this piece of code?

@mattker

This comment has been minimized.

Show comment
Hide comment
@mattker

mattker Mar 11, 2015

@shuffless You add this code to the file bp-custom.php in the /wp-content/plugins/ folder

Also - if I didn't want to disable the comments... how would I do that?

mattker commented Mar 11, 2015

@shuffless You add this code to the file bp-custom.php in the /wp-content/plugins/ folder

Also - if I didn't want to disable the comments... how would I do that?

@thenetking

This comment has been minimized.

Show comment
Hide comment
@thenetking

thenetking Sep 13, 2015

Thank you so much. I looked for this for hours, days even. Buddypress is a great piece of code for the most part but omg trying to find info on how to manipulate it is ridiculous.

Thank you so much. I looked for this for hours, days even. Buddypress is a great piece of code for the most part but omg trying to find info on how to manipulate it is ridiculous.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment