# bbp-core/2.5.1/includes/admin/menu/admin_ui.php

Forumax – AI Powered Advanced Community Forum Plugin, version 2.5.1. 245 lines.

- Page: https://pluginprobe.com/plugins/bbp-core/2.5.1/code/includes/admin/menu/admin_ui.php
- Raw: https://pluginprobe.com/plugins/bbp-core/2.5.1/raw/includes/admin/menu/admin_ui.php
- Modified: 2026-10-12T12:43:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/bbp-core/2.5.1/code/includes/admin/menu/admin_ui.php#L10-L20`.

```php
<?php
if ( ! class_exists( 'bbPress' ) ) {
	return;
}

if ( ! function_exists( 'forumax_admin_reply_stats' ) ) {
	/**
	 * Reply counts and pending reply IDs for many topics in two queries.
	 *
	 * Replaces per-topic get_children()/WP_Query calls, which made this screen
	 * run several queries per topic on large forums.
	 *
	 * @param int[] $topic_ids Topic IDs.
	 * @return array{total: array<int,int>, pending: array<int,int[]>}
	 */
	function forumax_admin_reply_stats( array $topic_ids ) {
		global $wpdb;

		$stats     = [
			'total'   => [],
			'pending' => [],
		];
		$topic_ids = array_values( array_unique( array_filter( array_map( 'intval', $topic_ids ) ) ) );

		foreach ( array_chunk( $topic_ids, 500 ) as $chunk ) {
			$placeholders = implode( ',', array_fill( 0, count( $chunk ), '%d' ) );
			$args         = array_merge( [ bbp_get_reply_post_type() ], $chunk );

			// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
			$rows = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_parent, post_status FROM {$wpdb->posts} WHERE post_type = %s AND post_status IN ( 'publish', 'draft', 'pending' ) AND post_parent IN ( $placeholders ) ORDER BY post_date DESC", $args ) );

			foreach ( $rows as $row ) {
				$parent                    = (int) $row->post_parent;
				$stats['total'][ $parent ] = ( $stats['total'][ $parent ] ?? 0 ) + 1;

				if ( 'pending' === $row->post_status ) {
					$stats['pending'][ $parent ][] = (int) $row->ID;
				}
			}
		}

		// Pending reply excerpts and each topic's freshness link are rendered,
		// so load those posts together instead of one query each.
		$prime_ids = empty( $stats['pending'] ) ? [] : array_merge( ...array_values( $stats['pending'] ) );
		foreach ( $topic_ids as $topic_id ) {
			$prime_ids[] = (int) get_post_meta( $topic_id, '_bbp_last_active_id', true );
		}
		$prime_ids = array_filter( $prime_ids );

		if ( ! empty( $prime_ids ) ) {
			_prime_post_caches( $prime_ids, false, true );
		}

		return $stats;
	}
}

$parent_forums = [];
$fcount        = wp_count_posts( bbp_get_forum_post_type() );
$forum_count   = (int) ( $fcount->publish + $fcount->hidden + $fcount->spam );
?>
<div class="wrap">
<div class="body-dark">
	<?php
	if ( $forum_count > 0 ) :
		include __DIR__ . '/admin_ui/header.php';
		?>
		<main>
			<div class="easydocs-sidebar-menu">
				<div class="tab-container">
					<?php
					$forum_query = new WP_Query( [
						'post_type'      => bbp_get_forum_post_type(),
						'posts_per_page' => -1,
						'post_parent'    => 0,
						'orderby'        => 'menu_order',
						'order'          => 'ASC',
						'post_status'    => 'publish',
					] );
					$count = $forum_query->found_posts;
					// Left Sidebar Forums.
					include __DIR__ . '/admin_ui/forums.php';
					?>
					<div class="easydocs-tab-content">
						<?php
						$ids       = 0;
						$container = 1;
						if ( is_array( $parent_forums ) ) :
							foreach ( $parent_forums as $item ) :
								$ids ++;
								$container ++;
								$active = $ids == 1 ? ' tab-active' : '';

								$children = new WP_Query(
									[
										'post_parent'    => $item,
										'post_type'      => bbp_get_topic_post_type(),
										'orderby'        => 'menu_order',
										'order'          => 'asc',
										'posts_per_page' => -1,
										'post_status'    => [ 'any', 'spam' ],
									]
								);

								$count_open     = 0;
								$count_closed   = 0;
								$count_hidden   = 0;
								$count_no_reply = 0;
								$count_solved   = 0;
								$count_unsolved = 0;
								$count_trash    = 0;

								$reply_stats = forumax_admin_reply_stats( wp_list_pluck( $children->posts, 'ID' ) );

								while ( $children->have_posts() ) : $children->the_post();
									$topic_id = get_the_ID();

									// Count open/closed topics.
									if ( bbp_is_topic_closed( $topic_id ) ) {
										$count_closed++;
									} else {
										$count_open++;
									}

									// Count spam( hidden ) topics.
									if ( bbp_is_topic_spam( $topic_id ) || bbp_is_topic_pending( $topic_id ) ) {
										$count_hidden++;
									}

									// Replies count.
									if ( empty( $reply_stats['total'][ $topic_id ] ) ) {
										$count_no_reply++;
									}

									// Count solved.
									// Before using $GLOBALS['forumax_solve_topic'], check if it is set
									if (isset($GLOBALS['forumax_solve_topic']) && $GLOBALS['forumax_solve_topic']->is_solved($topic_id)) {
										$count_solved++;
									} else {
										$count_unsolved++;
									}
								endwhile; 
								wp_reset_postdata();

								// Count trashed topics without loading them.
								$trash_topic = new WP_Query( [
									'post_parent'            => $item,
									'post_type'              => bbp_get_topic_post_type(),
									'posts_per_page'         => 1,
									'post_status'            => [ 'trash' ],
									'fields'                 => 'ids',
									'update_post_meta_cache' => false,
									'update_post_term_cache' => false,
								] );
								$count_trash = (int) $trash_topic->found_posts;
								?>
								<div class="easydocs-tab <?php echo esc_attr( $active ); ?>" id="tab-<?php echo esc_attr( $item ); ?>">

									<!-- Tab filters. -->
									<?php include __DIR__ . '/admin_ui/tab_filters.php'; ?>

									<!-- Children topics. -->
									<?php include __DIR__ . '/admin_ui/topics.php'; ?>

									<?php if ( $children->post_count > 0 ) : ?>
										<div class="controls bbpc-admin-pagination" style="display:none;">
											<div class="mixitup-control mixitup-page-list"></div>
										</div>
									<?php endif; ?>

									<a class="easydocs-btn easydocs-btn-outline-blue easydocs-btn-sm easydocs-btn-round button button-info section-doc" id="bbpc-topic" target="_blank" name="submit" href="javascript:void(0)" bbp_forum_id="<?php echo esc_attr( $item ); ?>">
										<?php esc_html_e( 'Add Topic', 'forumax' ); ?>
									</a>
								</div>
								<?php
								endforeach;
							endif;
							?>
						</div>
					</div>
				</div>
			</main>
			<?php
		else :
			?>
			<div class="eazydocs-no-content">
				<img src="<?php echo esc_url( FORUMAX_IMG . 'icon/folder-open.png' ); ?>" alt="<?php esc_attr_e( 'Folder Open', 'forumax' ); ?>">
				<p class="big-p"> <?php esc_html_e( 'No forums found. Get started by creating a new forum or importing demo data.', 'forumax' ); ?> </p>
				<p class="forumax-empty-actions">
					<a href="javascript:void(0)" type="button" id="bbpc-forum" class="button button-primary ezd-btn btn-lg">
						<span class="dashicons dashicons-plus-alt2"></span>
						<?php esc_html_e( 'Create Forum', 'forumax' ); ?>
					</a>
					<span class="forumax-actions-separator"><?php esc_html_e( 'or', 'forumax' ); ?></span>
					<a href="javascript:void(0)" type="button" id="forumax-import-demo" class="button ezd-btn btn-lg forumax-import-demo-btn">
						<span class="dashicons dashicons-database-import"></span>
						<?php esc_html_e( 'Import Demo Data', 'forumax' ); ?>
					</a>
				</p>
			</div>
			<?php
		endif;
		?>
	</div>
</div>

<script>
	(function ($) {
		$(document).ready(function () {
			let docContainer = document.querySelectorAll('.easydocs-tab');
			var config = {
				controls: {
					scope: 'local',
				},
				animation: {
					enable: false,
				},
				load: {
					filter: '<?php echo esc_js( forumax_get_opt( 'default_filter', '.open-topics' ) ); ?>'
				},
				pagination: {
					limit: 10,
				},
				callbacks: {
					onMixEnd: function(state) {
						var pagination = state.container.querySelector('.bbpc-admin-pagination');
						if ( pagination ) {
							// Count matching items directly from the DOM using the active
							// filter selector. MixItUp always renders prev/next buttons so
							// children.length is unreliable for detecting multi-page results.
							var selector    = state.activeFilter ? state.activeFilter.selector : '';
							var matchCount  = ( ! selector || selector === 'all' )
								? state.container.querySelectorAll('.mix').length
								: state.container.querySelectorAll(selector).length;
							pagination.style.display = matchCount > 10 ? 'block' : 'none';
						}
					}
				}
			};
			for (let i = 0; i < docContainer.length; i++) {
			var mixer1 = mixitup(docContainer[i], config);
		}
	});
})(jQuery);
</script>
```
