# bbp-core/2.4.4/includes/admin/menu/Delete_Topic.php

Forumax – AI Powered Advanced Community Forum Plugin, version 2.4.4. 57 lines.

- Page: https://pluginprobe.com/plugins/bbp-core/2.4.4/code/includes/admin/menu/Delete_Topic.php
- Raw: https://pluginprobe.com/plugins/bbp-core/2.4.4/raw/includes/admin/menu/Delete_Topic.php
- Modified: 2026-01-28T15:54:38+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.4.4/code/includes/admin/menu/Delete_Topic.php#L10-L20`.

```php
<?php
/**
 * Delete Topic functionality
 *
 * @package Forumax
 */

defined( 'ABSPATH' ) || exit;

// AJAX handler to delete a topic
add_action( 'wp_ajax_forumax_delete_topic', 'forumax_delete_topic' );

/**
 * Delete a topic and its replies.
 */
function forumax_delete_topic() {

	// Check the nonce
	check_ajax_referer( 'bbpc-admin-nonce', 'bbpc_nonce' );

	if ( ! current_user_can( 'manage_options' ) ) {
		wp_send_json_error( 'Unauthorized request.' );
	}

	$topic_id = ! empty( $_POST['topic_id'] ) ? absint( $_POST['topic_id'] ) : 0;
	if ( empty( $topic_id ) ) {
		wp_send_json_error( 'Topic ID cannot be empty.' );
	}

	$replies = get_children( [
		'post_parent' => $topic_id,
		'post_type'   => 'reply',
		'orderby'     => 'menu_order',
		'order'       => 'asc',
	] );

	$reply_ids = '';
	if ( is_array( $replies ) ) {
		foreach ( $replies as $reply ) {
			$reply_ids .= $reply->ID . ',';
		}
	}

	$topic_posts     = $topic_id . ',' . $reply_ids;
	$topic_posts     = explode( ',', $topic_posts );
	$topic_posts_int = array_map( 'intval', $topic_posts );

	foreach ( $topic_posts_int as $delete_topic ) {
		if ( ! empty( $delete_topic ) ) {
			wp_trash_post( $delete_topic );
		}
	}

	wp_send_json_success( 'Topic Deleted successfully.' );
	wp_die();
}

```
