Show Advanced Options (For Pro Users)
Generate
admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'rapidtextai_nonce' ), 'api_key' => get_option('rapidtextai_api_key', ''), ) ); } add_action( 'admin_enqueue_scripts', 'rapidtextai_metabox_enqueue_scripts' ); // AJAX handler function rapidtextai_generate_article() { // Check nonce check_ajax_referer( 'rapidtextai_nonce', 'nonce' ); // Get POST data $type = isset( $_POST['type'] ) ? sanitize_text_field( $_POST['type'] ) : ''; $tone_of_voice = isset( $_POST['toneOfVoice'] ) ? sanitize_text_field( $_POST['toneOfVoice'] ) : ''; $language = isset( $_POST['language'] ) ? sanitize_text_field( $_POST['language'] ) : 'en'; $text = isset( $_POST['text'] ) ? sanitize_textarea_field( $_POST['text'] ) : ''; $temperature = isset( $_POST['temperature'] ) ? sanitize_text_field( $_POST['temperature'] ) : '0.7'; $custom_prompt = isset( $_POST['custom_prompt'] ) ? sanitize_textarea_field( $_POST['custom_prompt'] ) : ''; $chatsession = isset( $_POST['chatsession'] ) ? sanitize_text_field( $_POST['chatsession'] ) : ''; $userid = isset( $_POST['userid'] ) ? sanitize_text_field( $_POST['userid'] ) : ''; // Handle model if ( isset( $_POST['model'] ) && ! empty( $_POST['model'] ) ) { $model = sanitize_text_field( $_POST['model'] ); } else { $model = 'default_model'; // Set a default model if not provided } // Build the API request payload $api_payload = array( 'type' => $type, 'toneOfVoice' => $tone_of_voice, 'language' => $language, 'text' => $text, 'temperature' => $temperature, 'custom_prompt' => $custom_prompt, 'chatsession' => $chatsession, 'userid' => $userid, 'model' => $model, ); // Now, make the API call $current_api_key = get_option('rapidtextai_api_key', ''); // API endpoint with API key $api_url = "https://app.rapidtextai.com/openai/detailedarticle-v3?gigsixkey=" . urlencode( $current_api_key ); $args = array( 'body' => $api_payload, 'timeout' => 60, ); $response = wp_remote_post( $api_url, $args ); if ( is_wp_error( $response ) ) { wp_send_json_error( $response->get_error_message() ); } else { $body = wp_remote_retrieve_body( $response ); wp_send_json_success( $body ); } } add_action( 'wp_ajax_rapidtextai_generate_article', 'rapidtextai_generate_article' );