PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
bbp-core / includes / admin / menu / admin_ui / forums.php

forums.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.1, at includes/admin/menu/admin_ui/forums.php

131 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 topics without loading every topic object.
17 $topic_count_query = new WP_Query(
18 [
19 'post_parent' => $current_post,
20 'post_type' => bbp_get_topic_post_type(),
21 'post_status' => [ 'any', 'spam' ],
22 'posts_per_page' => 1,
23 'fields' => 'ids',
24 'update_post_meta_cache' => false,
25 'update_post_term_cache' => false,
26 ]
27 );
28 $topic_count = (int) $topic_count_query->found_posts;
29
30 // Get sub-forums for this forum.
31 $sub_forums = new WP_Query(
32 [
33 'post_type' => bbp_get_forum_post_type(),
34 'posts_per_page' => -1,
35 'post_parent' => $forum_id,
36 'orderby' => 'menu_order',
37 'order' => 'ASC',
38 'post_status' => 'publish',
39 ]
40 );
41
42 $has_subforums = $sub_forums->have_posts();
43 ?>
44 <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 ); ?>">
45 <?php if ( $has_subforums ) : ?>
46 <button type="button" class="subforum-toggle" aria-expanded="true" title="<?php esc_attr_e( 'Toggle sub-forums', 'forumax' ); ?>">
47 <span class="dashicons dashicons-arrow-down-alt2"></span>
48 </button>
49 <?php endif; ?>
50 <div class="title">
51 <div class="featured-image">
52 <?php
53 if ( get_the_post_thumbnail( $current_post ) ) :
54 echo get_the_post_thumbnail( $current_post, 'forumax_32x32', array( 'alt' => get_the_title( $current_post ) ) );
55 else :
56 ?>
57 <span class="dashicons dashicons-buddicons-forums"></span>
58 <?php endif; ?>
59 </div>
60
61 <span class="easydocs-forums-title"><?php echo esc_html( get_the_title( $current_post ) ); ?></span>
62 </div>
63 <div class="total-page">
64 <span>
65 <?php echo $topic_count > 0 ? esc_html( $topic_count ) : ''; ?>
66 </span>
67 </div>
68 <div class="link-wrapper link">
69 <?php
70 if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) :
71 ?>
72 <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' ); ?>">
73 <span class="dashicons dashicons-edit"></span>
74 </a>
75 <?php
76 endif;
77 ?>
78
79 <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' ); ?>">
80 <span class="dashicons dashicons-external"></span>
81 </a>
82 <?php
83 if ( current_user_can( 'editor' ) || current_user_can( 'administrator' ) ) :
84 ?>
85 <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' ); ?>">
86 <span class="dashicons dashicons-trash"></span>
87 </a>
88 <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' ); ?>">
89 <span class="dashicons dashicons-plus-alt2"></span>
90 </a>
91 <?php endif; ?>
92 </div>
93 </li>
94 <?php
95 // Render sub-forums if any.
96 if ( $has_subforums ) :
97 ?>
98 <li class="easydocs-subforum-container" data-parent="<?php echo esc_attr( $forum_id ); ?>">
99 <ul class="easydocs-subforums">
100 <?php
101 while ( $sub_forums->have_posts() ) :
102 $sub_forums->the_post();
103 $sub_forum_id = get_the_ID();
104 $parent_forums[] = $sub_forum_id;
105 forumax_render_forum_item( $sub_forum_id, $depth + 1, $parent_forums, false );
106 endwhile;
107 wp_reset_postdata();
108 ?>
109 </ul>
110 </li>
111 <?php
112 endif;
113 }
114 ?>
115 <div class="tab-menu <?php echo $count > 12 ? '' : 'short'; ?>">
116 <div class="tab-menu-left-layer"></div>
117 <ul class="easydocs-navbar">
118 <?php
119 $i = 0;
120 while ( $forum_query->have_posts() ) :
121 $forum_query->the_post();
122 $i++;
123 $current_post = get_the_ID();
124 $parent_forums[] = $current_post;
125 $is_active = ( 1 === $i );
126 forumax_render_forum_item( $current_post, 0, $parent_forums, $is_active );
127 endwhile;
128 wp_reset_postdata();
129 ?>
130 </ul>
131 </div>