'', 'ai' => '', 'model' => '', 'subject' => '', 'length' => 300, 'prompt_title' => 'Write one blog post title about [subject].', 'prompt_content' => 'Write blog post about [subject]. Use html characters and subheadings. And content length should be [length] words.', 'recurrence' => 'hourly', 'categories' => array(), 'publish_date' => 'directly', ]; $args = []; // Check if ( $_POST['post_id'] ){ $post_id = intval( $_POST['post_id'] ); $args = [ 'title' => get_the_title( $post_id ), 'ai' => get_post_meta( $post_id, 'aibp_ai', true ), 'model' => get_post_meta( $post_id, 'aibp_model', true ), 'subject' => get_post_meta( $post_id, 'aibp_subject', true ), 'length' => get_post_meta( $post_id, 'aibp_length', true ), 'prompt_title' => get_post_meta( $post_id, 'aibp_prompt_title', true ), 'prompt_content' => get_post_meta( $post_id, 'aibp_prompt_content', true ), 'recurrence' => get_post_meta( $post_id, 'aibp_recurrence', true ), 'categories' => get_post_meta( $post_id, 'aibp_post_categories', true ), 'publish_date' => get_post_meta( $post_id, 'aibp_post_publish_date', true ), ]; } $args = wp_parse_args( $args, $defaults ); ob_start(); ?>

'post[categories]', 'echo' => true, 'selected' => (array) $args['categories'], ] ); ?>

'recurrence', 'id' => 'recurrence', 'options' => Helper::get_wp_get_schedules(), 'selected' => $args['recurrence'] ] ); ?>
isset( $_POST['post_id'] ) ? esc_html__( 'Edit Event', 'ai-bulk-post' ) : esc_html__( 'Add Event', 'ai-bulk-post' ), 'output' => $output_string ] ); } function add_event() { check_ajax_referer( 'aibp-nonce', 'nonce' ); $sanitized_form = filter_input(INPUT_POST, 'form', FILTER_SANITIZE_STRING); parse_str($sanitized_form, $parsed_form); $title = sanitize_text_field( $parsed_form['title'] ); $ai = sanitize_text_field( $parsed_form['ai'] ); $model = sanitize_text_field( $parsed_form['model'] ); $subject = sanitize_text_field( $parsed_form['subject'] ); $length = intval( $parsed_form['length'] ); $prompt_title = sanitize_text_field( $parsed_form['prompt_title'] ); $prompt_content = sanitize_text_field( $parsed_form['prompt_content'] ); $recurrence = sanitize_text_field( $parsed_form['recurrence'] ); $post_categories = $parsed_form['post']['categories'] ?? array(); $post_publish_date = $parsed_form['post']['publish_date'] ?? 'directly'; // @see: https://developer.wordpress.org/reference/functions/wp_insert_post/ $post_id = wp_insert_post( [ 'post_type' => 'aibp_events', 'post_status' => 'publish', 'post_title' => $title, 'meta_input' => [ 'aibp_status' => 'passive', // passive, active 'aibp_ai' => $ai, 'aibp_model' => $model, 'aibp_subject' => $subject, 'aibp_length' => $length, 'aibp_prompt_title' => $prompt_title, 'aibp_prompt_content' => $prompt_content, 'aibp_recurrence' => $recurrence, 'aibp_post_categories' => $post_categories, 'aibp_post_publish_date' => $post_publish_date, ] ] ); if ( is_wp_error( $post_id ) ) { wp_send_json( [ 'error' => true, $post_id->get_error_message() ] ); } wp_send_json( $post_id ); } function update_event() { check_ajax_referer( 'aibp-nonce', 'nonce' ); $sanitized_form = filter_input(INPUT_POST, 'form', FILTER_SANITIZE_STRING); parse_str($sanitized_form, $parsed_form); $post_id = intval( $_POST['post_id'] ); $title = sanitize_text_field( $parsed_form['title'] ); $ai = sanitize_text_field( $parsed_form['ai'] ); $model = sanitize_text_field( $parsed_form['model'] ); $subject = sanitize_text_field( $parsed_form['subject'] ); $length = intval( $parsed_form['length'] ); $prompt_title = sanitize_text_field( $parsed_form['prompt_title'] ); $prompt_content = sanitize_text_field( $parsed_form['prompt_content'] ); $recurrence = sanitize_text_field( $parsed_form['recurrence'] ); $post_categories = $parsed_form['post']['categories'] ?? array(); $post_publish_date = $parsed_form['post']['publish_date'] ?? 'directly'; // @see: https://developer.wordpress.org/reference/functions/wp_insert_post/ $post_id = wp_update_post( [ 'ID' => $post_id, 'post_type' => 'aibp_events', 'post_status' => 'publish', 'post_title' => $title, 'meta_input' => [ 'aibp_ai' => $ai, 'aibp_model' => $model, 'aibp_subject' => $subject, 'aibp_length' => $length, 'aibp_prompt_title' => $prompt_title, 'aibp_prompt_content' => $prompt_content, 'aibp_recurrence' => $recurrence, 'aibp_post_categories' => $post_categories, 'aibp_post_publish_date' => $post_publish_date, ] ] ); if ( is_wp_error( $post_id ) ) { wp_send_json( [ 'error' => true, $post_id->get_error_message() ] ); } wp_send_json( $post_id ); } function delete_event() { check_ajax_referer( 'aibp-nonce', 'nonce' ); $post_id = intval( $_POST['post_id'] ); if ( $post_id ) { wp_delete_post( $post_id ); wp_send_json( [ 'message' => esc_html__( 'Deleted!', 'ai-bulk-post' ) ] ); } wp_send_json( [ 'error' => true, 'message' => esc_html__( 'Event cannot found!', 'ai-bulk-post' ) ] ); } function update_event_status() { check_ajax_referer( 'aibp-nonce', 'nonce' ); $post_id = intval( $_POST['post_id'] ); if ( $post_id ) { $get_status = get_post_meta( $post_id, 'aibp_status', true ); $status = ''; if ( empty( $get_status ) || $get_status == 'passive' ) { $status = 'active'; } else { $status = 'passive'; } update_post_meta( $post_id, 'aibp_status', $status ); wp_send_json( [ 'message' => esc_html__( 'Updated!', 'ai-bulk-post' ), 'status' => $status, ] ); } wp_send_json( [ 'error' => true, 'message' => esc_html__( 'Event cannot found!', 'ai-bulk-post' ) ] ); } }