bp_blogs_activity_comment_single_action( string $retval, BP_Activity_Activity $activity )

Formats single activity comment entries to use the blog comment action.


Description Description

This is only done if the activity comment is associated with a blog comment.


Parameters Parameters

$retval

(Required) The activity action.

$activity

(Required) Activity object.


Top ↑

Return Return

(string)


Top ↑

Source Source

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

function bp_blogs_activity_comment_single_action( $retval, $activity ) {
	if ( 'activity_comment' !== $activity->type ) {
		return $retval;
	}

	if ( bp_disable_blogforum_comments() ) {
		return $retval;
	}

	$parent_activity = new BP_Activity_Activity( $activity->item_id );

	if ( ! isset( $parent_activity->type ) ) {
		return $retval;
	}

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

	if ( ! $post_type ) {
		return $retval;
	}

	$blog_comment_id = bp_activity_get_meta( $activity->id, "bp_blogs_{$post_type}_comment_id" );

	if ( ! empty( $blog_comment_id ) ) {
		$bp = buddypress();

		// Check if a comment action id is set for the parent activity
		$comment_action_id = bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'comment_action_id' );

		// Use the action string callback for the activity type
		if ( ! empty( $comment_action_id ) ) {
			// Fake a 'new_{post_type}_comment' by cloning the activity object.
			$object = clone $activity;

			// Set the type of the activity to be a comment about a post type
			$object->type = $comment_action_id;

			// Use the blog ID as the item_id.
			$object->item_id = $parent_activity->item_id;

			// Use comment ID as the secondary_item_id.
			$object->secondary_item_id = $blog_comment_id;

			// Get the format callback for this activity comment
			$format_callback = bp_activity_post_type_get_tracking_arg( $comment_action_id, 'format_callback' );

			// now format the activity action using the 'new_{post_type}_comment' action callback
			if ( is_callable( $format_callback ) ) {
				$retval = call_user_func_array( $format_callback, array( '', $object ) );
			}
		}
	}

	return $retval;
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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