Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Plugin Name: AppCommunity List Activity Replies
* Description: Unnest replies from comment (activity children)
* Version: 1.0.0
* Author: Matt Thiessen
*/
function appcommunity_get_nested_replies( &$replies, $activity ) {
if( !empty( $activity->children ) ) {
foreach( $activity->children as $child_activity ) {
array_push( $replies, $child_activity );
if( !empty( $child_activity->children ) ) {
appcommunity_get_nested_replies( $replies, $child_activity );
}
}
$activity->children = array();
}
}
function appcommunity_include_replies( $act_item, $retval, $request ) {
$comments = array();
foreach($act_item['activities'] as $activity) {
appcommunity_get_nested_replies( $comments, $activity );
if( !empty( $comments ) ) {
$activity->children = $comments;
}
}
}
add_action( 'appcommunity_activity_get_item', 'appcommunity_include_replies', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment