bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity )

Updates the blog comment when the associated activity comment is edited.


Parameters Parameters

$activity

(BP_Activity_Activity) (Required) The activity object.


Source Source

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

function bp_blogs_sync_activity_edit_to_post_comment( BP_Activity_Activity $activity ) {
	// This is a new entry, so stop!
	// We only want edits!
	if ( empty( $activity->id ) || bp_disable_blogforum_comments() ) {
		return;
	}

	// Fetch parent activity item.
	$parent_activity = new BP_Activity_Activity( $activity->item_id );

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

	$post_type = bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' );

	// No associated post type for this activity comment, stop.
	if ( ! $post_type ) {
		return;
	}

	// Try to see if a corresponding blog comment exists.
	$post_comment_id = bp_activity_get_meta( $activity->id, "bp_blogs_{$post_type}_comment_id" );

	if ( empty( $post_comment_id ) ) {
		return;
	}

	// Handle multisite.
	switch_to_blog( $parent_activity->item_id );

	// Get the comment status.
	$post_comment_status = wp_get_comment_status( $post_comment_id );
	$old_comment_status  = $post_comment_status;

	// No need to edit the activity, as it's the activity who's updating the comment.
	remove_action( 'transition_comment_status', 'bp_activity_transition_post_type_comment_status', 10 );
	remove_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment', 10 );

	if ( 1 === $activity->is_spam && 'spam' !== $post_comment_status ) {
		wp_spam_comment( $post_comment_id );
	} elseif ( ! $activity->is_spam ) {
		if ( 'spam' === $post_comment_status  ) {
			wp_unspam_comment( $post_comment_id );
		} elseif ( 'trash' === $post_comment_status ) {
			wp_untrash_comment( $post_comment_id );
		} else {
			// Update the blog post comment.
			wp_update_comment( array(
				'comment_ID'       => $post_comment_id,
				'comment_content'  => $activity->content,
			) );
		}
	}

	// Restore actions.
	add_action( 'transition_comment_status',     'bp_activity_transition_post_type_comment_status', 10, 3 );
	add_action( 'bp_activity_post_type_comment', 'bp_blogs_comment_sync_activity_comment',          10, 4 );

	restore_current_blog();
}


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.