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 / Create_Forum.php

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

45 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // AJAX handler to create a forum
3 add_action( 'wp_ajax_forumax_create_forum', 'forumax_create_forum' );
4 function forumax_create_forum() {
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 $bbp_forum_title = isset( $_POST['bbp_forum_title'] ) ? sanitize_text_field( $_POST['bbp_forum_title'] ) : '';
14 if ( empty( $bbp_forum_title ) ) {
15 wp_send_json_error( 'Forum title cannot be empty.' );
16 }
17
18 $args = [
19 'post_type' => 'forum',
20 'post_parent' => 0
21 ];
22
23 $query = new \WP_Query( $args );
24 $total = $query->found_posts;
25 $add = 2;
26 $order = $total + $add;
27
28 // Insert the post
29 $post_id = wp_insert_post( array(
30 'post_title' => $bbp_forum_title,
31 'post_parent' => 0,
32 'post_content' => '',
33 'post_type' => 'forum',
34 'post_status' => 'publish',
35 'post_author' => get_current_user_id(),
36 'menu_order' => $order,
37 ) );
38
39 if ( is_wp_error( $post_id ) ) {
40 wp_send_json_error( 'Failed to create the forum.' );
41 }
42
43 // Return success
44 wp_send_json_success( 'Forum created successfully.' );
45 }