bp_activity_new_comment_notification( int $comment_id, int $commenter_id, array $params = array() )

Send email and BP notifications when an activity item receives a comment.

Description

Parameters

$comment_id

(Required) The comment id.

$commenter_id

(Required) The ID of the user who posted the comment.

$params

(Optional) bp_activity_new_comment().

Default value: array()

Source

File: bp-activity/bp-activity-functions.php

4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
function bp_activity_new_comment_notification( $comment_id = 0, $commenter_id = 0, $params = array() ) {
    $original_activity = new BP_Activity_Activity( $params['activity_id'] );
    $poster_name       = bp_core_get_user_displayname( $commenter_id );
    $thread_link       = bp_activity_get_permalink( $params['activity_id'] );
 
    remove_filter( 'bp_get_activity_content_body', 'convert_smilies' );
    remove_filter( 'bp_get_activity_content_body', 'wpautop' );
    remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
 
    /** This filter is documented in bp-activity/bp-activity-template.php */
    $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $params['content'], &$original_activity ) );
 
    add_filter( 'bp_get_activity_content_body', 'convert_smilies' );
    add_filter( 'bp_get_activity_content_body', 'wpautop' );
    add_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 );
 
    if ( $original_activity->user_id != $commenter_id ) {
 
        // Send an email if the user hasn't opted-out.
        if ( 'no' != bp_get_user_meta( $original_activity->user_id, 'notification_activity_new_reply', true ) ) {
 
            $unsubscribe_args = array(
                'user_id'           => $original_activity->user_id,
                'notification_type' => 'activity-comment',
            );
 
            $args = array(
                'tokens' => array(
                    'comment.id'                => $comment_id,
                    'commenter.id'              => $commenter_id,
                    'usermessage'               => wp_strip_all_tags( $content ),
                    'original_activity.user_id' => $original_activity->user_id,
                    'poster.name'               => $poster_name,
                    'thread.url'                => esc_url( $thread_link ),
                    'unsubscribe'               => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
                ),
            );
 
            bp_send_email( 'activity-comment', $original_activity->user_id, $args );
        }
 
        /**
         * Fires at the point that notifications should be sent for activity comments.
         *
         * @since BuddyPress 2.6.0
         *
         * @param BP_Activity_Activity $original_activity The original activity.
         * @param int                  $comment_id        ID for the newly received comment.
         * @param int                  $commenter_id      ID of the user who made the comment.
         * @param array                $params            Arguments used with the original activity comment.
         */
        do_action( 'bp_activity_sent_reply_to_update_notification', $original_activity, $comment_id, $commenter_id, $params );
    }
 
 
    /*
     * If this is a reply to another comment, send an email notification to the
     * author of the immediate parent comment.
     */
    if ( empty( $params['parent_id'] ) || ( $params['activity_id'] == $params['parent_id'] ) ) {
        return;
    }
 
    $parent_comment = new BP_Activity_Activity( $params['parent_id'] );
 
    if ( $parent_comment->user_id != $commenter_id && $original_activity->user_id != $parent_comment->user_id ) {
 
        // Send an email if the user hasn't opted-out.
        if ( 'no' != bp_get_user_meta( $parent_comment->user_id, 'notification_activity_new_reply', true ) ) {
 
            $unsubscribe_args = array(
                'user_id'           => $parent_comment->user_id,
                'notification_type' => 'activity-comment-author',
            );
 
            $args = array(
                'tokens' => array(
                    'comment.id'             => $comment_id,
                    'commenter.id'           => $commenter_id,
                    'usermessage'            => wp_strip_all_tags( $content ),
                    'parent-comment-user.id' => $parent_comment->user_id,
                    'poster.name'            => $poster_name,
                    'thread.url'             => esc_url( $thread_link ),
                    'unsubscribe'            => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
                ),
            );
 
            bp_send_email( 'activity-comment-author', $parent_comment->user_id, $args );
        }
 
        /**
         * Fires at the point that notifications should be sent for comments on activity replies.
         *
         * @since BuddyPress 2.6.0
         *
         * @param BP_Activity_Activity $parent_comment The parent activity.
         * @param int                  $comment_id     ID for the newly received comment.
         * @param int                  $commenter_id   ID of the user who made the comment.
         * @param array                $params         Arguments used with the original activity comment.
         */
        do_action( 'bp_activity_sent_reply_to_reply_notification', $parent_comment, $comment_id, $commenter_id, $params );
    }
}

Changelog

Changelog
Version Description
BuddyPress 2.5.0 Updated to use new email APIs. BuddyPress 2.5.0 Updated to use new email APIs.
BuddyPress 1.2.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.