BP_Activity_List_Table::can_comment( array $item )

Checks if an activity item can be replied to.

Description

This method merges functionality from bp_activity_can_comment() and bp_blogs_disable_activity_commenting(). This is done because the activity list table doesn’t use a BuddyBoss activity loop, which prevents those functions from working as intended.

Parameters

$item

(array) (Required) An array version of the BP_Activity_Activity object.

Return

(bool) $can_comment

Source

File: bp-activity/classes/class-bp-activity-list-table.php

	protected function can_comment( $item  ) {
		$can_comment = bp_activity_type_supports( $item['type'], 'comment-reply' );

		if ( ! $this->disable_blogforum_comments && bp_is_active( 'blogs' ) ) {
			$parent_activity = false;

			if ( bp_activity_type_supports( $item['type'], 'post-type-comment-tracking' ) ) {
				$parent_activity = (object) $item;
			} elseif ( 'activity_comment' === $item['type'] ) {
				$parent_activity = new BP_Activity_Activity( $item['item_id'] );
				$can_comment     = bp_activity_can_comment_reply( (object) $item );
			}

			if ( isset( $parent_activity->type ) && bp_activity_post_type_get_tracking_arg( $parent_activity->type, 'post_type' ) ) {
				// Fetch blog post comment depth and if the blog post's comments are open.
				bp_blogs_setup_activity_loop_globals( $parent_activity );

				$can_comment = bp_blogs_can_comment_reply( true, $item );
			}
		}

		/**
		 * Filters if an activity item can be commented on or not.
		 *
		 * @since BuddyPress 2.0.0
		 * @since BuddyPress 2.5.0 Add a second parameter to include the activity item into the filter.
		 *
		 * @param bool  $can_comment Whether an activity item can be commented on or not.
		 * @param array $item        An array version of the BP_Activity_Activity object.
		 */
		return apply_filters( 'bp_activity_list_table_can_comment', $can_comment, $item );
	}

Changelog

Changelog
Version Description
BuddyPress 2.5.0 Include Post type activities types BuddyPress 2.5.0 Include Post type activities types
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.