bp_activity_get_comment_depth( object|int $comment )

Return the current activity comment depth.

Description

Parameters

$comment

(Required) Object of the activity comment or activity comment ID. Usually unnecessary when used in activity comment loop.

Return

(int)

Source

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

	function bp_activity_get_comment_depth( $comment = 0 ) {
		$depth = 0;

		// Activity comment loop takes precedence.
		if ( isset( $GLOBALS['activities_template']->activity->current_comment->depth ) ) {
			$depth = $GLOBALS['activities_template']->activity->current_comment->depth;

		// Get depth for activity comment manually.
		} elseif ( ! empty( $comment ) ) {
			// We passed an activity ID, so fetch the activity object.
			if ( is_int( $comment ) ) {
				$comment = new BP_Activity_Activity( $comment );
			}

			// Recurse through activity tree to find the depth.
			if ( is_object( $comment ) && isset( $comment->type ) && 'activity_comment' === $comment->type ) {
				// Fetch the entire root comment tree... ugh.
				$comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) );

				// Recursively find our comment object from the comment tree.
				$iterator  = new RecursiveArrayIterator( $comments );
				$recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST );
				foreach ( $recursive as $cid => $cobj ) {
					// Skip items that are not a comment object.
					if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) {
						continue;
					}

					// We found the activity comment! Set the depth.
					if ( $cid === $comment->id && isset( $cobj->depth ) ) {
						$depth = $cobj->depth;
						break;
					}
				}
			}
		}

		/**
		 * Filters the comment depth of the current activity comment.
		 *
		 * @since BuddyPress 2.0.0
		 *
		 * @param int $depth Depth for the current activity comment.
		 */
		return apply_filters( 'bp_activity_get_comment_depth', $depth );
	}

Changelog

Changelog
Version Description
BuddyPress 2.8.0 Added $comment as a parameter. BuddyPress 2.8.0 Added $comment as a parameter.
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.