PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.0.0
Forumax – AI Powered Advanced Community Forum Plugin v2.0.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.0.0, at includes/admin/menu/Delete_Topic.php

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