bp_activity_add_notification_for_synced_blog_comment( int $activity_id, WP_Comment $post_type_comment, array $activity_args, object $activity_post_object )
Add a notification for post comments to the post author or post commenter.
Description
Requires "activity feed commenting on posts and comments" to be enabled.
Parameters
- $activity_id
-
(Required) The activity comment ID.
- $post_type_comment
-
(Required) WP Comment object.
- $activity_args
-
(Required) Activity comment arguments.
- $activity_post_object
-
(Required) The post type tracking args object.
Source
File: bp-activity/bp-activity-notifications.php
function bp_activity_add_notification_for_synced_blog_comment( $activity_id, $post_type_comment, $activity_args, $activity_post_object ) {
// If activity comments are disabled for WP posts, stop now!
if ( bp_disable_blogforum_comments() || empty( $activity_id ) ) {
return;
}
// Send a notification to the blog post author.
if ( (int) $post_type_comment->post->post_author !== (int) $activity_args['user_id'] ) {
// Only add a notification if comment author is a registered user.
// @todo Should we remove this restriction?
if ( ! empty( $post_type_comment->user_id ) ) {
bp_notifications_add_notification( array(
'user_id' => $post_type_comment->post->post_author,
'item_id' => $activity_id,
'secondary_item_id' => $post_type_comment->user_id,
'component_name' => buddypress()->activity->id,
'component_action' => 'update_reply',
'date_notified' => $post_type_comment->comment_date_gmt,
'is_new' => 1,
) );
}
}
// Send a notification to the parent comment author for follow-up comments.
if ( ! empty( $post_type_comment->comment_parent ) ) {
$parent_comment = get_comment( $post_type_comment->comment_parent );
if ( ! empty( $parent_comment->user_id ) && (int) $parent_comment->user_id !== (int) $activity_args['user_id'] ) {
bp_notifications_add_notification( array(
'user_id' => $parent_comment->user_id,
'item_id' => $activity_id,
'secondary_item_id' => $post_type_comment->user_id,
'component_name' => buddypress()->activity->id,
'component_action' => 'comment_reply',
'date_notified' => $post_type_comment->comment_date_gmt,
'is_new' => 1,
) );
}
}
}
Changelog
| Version | Description |
|---|---|
| BuddyPress 2.6.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.