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

Removes blog comments that are associated with activity comments.


Description Description

See also See also


Top ↑

Parameters Parameters

$activity_ids

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

Default value: array()

$force_delete

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

Default value: true


Top ↑

Source 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' );
		}
	}
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.