bp_blogs_sync_delete_from_activity_comment( bool $retval, int $parent_activity_id, int $activity_id, bool $deleted )

Deletes the blog comment when the associated activity comment is deleted.

Description

Note: This is hooked on the ‘bp_activity_delete_comment_pre’ filter instead of the ‘bp_activity_delete_comment’ action because we need to fetch the activity comment children before they are deleted.

Parameters

$retval

(Required) Whether BuddyPress should continue or not.

$parent_activity_id

(Required) The parent activity ID for the activity comment.

$activity_id

(Required) The activity ID for the pending deleted activity comment.

$deleted

(Required) Whether the comment was deleted or not.

Return

(bool)

Source

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

function bp_blogs_sync_delete_from_activity_comment( $retval, $parent_activity_id, $activity_id, &$deleted ) {
	// Check if parent activity is a blog post.
	$parent_activity = new BP_Activity_Activity( $parent_activity_id );

	// if parent activity isn't a post type having the buddypress-activity support, stop now!
	if ( ! bp_activity_type_supports( $parent_activity->type, 'post-type-comment-tracking' ) ) {
		return $retval;
	}

	// Fetch the activity comments for the activity item.
	$activity = bp_activity_get( array(
		'in'               => $activity_id,
		'display_comments' => 'stream',
		'spam'             => 'all',
	) );

	// Get all activity comment IDs for the pending deleted item.
	$activity_ids   = bp_activity_recurse_comments_activity_ids( $activity );
	$activity_ids[] = $activity_id;

	// Handle multisite
	// switch to the blog where the comment was made.
	switch_to_blog( $parent_activity->item_id );

	// Remove associated blog comments.
	bp_blogs_remove_associated_blog_comments( $activity_ids, current_user_can( 'moderate_comments' ) );

	// Multisite again!
	restore_current_blog();

	// Rebuild activity comment tree
	// emulate bp_activity_delete_comment().
	BP_Activity_Activity::rebuild_activity_comment_tree( $parent_activity_id );

	// Avoid the error message although the comments were successfully deleted
	$deleted = true;

	// We're overriding the default bp_activity_delete_comment() functionality
	// so we need to return false.
	return false;
}

Changelog

Changelog
Version Description
BuddyPress 2.5.0 Add the $delected parameter BuddyPress 2.5.0 Add the $delected parameter
BuddyPress 2.0.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.