bbp_get_reply_ancestors( int $reply_id )

Get all ancestors to a reply


Description Description

Because settings can be changed, this function does not care if hierarchical replies are active or to what depth.


Parameters Parameters

$reply_id

(Required)


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/replies/functions.php

function bbp_get_reply_ancestors( $reply_id = 0 ) {

	// Validation
	$reply_id  = bbp_get_reply_id( $reply_id );
	$ancestors = array();

	// Reply id is valid
	if ( ! empty( $reply_id ) ) {

		// Try to get reply parent
		$reply_to = bbp_get_reply_to( $reply_id );

		// Reply has a hierarchical parent
		if ( ! empty( $reply_to ) ) {

			// Setup the current ID and current post as an ancestor
			$id        = $reply_to;
			$ancestors = array( $reply_to );

			// Get parent reply
			while ( $ancestor = bbp_get_reply( $id ) ) {

				// Does parent have a parent?
				$grampy_id = bbp_get_reply_to( $ancestor->ID );

				// Loop detection: If the ancestor has been seen before, break.
				if ( empty( $ancestor->post_parent ) || ( $grampy_id === $reply_id ) || in_array( $grampy_id, $ancestors, true ) ) {
					break;
				}

				$id = $ancestors[] = $grampy_id;
			}
		}
	}

	// Filter & return
	return (array) apply_filters( 'bbp_get_reply_ancestors', $ancestors, $reply_id );
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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