<?php

// WordPress sitesinin URL'si ve yorum eklemek istediğiniz makalenin ID'si
$site_url = 'https://yourwordpresssite.com';
$post_id = 1; // Makale ID'sini buraya girin

// Yorum eklenecek URL
$comments_url = $site_url . '/wp-json/wp/v2/comments';

// Yorum verisi
$comment_data = array(
    'post' => $post_id,
    'author_name' => 'John Doe', // Yorum yapanın adı
    'author_email' => 'johndoe@example.com', // Yorum yapanın e-posta adresi
    'content' => 'Bu bir test yorumudur.' // Yorum içeriği
);

// Yorum verisini JSON formatına dönüştür
$comment_data_json = json_encode($comment_data);

// Yorum eklemek için POST isteği gönder
$ch = curl_init($comments_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $comment_data_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// Yanıtı kontrol et
if ($http_code == 201) {
    echo 'Yorum başarıyla eklendi.';
} else {
    echo 'Yorum eklenirken bir hata oluştu. Durum kodu: ' . $http_code . '<br>';
    echo 'Hata mesajı: ' . $response;
}

// cURL bağlantısını kapat
curl_close($ch);
?>