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
2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 | 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
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.