Merhaba, wp plugin yazmak istiyorum. Plugin sunişi yapacak, chatgpt apiye bağlanıp verilen başlıkta makale yazdırıp wordprese siteye ekleyecek. Birlikte yazabilirmiyiz plugini lutfen

Sonuç fena değil gibi


<?php
/**
* Plugin Name: ChatGPT Article Writer
* Description: Connects to the ChatGPT API to generate articles based on a given title and adds them to the WordPress site.
* Version: 1.0
* Author: Your Name
*/

function chatgpt_generate_article($title) {
$api_key = 'YOUR_API_KEY';
$prompt = "Please write a detailed article about: " . $title;
$api_url = 'https://api.openai.com/v4/completions';

// API'ye istek yapma
$response = wp_remote_post($api_url, [
'body' => json_encode([
'model' => 'text-davinci-003', // Modeli güncelleyin
'prompt' => $prompt,
'temperature' => 0.7,
'max_tokens' => 2048,
]),
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $api_key,
],
]);

if (is_wp_error($response)) {
return;
}

$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
$article_content = $data['choices'][0]['text'];

// WordPress'e makale ekleme
wp_insert_post([
'post_title' => $title,
'post_content' => $article_content,
'post_status' => 'publish',
'post_author' => 1, // Yazar ID'si
'post_category' => [2], // Kategori ID'si
]);
}

// Bu fonksiyonu tetiklemek için bir yol sağlamanız gerekecek, örneğin bir shortcode veya bir WP-Cron işi.
?>