PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.2.0
Forumax – AI Powered Advanced Community Forum Plugin v2.2.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 2.0.0 2.1.0 All 29 releases
bbp-core / includes / admin / menu / Delete_Topic.php

Delete_Topic.php in Forumax – AI Powered Advanced Community Forum Plugin 2.2.0, at includes/admin/menu/Delete_Topic.php

57 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Delete Topic functionality
4 *
5 * @package Forumax
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 // AJAX handler to delete a topic
11 add_action( 'wp_ajax_forumax_delete_topic', 'forumax_delete_topic' );
12
13 /**
14 * Delete a topic and its replies.
15 */
16 function forumax_delete_topic() {
17
18 // Check the nonce
19 check_ajax_referer( 'bbpc-admin-nonce', 'bbpc_nonce' );
20
21 if ( ! current_user_can( 'manage_options' ) ) {
22 wp_send_json_error( 'Unauthorized request.' );
23 }
24
25 $topic_id = ! empty( $_POST['topic_id'] ) ? absint( $_POST['topic_id'] ) : 0;
26 if ( empty( $topic_id ) ) {
27 wp_send_json_error( 'Topic ID cannot be empty.' );
28 }
29
30 $replies = get_children( [
31 'post_parent' => $topic_id,
32 'post_type' => 'reply',
33 'orderby' => 'menu_order',
34 'order' => 'asc',
35 ] );
36
37 $reply_ids = '';
38 if ( is_array( $replies ) ) {
39 foreach ( $replies as $reply ) {
40 $reply_ids .= $reply->ID . ',';
41 }
42 }
43
44 $topic_posts = $topic_id . ',' . $reply_ids;
45 $topic_posts = explode( ',', $topic_posts );
46 $topic_posts_int = array_map( 'intval', $topic_posts );
47
48 foreach ( $topic_posts_int as $delete_topic ) {
49 if ( ! empty( $delete_topic ) ) {
50 wp_trash_post( $delete_topic );
51 }
52 }
53
54 wp_send_json_success( 'Topic Deleted successfully.' );
55 wp_die();
56 }
57