Help me fix a function that adds blog comments to activity
-
I have this function that I pieced together a few months back that worked until a recent WP or BP upgrade (not sure which or when). The function adds blog comments as activity items so that I can have them show up in notifications without actually using the activity feed. It no longer works. Does anyone know why this wouldn’t work anymore?
function rt_bp_blogs_record_comment( $comment_id, $is_approved = true ) {
global $bp;// Get the users comment
$recorded_comment = get_comment( $comment_id );// Don't record activity if the comment hasn't been approved
if ( empty( $is_approved ) )
return false;// Don't record activity if no email address has been included
if ( empty( $recorded_comment->comment_author_email ) )
return false;// Get the user_id from the comment author email.
$user = get_user_by( 'email', $recorded_comment->comment_author_email );
$user_id = (int)$user->ID;// If there's no registered user id, don't record activity
if ( empty( $user_id ) )
return false;// Get blog and post data
$blog_id = get_current_blog_id();
$recorded_comment->post = get_post( $recorded_comment->comment_post_ID );if ( empty( $recorded_comment->post ) || is_wp_error( $recorded_comment->post ) )
return false;// If this is a password protected post, don't record the comment
if ( !empty( $recorded_comment->post->post_password ) )
return false;// Don't record activity if the comment's associated post isn't a WordPress Post
if ( !in_array( $recorded_comment->post->post_type, apply_filters( 'bp_blogs_record_comment_post_types', array( 'post' ) ) ) )
return false;$is_blog_public = apply_filters( 'bp_is_blog_public', (int)get_blog_option( $blog_id, 'blog_public' ) );
// If blog is public allow activity to be posted
if ( $is_blog_public ) {// Get activity related links
$post_permalink = get_permalink( $recorded_comment->comment_post_ID );
$comment_link = htmlspecialchars( get_comment_link( $recorded_comment->comment_ID ) );// Prepare to record in activity streams
if ( is_multisite() )
$activity_action = sprintf( __( '%1$s commented on the post, %2$s, on the site %3$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '', '' . get_blog_option( $blog_id, 'blogname' ) . '' );
else
$activity_action = sprintf( __( '%1$s commented on the post, %2$s', 'buddypress' ), bp_core_get_userlink( $user_id ), '' . apply_filters( 'the_title', $recorded_comment->post->post_title ) . '' );$activity_content = $recorded_comment->comment_content;
// Record in activity streams
$activity_id = bp_blogs_record_activity( array(
'user_id' => $user_id,
'action' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_action', array( $activity_action, &$recorded_comment, $comment_link ) ),
'content' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_content', array( $activity_content, &$recorded_comment, $comment_link ) ),
'primary_link' => apply_filters_ref_array( 'bp_blogs_activity_new_comment_primary_link', array( $comment_link, &$recorded_comment ) ),
'type' => 'new_blog_comment',
'item_id' => $blog_id,
'secondary_item_id' => $comment_id,
'recorded_time' => $recorded_comment->comment_date_gmt
) );// Update the blogs last active date
bp_blogs_update_blogmeta( $blog_id, 'last_activity', bp_core_current_time() );
}do_action('bp_blogs_comment_recorded',$activity_id);
return $recorded_comment;
}
remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 );
remove_action( 'edit_comment', 'bp_blogs_record_comment', 10 );
add_action( 'comment_post', 'rt_bp_blogs_record_comment', 10, 2 );
add_action( 'edit_comment', 'rt_bp_blogs_record_comment', 10 );
You must be logged in to reply to this topic.