Discussion::dozent_discussion_ask_question()
Source
File: classes/Discussion.php
public function dozent_discussion_ask_question(){ dozent_checking_nonce(); global $wpdb; $lecture_id = (int) dozent_input_text('post_ID'); $question_title = dozent_input_text('question_title'); $question = dozent_input_textarea('question_details'); if ( empty( $question ) || empty( $question_title ) ){ wp_send_json_error( __('Empty question title or details', 'dozent') ); } $question = [ 'title' => $question_title, 'question' => $question, ]; $user_id = get_current_user_id(); $user = get_userdata($user_id); $date = date("Y-m-d H:i:s", dozent_time()); do_action('dozent_ask_question_before', $lecture_id); $data = apply_filters('dozent_ask_question_data', [ 'comment_post_ID' => $lecture_id, 'comment_author' => $user->user_login, 'comment_date' => $date, 'comment_date_gmt' => get_gmt_from_date( $date ), 'comment_content' => wp_json_encode($question), 'comment_approved' => 'answer_pending', 'comment_agent' => 'DozentLMSPlugin', 'comment_type' => 'dozent_discussion', 'user_id' => $user_id, ]); $wpdb->insert($wpdb->comments, $data); $comment_id = (int) $wpdb->insert_id; do_action('dozent_ask_question_after', $lecture_id, $comment_id, $data ); wp_send_json_success(__('Question has been added successfully', 'dozent')); }