bp_activity_delete_comment( int $activity_id, int $comment_id )

Delete an activity comment.

Description

Parameters

$activity_id

(Required) The ID of the "root" activity, ie the comment's oldest ancestor.

$comment_id

(Required) The ID of the comment to be deleted.

Return

(bool) True on success, false on failure.

Source

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

3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
function bp_activity_delete_comment( $activity_id, $comment_id ) {
    $deleted = false;
 
    /**
     * Filters whether BuddyPress should delete an activity comment or not.
     *
     * You may want to hook into this filter if you want to override this function and
     * handle the deletion of child comments differently. Make sure you return false.
     *
     * @since BuddyPress 1.2.0
     * @since BuddyPress 2.5.0 Add the deleted parameter (passed by reference)
     *
     * @param bool $value       Whether BuddyPress should continue or not.
     * @param int  $activity_id ID of the root activity item being deleted.
     * @param int  $comment_id  ID of the comment being deleted.
     * @param bool $deleted     Whether the activity comment has been deleted or not.
     */
    if ( ! apply_filters_ref_array( 'bp_activity_delete_comment_pre', array( true, $activity_id, $comment_id, &$deleted ) ) ) {
        return $deleted;
    }
 
    // Check if comment still exists.
    $comment = new BP_Activity_Activity( $comment_id );
    if ( empty( $comment->id ) ) {
        return false;
    }
 
    // Delete any children of this comment.
    bp_activity_delete_children( $activity_id, $comment_id );
 
    // Delete the actual comment.
    if ( ! bp_activity_delete( array( 'id' => $comment_id, 'type' => 'activity_comment' ) ) ) {
        return false;
    } else {
        $deleted = true;
    }
 
    // Purge comment cache for the root activity update.
    wp_cache_delete( $activity_id, 'bp_activity_comments' );
 
    // Recalculate the comment tree.
    BP_Activity_Activity::rebuild_activity_comment_tree( $activity_id );
 
    /**
     * Fires at the end of the deletion of an activity comment, before returning success.
     *
     * @since BuddyPress 1.2.0
     *
     * @param int $activity_id ID of the activity that has had a comment deleted from.
     * @param int $comment_id  ID of the comment that was deleted.
     */
    do_action( 'bp_activity_delete_comment', $activity_id, $comment_id );
 
    return $deleted;
}

Changelog

Changelog
Version Description
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.