Skip to content

Instantly share code, notes, and snippets.

@stillatmylinux
Created January 4, 2019 20:08
Show Gist options
  • Save stillatmylinux/2bb2d5c715b16ddd6d8fe017a4eeddb5 to your computer and use it in GitHub Desktop.
Save stillatmylinux/2bb2d5c715b16ddd6d8fe017a4eeddb5 to your computer and use it in GitHub Desktop.
<?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