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
← All changes | includes/admin/menu/Create_Topic.php +31 -19 1.3.22.2.0 View file →
@@ -1,27 +1,39 @@
1 1 <?php
2 +/**
3 + * Create Topic functionality
4 + *
5 + * @package Forumax
6 + */
7 +
8 +defined( 'ABSPATH' ) || exit;
9 +
2 10 // AJAX handler to create a topic
3 -add_action( 'wp_ajax_bbp_create_topic', 'bbp_create_topic' );
4 -function bbp_create_topic() {
5 -
11 +add_action( 'wp_ajax_forumax_create_topic', 'forumax_create_topic' );
12 +
13 +/**
14 + * Create a new topic.
15 + */
16 +function forumax_create_topic() {
17 +
6 18 // Check the nonce
7 19 check_ajax_referer( 'bbpc-admin-nonce', 'bbpc_nonce' );
8 20
9 21 if ( ! current_user_can( 'manage_options' ) ) {
10 - wp_send_json_error( 'Unauthorized request.' );
11 - }
22 + wp_send_json_error( 'Unauthorized request.' );
23 + }
12 24
13 - $bbp_topic_title = isset( $_POST['bbp_topic_title'] ) ? sanitize_text_field( $_POST['bbp_topic_title'] ) : '';
14 - if ( empty( $bbp_topic_title ) ) {
15 - wp_send_json_error( 'Topic title cannot be empty.' );
16 - }
25 + $bbp_topic_title = isset( $_POST['bbp_topic_title'] ) ? sanitize_text_field( wp_unslash( $_POST['bbp_topic_title'] ) ) : '';
26 + if ( empty( $bbp_topic_title ) ) {
27 + wp_send_json_error( 'Topic title cannot be empty.' );
28 + }
17 29
18 - $forum_id = ! empty ( $_POST['forum_id'] ) ? absint( $_POST['forum_id'] ) : 0;
19 - $topic_author = bbp_get_current_user_id();
30 + $forum_id = ! empty( $_POST['forum_id'] ) ? absint( $_POST['forum_id'] ) : 0;
31 + $topic_author = bbp_get_current_user_id();
20 32
21 33 $parent_item = get_children( [
22 34 'post_parent' => $forum_id,
23 - 'post_type' => 'topic'
35 + 'post_type' => 'topic',
24 36 ] );
25 37
26 38 $add = 2;
27 39 $order = count( $parent_item );
@@ -27,23 +39,23 @@
27 39 $order = count( $parent_item );
28 40 $order = $order + $add;
29 41
30 42 // Create topic object
31 - $topic_data = apply_filters( 'bbp_new_topic_pre_insert', array(
43 + $topic_data = apply_filters( 'bbp_new_topic_pre_insert', [
32 44 'post_author' => $topic_author,
33 45 'post_title' => $bbp_topic_title,
34 46 'post_parent' => $forum_id,
35 47 'post_content' => '',
36 - 'post_type' => bbp_get_topic_post_type(),
48 + 'post_type' => bbp_get_topic_post_type(),
37 49 'post_status' => 'publish',
38 - 'menu_order' => $order
39 - ) );
40 -
50 + 'menu_order' => $order,
51 + ] );
52 +
41 53 $topic_id = wp_insert_post( $topic_data, true );
42 54
43 55 if ( is_wp_error( $topic_id ) ) {
44 56 wp_send_json_error( 'Failed to create the topic.' );
45 57 }
46 -
58 +
47 59 do_action( 'bbp_new_topic', $topic_id, $forum_id, '', $topic_author );
48 60 wp_send_json_success( 'Topic created successfully.' );
49 -}
61 +}