api_url kısmına hangi siteden çekileceğini belirliyorsunuz.. daha sonra eklenti.php olarak kaydedip wordpress eklenti kısmına yükleyin wordpress admin panelinden etkinleştirin artık eklentiniz hazır
<?php
/*
Plugin Name: WP Remote Get Content by ID Range
Description: Belirtilen URL ve ID aralığındaki WordPress yazılarını çeker ve yayınlar.
Version: 1.0
Author: Sizin Adınız
*/
// Eklenti sayfasını oluştur
function wp_remote_get_content_by_id_range_page() {
?>
<div class="wrap">
<h1>WP Remote Get Content by ID Range</h1>
<form method="post">
<label for="site_url">Site URL:</label>
<input type="text" id="site_url" name="site_url" required>
<label for="start_id">Başlangıç ID:</label>
<input type="number" id="start_id" name="start_id" required>
<label for="end_id">Bitiş ID:</label>
<input type="number" id="end_id" name="end_id" required>
<input type="submit" value="İçerikleri Çek ve Paylaş">
</form>
<?php
if (isset($_POST['site_url'], $_POST['start_id'], $_POST['end_id'])) {
$site_url = esc_url($_POST['site_url']);
$start_id = intval($_POST['start_id']);
$end_id = intval($_POST['end_id']);
if ($start_id > 0 && $end_id >= $start_id) {
fetch_and_publish_content_by_range($site_url, $start_id, $end_id);
} else {
echo '<p>Lütfen geçerli bir başlangıç ve bitiş ID girin.</p>';
}
}
?>
</div>
<?php
}
// Belirtilen URL ve ID aralığındaki WordPress yazılarını çeken ve yayınlayan fonksiyon
function fetch_and_publish_content_by_range($site_url, $start_id, $end_id) {
for ($id = $start_id; $id <= $end_id; $id++) {
$target_api_url = $site_url . '/wp-json/wp/v2/posts/' . $id;
$response = wp_remote_get($target_api_url);
if (is_wp_error($response)) {
continue;
} else {
$post_data = json_decode(wp_remote_retrieve_body($response), true);
if (!empty($post_data) && !isset($post_data['error'])) {
$post_title = $post_data['title']['rendered'];
$post_content = $post_data['content']['rendered'];
$new_post = array(
'post_title' => $post_title,
'post_content' => $post_content,
'post_status' => 'publish',
);
$new_post_id = wp_insert_post($new_post);
if (is_wp_error($new_post_id)) {
continue;
}
echo 'ID ' . $id . ' başarıyla çekildi ve yayınlandı.<br>';
}
}
}
}
// Eklenti sayfasını admin menüsüne ekleyin
add_action('admin_menu', function () {
add_menu_page('WP Remote Get Content by ID Range', 'Remote Content by ID Range', 'manage_options', 'wp_remote_get_content_by_id_range', 'wp_remote_get_content_by_id_range_page');
});
?>


