Changeset 14150
- Timestamp:
- 12/16/2025 04:29:43 PM (4 months ago)
- Location:
- branches/14.0
- Files:
-
- 4 edited
-
src/bp-activity/bp-activity-template.php (modified) (1 diff)
-
src/bp-activity/classes/class-bp-activity-activity.php (modified) (3 diffs)
-
src/bp-core/bp-core-template-loader.php (modified) (1 diff)
-
tests/phpunit/testcases/activity/functions/bpActivityGetCommentDepth.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/14.0/src/bp-activity/bp-activity-template.php
r13897 r14150 2635 2635 $comments = BP_Activity_Activity::get_activity_comments( $comment->item_id, 1, constant( 'PHP_INT_MAX' ) ); 2636 2636 2637 if ( ! is_array( $comments ) ) { 2638 $comments = []; 2639 } 2640 2637 2641 // Recursively find our comment object from the comment tree. 2638 $iterator = new RecursiveArrayIterator( $comments ); 2639 $recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST ); 2640 foreach ( $recursive as $cid => $cobj ) { 2641 // Skip items that are not a comment object. 2642 if ( ! is_numeric( $cid ) || ! is_object( $cobj ) ) { 2643 continue; 2644 } 2645 2646 // We found the activity comment! Set the depth. 2647 if ( $cid === $comment->id && isset( $cobj->depth ) ) { 2648 $depth = $cobj->depth; 2649 break; 2650 } 2642 $comment_in_tree = BP_Activity_Activity::find_comment_in_tree( $comments, $comment->id ); 2643 2644 if ( is_object( $comment_in_tree ) && isset( $comment_in_tree->depth ) ) { 2645 $depth = $comment_in_tree->depth; 2651 2646 } 2652 2647 } -
branches/14.0/src/bp-activity/classes/class-bp-activity-activity.php
r13897 r14150 1629 1629 * @param string $spam Optional. 'ham_only' (default), 'spam_only' or 'all'. 1630 1630 * @param int $top_level_parent_id Optional. The id of the root-level parent activity item. 1631 * @return array The updated activities with nested comments.1631 * @return array|false The updated activities with nested comments. False if no comments are found. 1632 1632 */ 1633 1633 public static function get_activity_comments( $activity_id, $left, $right, $spam = 'ham_only', $top_level_parent_id = 0 ) { … … 1744 1744 if ( isset( $direct_parent->secondary_item_id ) ) { 1745 1745 // If the direct parent is not an activity update, that means we've reached 1746 // the parent activity item (e g. new_blog_post).1746 // the parent activity item (e.g. new_blog_post). 1747 1747 if ( 'activity_update' !== $direct_parent->type ) { 1748 1748 $parent_id = $r->item_id; … … 2089 2089 return $wpdb->get_var( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET hide_sitewide = 1 WHERE user_id = %d", $user_id ) ); 2090 2090 } 2091 2092 /** 2093 * Recursively find a comment object from a nested comment tree. 2094 * 2095 * @since 14.5.0 2096 * 2097 * @param array $comments Array of comment objects with nested children. 2098 * @param int $target_id The comment ID to find. 2099 * @return object|false The comment object if found, false otherwise. 2100 */ 2101 public static function find_comment_in_tree( $comments, $target_id ) { 2102 2103 if ( ! is_array( $comments ) ) { 2104 return false; 2105 } 2106 2107 foreach ( $comments as $comment_id => $comment ) { 2108 // Skip items that are not a comment object. 2109 if ( ! is_numeric( $comment_id ) || ! is_object( $comment ) ) { 2110 continue; 2111 } 2112 2113 if ( (int) $comment_id === (int) $target_id ) { 2114 return $comment; 2115 } 2116 2117 // Recurse into children if they exist. 2118 if ( ! empty( $comment->children ) && is_array( $comment->children ) ) { 2119 $found = self::find_comment_in_tree( $comment->children, $target_id ); 2120 2121 if ( false !== $found ) { 2122 return $found; 2123 } 2124 } 2125 } 2126 2127 return false; 2128 } 2091 2129 } -
branches/14.0/src/bp-core/bp-core-template-loader.php
r13903 r14150 594 594 $url_query_chunks = bp_parse_args( $GLOBALS['wp']->query_string, array() ); 595 595 $directory = key( $url_query_chunks ); 596 if ( isset( $ bp_directories[ $directory ] ) ) {596 if ( isset( $directory, $bp_directories[ $directory ] ) ) { 597 597 $url_query_chunks[ $directory ] = $bp_directories[ $directory ]; 598 598 } -
branches/14.0/tests/phpunit/testcases/activity/functions/bpActivityGetCommentDepth.php
r11737 r14150 41 41 bp_has_activities( 'display_comments=threaded' ); 42 42 43 // Loop through activity comments generated in activity loop. 44 $recursive = new RecursiveIteratorIterator( new RecursiveArrayIterator( $GLOBALS['activities_template']->activities[0]->children ), RecursiveIteratorIterator::SELF_FIRST ); 45 foreach ( $recursive as $aid => $a ) { 46 if ( ! is_numeric( $aid ) || ! is_object( $a ) ) { 43 $children = $GLOBALS['activities_template']->activities[0]->children; 44 45 foreach ( array( $comment_one, $comment_one_one, $comment_two ) as $aid ) { 46 $a = BP_Activity_Activity::find_comment_in_tree( $children, $aid ); 47 48 if ( false === $a ) { 47 49 continue; 48 50 } … … 66 68 break; 67 69 } 68 69 70 } 70 71
Note: See TracChangeset
for help on using the changeset viewer.