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
← All changes | includes/admin/menu/Delete_Forum.php +7 -33 2.4.3 → 2.5.1 View file →
@@ -26,43 +26,17 @@
26 26 if ( empty( $forum_id ) ) {
27 27 wp_send_json_error( 'Forum ID cannot be empty.' );
28 28 }
29 29
30 - $children = get_children( [
31 - 'post_parent' => $forum_id,
32 - 'post_type' => 'topic',
33 - 'orderby' => 'menu_order',
34 - 'order' => 'asc',
35 - ] );
36 -
37 - $topics = '';
38 - $topic_replies = '';
39 -
40 - if ( is_array( $children ) ) {
41 - foreach ( $children as $child ) {
42 - $replies = get_children( [
43 - 'post_parent' => $child->ID,
44 - 'post_type' => 'reply',
45 - 'post_status' => [ 'publish', 'draft' ],
46 - ] );
47 -
48 - $topics .= $child->ID . ',';
49 - if ( is_array( $replies ) ) {
50 - foreach ( $replies as $reply ) {
51 - $topic_replies .= $reply->ID . ',';
52 - }
53 - }
54 - }
30 + if ( ! bbp_is_forum( $forum_id ) ) {
31 + wp_send_json_error( 'Invalid forum.' );
55 32 }
56 33
57 - $forum_posts = $forum_id . ',' . $topic_replies . $topics;
58 - $forum_posts = explode( ',', $forum_posts );
59 - $forum_posts_int = array_map( 'intval', $forum_posts );
60 -
61 - foreach ( $forum_posts_int as $deletes ) {
62 - if ( ! empty( $deletes ) ) {
63 - wp_trash_post( $deletes );
64 - }
34 + // bbPress trashes the forum's topics (and their replies) on wp_trash_post
35 + // and remembers them for untrash, so there is no need to load every
36 + // topic and reply here, which timed out on large forums.
37 + if ( ! wp_trash_post( $forum_id ) ) {
38 + wp_send_json_error( 'Failed to delete the forum.' );
65 39 }
66 40
67 41 wp_send_json_success( 'Forum Deleted successfully.' );
68 42 wp_die();