| 1 |
<?php |
| 2 |
/** |
| 3 |
* Render a forum item with its sub-forums recursively. |
| 4 |
* |
| 5 |
* @param int $forum_id The forum ID. |
| 6 |
* @param int $depth The nesting depth level. |
| 7 |
* @param array $parent_forums Reference to the parent forums array. |
| 8 |
* @param bool $is_active Whether this forum should be active. |
| 9 |
* |
| 10 |
* @return void |
| 11 |
*/ |
| 12 |
function forumax_render_forum_item( $forum_id, $depth = 0, &$parent_forums = [], $is_active = false ) { |
| 13 |
$current_post = $forum_id; |
| 14 |
$active_class = $is_active ? 'is-active' : ''; |
| 15 |
$depth_class = $depth > 0 ? 'is-subforum depth-' . $depth : ''; |
| 16 |
$count_children = get_children( |
| 17 |
[ |
| 18 |
'post_parent' => $current_post, |
| 19 |
'post_type' => bbp_get_topic_post_type(), |
| 20 |
'orderby' => 'menu_order', |
| 21 |
'order' => 'asc', |
| 22 |
'post_status' => [ 'any', 'spam' ], |
| 23 |
] |
| 24 |
); |
| 25 |
|
| 26 |
// Get sub-forums for this forum. |
| 27 |
$sub_forums = new WP_Query( |
| 28 |
[ |
| 29 |
'post_type' => bbp_get_forum_post_type(), |
| 30 |
'posts_per_page' => -1, |
| 31 |
'post_parent' => $forum_id, |
| 32 |
'orderby' => 'menu_order', |
| 33 |
'order' => 'ASC', |
| 34 |
'post_status' => 'publish', |
| 35 |
] |
| 36 |
); |
| 37 |
|
| 38 |
$has_subforums = $sub_forums->have_posts(); |
| 39 |
?> |
| 40 |
<li class="easydocs-navitem <?php echo esc_attr( $active_class . ' ' . $depth_class ); ?>" data-rel="tab-<?php echo esc_attr( $current_post ); ?>" data-id="<?php echo esc_attr( $current_post ); ?>" data-depth="<?php echo esc_attr( $depth ); ?>"> |
| 41 |
<?php if ( $has_subforums ) : ?> |
| 42 |
<button type="button" class="subforum-toggle" aria-expanded="true" title="<?php esc_attr_e( 'Toggle sub-forums', 'forumax' ); ?>"> |
| 43 |
<span class="dashicons dashicons-arrow-down-alt2"></span> |
| 44 |
</button> |
| 45 |
<?php endif; ?> |
| 46 |
<div class="title"> |
| 47 |
<div class="featured-image"> |
| 48 |
<?php |
| 49 |
if ( get_the_post_thumbnail( $current_post ) ) : |
| 50 |
echo get_the_post_thumbnail( $current_post, 'forumax_32x32', array( 'alt' => get_the_title( $current_post ) ) ); |
| 51 |
else : |
| 52 |
?> |
| 53 |
<span class="dashicons dashicons-buddicons-forums"></span> |
| 54 |
<?php endif; ?> |
| 55 |
</div> |
| 56 |
|
| 57 |
<span class="easydocs-forums-title"><?php echo esc_html( get_the_title( $current_post ) ); ?></span> |
| 58 |
</div> |
| 59 |
<div class="total-page"> |
| 60 |
<span> |
| 61 |
<?php echo count( $count_children ) > 0 ? count( $count_children ) : ''; ?> |
| 62 |
</span> |
| 63 |
</div> |
| 64 |
<div class="link-wrapper link"> |
| 65 |
<?php |
| 66 |
if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) : |
| 67 |
?> |
| 68 |
<a href="<?php echo esc_url( get_edit_post_link( $current_post ) ); ?>" class="link edit" target="_blank" title="<?php esc_attr_e( 'Edit this forum.', 'forumax' ); ?>"> |
| 69 |
<span class="dashicons dashicons-edit"></span> |
| 70 |
</a> |
| 71 |
<?php |
| 72 |
endif; |
| 73 |
?> |
| 74 |
|
| 75 |
<a href="<?php echo esc_url( get_permalink( $current_post ) ); ?>" class="link external-link" target="_blank" data-id="tab-<?php echo esc_attr( $current_post ); ?>" title="<?php esc_attr_e( 'View this forum in new tab', 'forumax' ); ?>"> |
| 76 |
<span class="dashicons dashicons-external"></span> |
| 77 |
</a> |
| 78 |
<?php |
| 79 |
if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) : |
| 80 |
?> |
| 81 |
<a href="javascript:void(0);" bbp_forum_id="<?php echo esc_attr( $current_post ); ?>" class="link forum-delete" title="<?php esc_attr_e( 'Move this forum to the Trash', 'forumax' ); ?>"> |
| 82 |
<span class="dashicons dashicons-trash"></span> |
| 83 |
</a> |
| 84 |
<a href="javascript:void(0);" bbp_parent_forum_id="<?php echo esc_attr( $current_post ); ?>" class="link add-subforum" title="<?php esc_attr_e( 'Add Sub-Forum', 'forumax' ); ?>"> |
| 85 |
<span class="dashicons dashicons-plus-alt2"></span> |
| 86 |
</a> |
| 87 |
<?php endif; ?> |
| 88 |
</div> |
| 89 |
</li> |
| 90 |
<?php |
| 91 |
// Render sub-forums if any. |
| 92 |
if ( $has_subforums ) : |
| 93 |
?> |
| 94 |
<li class="easydocs-subforum-container" data-parent="<?php echo esc_attr( $forum_id ); ?>"> |
| 95 |
<ul class="easydocs-subforums"> |
| 96 |
<?php |
| 97 |
while ( $sub_forums->have_posts() ) : |
| 98 |
$sub_forums->the_post(); |
| 99 |
$sub_forum_id = get_the_ID(); |
| 100 |
$parent_forums[] = $sub_forum_id; |
| 101 |
forumax_render_forum_item( $sub_forum_id, $depth + 1, $parent_forums, false ); |
| 102 |
endwhile; |
| 103 |
wp_reset_postdata(); |
| 104 |
?> |
| 105 |
</ul> |
| 106 |
</li> |
| 107 |
<?php |
| 108 |
endif; |
| 109 |
} |
| 110 |
?> |
| 111 |
<div class="tab-menu <?php echo $count > 12 ? '' : 'short'; ?>"> |
| 112 |
<div class="tab-menu-left-layer"></div> |
| 113 |
<ul class="easydocs-navbar"> |
| 114 |
<?php |
| 115 |
$i = 0; |
| 116 |
while ( $forum_query->have_posts() ) : |
| 117 |
$forum_query->the_post(); |
| 118 |
$i++; |
| 119 |
$current_post = get_the_ID(); |
| 120 |
$parent_forums[] = $current_post; |
| 121 |
$is_active = ( 1 === $i ); |
| 122 |
forumax_render_forum_item( $current_post, 0, $parent_forums, $is_active ); |
| 123 |
endwhile; |
| 124 |
wp_reset_postdata(); |
| 125 |
?> |
| 126 |
</ul> |
| 127 |
</div> |