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 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.


Top ↑

Parameters Parameters

$retval

(bool) (Required) Whether BuddyPress should continue or not.

$parent_activity_id

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

$activity_id

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

$deleted

(bool) (Required) Whether the comment was deleted or not.


Top ↑

Return Return

(bool)


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


Top ↑

Changelog Changelog

Changelog
Version Description
2.5.0 Add the $delected parameter
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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