bp_blogs_remove_associated_blog_comments( array $activity_ids = array(), bool $force_delete = true )

Removes blog comments that are associated with activity comments.

Description

See also

Parameters

$activity_ids

(Optional) The activity IDs to check association with blog comments.

Default value: array()

$force_delete

(Optional) Whether to force delete the comments. If false, comments are trashed instead.

Default value: true

Source

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

function bp_blogs_remove_associated_blog_comments( $activity_ids = array(), $force_delete = true ) {
	// Query args.
	$query_args = array(
		'meta_query' => array(
			array(
				'key'     => 'bp_activity_comment_id',
				'value'   => implode( ',', (array) $activity_ids ),
				'compare' => 'IN',
			)
		)
	);

	// Get comment.
	$comment_query = new WP_Comment_Query;
	$comments = $comment_query->query( $query_args );

	// Found the corresponding comments
	// let's delete them!
	foreach ( $comments as $comment ) {
		wp_delete_comment( $comment->comment_ID, $force_delete );

		// If we're trashing the comment, remove the meta key as well.
		if ( empty( $force_delete ) ) {
			delete_comment_meta( $comment->comment_ID, 'bp_activity_comment_id' );
		}
	}
}

Changelog

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