Created
January 4, 2019 20:08
-
-
Save stillatmylinux/2bb2d5c715b16ddd6d8fe017a4eeddb5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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