mükerrer kayıt uygulaması wordpress

Genel Forum
Cevapla
muratca61
Site Admin
Mesajlar: 35899
Kayıt: Cmt Ara 21, 2024 7:56 am

mükerrer kayıt uygulaması wordpress

Mesaj gönderen muratca61 »

selam. wordpress ile çok fazla yaazı haber içeriğim var ve bu içeriklerden mükerrer kayıtlar var bunları en hızlı en kısa şekilde nasıl tespit edebilirim. yeni bir admin uygulamasıda olabilir
bunu bir wordpress uygulaması ile yapabilir miyiz
wp-content/plugins/

Kod:Tümünü seç

duplicate-content-checker

Kod:Tümünü seç

duplicate-content-checker.php

Kod:Tümünü seç

<?php
/*
Plugin Name: Duplicate Content Checker
Description: Mükerrer yazıları başlık ve içerik bazında tespit eder.
Version: 1.0
Author: Your Name
Text Domain: duplicate-checker
*/

// Güvenlik Kontrolü
if (!defined('ABSPATH')) {
    exit;
}

// Admin Menüsünü Ekle
add_action('admin_menu', 'dcc_register_menu');
function dcc_register_menu() {
    add_menu_page(
        'Mükerrer İçerik Kontrol',
        'Mükerrer Kontrol',
        'manage_options',
        'duplicate-checker',
        'dcc_display_page',
        'dashicons-admin-page'
    );
}

// Admin Sayfasını Render Et
function dcc_display_page() {
    global $wpdb;

    // Silme İşlemi (Güvenlik Önlemli)
    if (isset($_GET['action']) && $_GET['action'] === 'delete' && isset($_GET['post_id'])) {
        if (!wp_verify_nonce($_GET['_wpnonce'], 'dcc_delete_post')) {
            wp_die('Güvenlik hatası!');
        }

        $post_id = intval($_GET['post_id']);
        if (wp_delete_post($post_id, true)) {
            echo '<div class="notice notice-success"><p>Yazı başarıyla silindi.</p></div>';
        }
    }

    // Mükerrer Yazıları Sorgula
    $duplicate_titles = $wpdb->get_results("
        SELECT post_title, GROUP_CONCAT(ID) AS ids 
        FROM {$wpdb->posts} 
        WHERE post_type = 'post' 
        AND post_status = 'publish' 
        GROUP BY post_title 
        HAVING COUNT(*) > 1
    ");

    $duplicate_contents = $wpdb->get_results("
        SELECT post_content, GROUP_CONCAT(ID) AS ids 
        FROM {$wpdb->posts} 
        WHERE post_type = 'post' 
        AND post_status = 'publish' 
        GROUP BY MD5(post_content) 
        HAVING COUNT(*) > 1
    ");

    // HTML Arayüz
    ?>
    <div class="wrap">
        <h1>Mükerrer İçerik Kontrol</h1>

        <h2>Aynı Başlıklı Yazılar</h2>
        <?php if (!empty($duplicate_titles)) : ?>
            <table class="wp-list-table widefat fixed striped">
                <thead>
                    <tr>
                        <th>Başlık</th>
                        <th>Yazı ID'leri</th>
                        <th>İşlem</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($duplicate_titles as $dup) : ?>
                        <tr>
                            <td><?php echo esc_html($dup->post_title); ?></td>
                            <td><?php echo esc_html($dup->ids); ?></td>
                            <td>
                                <a href="<?php echo admin_url('edit.php?post__in=' . $dup->ids); ?>">İncele</a> | 
                                <?php foreach (explode(',', $dup->ids) as $id) : ?>
                                    <a href="<?php echo wp_nonce_url(admin_url('admin.php?page=duplicate-checker&action=delete&post_id=' . $id), 'dcc_delete_post'); ?>">Sil (ID: <?php echo $id; ?>)</a>
                                <?php endforeach; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else : ?>
            <p>Aynı başlığa sahip yazı bulunamadı.</p>
        <?php endif; ?>

        <h2>Aynı İçerikli Yazılar</h2>
        <?php if (!empty($duplicate_contents)) : ?>
            <table class="wp-list-table widefat fixed striped">
                <thead>
                    <tr>
                        <th>İçerik (Kısaltılmış)</th>
                        <th>Yazı ID'leri</th>
                        <th>İşlem</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($duplicate_contents as $dup) : ?>
                        <tr>
                            <td><?php echo esc_html(substr($dup->post_content, 0, 100)) . '...'; ?></td>
                            <td><?php echo esc_html($dup->ids); ?></td>
                            <td>
                                <a href="<?php echo admin_url('edit.php?post__in=' . $dup->ids); ?>">İncele</a> | 
                                <?php foreach (explode(',', $dup->ids) as $id) : ?>
                                    <a href="<?php echo wp_nonce_url(admin_url('admin.php?page=duplicate-checker&action=delete&post_id=' . $id), 'dcc_delete_post'); ?>">Sil (ID: <?php echo $id; ?>)</a>
                                <?php endforeach; ?>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        <?php else : ?>
            <p>Aynı içeriğe sahip yazı bulunamadı.</p>
        <?php endif; ?>
    </div>
    <?php
}

// CSS Stilleri Ekle
add_action('admin_head', 'dcc_admin_styles');
function dcc_admin_styles() {
    echo '<style>
        .wp-list-table th, .wp-list-table td { padding: 15px; }
        .notice { margin: 20px 0; }
    </style>';
}




muratca61
Site Admin
Mesajlar: 35899
Kayıt: Cmt Ara 21, 2024 7:56 am

Re: mükerrer kayıt uygulaması wordpress

Mesaj gönderen muratca61 »

bu iyi ama sanki aynı içeriklilerin tamamını sildi

Kod:Tümünü seç

<?php
/*
Plugin Name: Advanced Duplicate Content Cleaner
Description: Mükerrer yazıları temizler, toplu silme ve ön izleme sunar.
Version: 3.0
Author: Your Name
Text Domain: advanced-duplicate-cleaner
*/

if (!defined('ABSPATH')) exit;

// Admin Menüsü
add_action('admin_menu', 'adcc_register_menu');
function adcc_register_menu() {
    add_menu_page(
        'Gelişmiş Mükerrer Temizleyici',
        'Mükerrer Temizle',
        'manage_options',
        'advanced-duplicate-cleaner',
        'adcc_display_page',
        'dashicons-admin-page'
    );
}

// Toplu Silme İşlemi
add_action('admin_init', 'adcc_bulk_delete');
function adcc_bulk_delete() {
    if (!isset($_POST['adcc_bulk_delete']) || !isset($_POST['duplicate_groups'])) return;
    
    check_admin_referer('adcc_bulk_delete_nonce', 'adcc_nonce');
    
    if (!current_user_can('manage_options')) {
        wp_die('Yetkiniz yok!');
    }

    $deleted_count = 0;
    foreach ($_POST['duplicate_groups'] as $group) {
        $ids = explode(',', sanitize_text_field($group));
        $keep_id = array_shift($ids); // İlk ID'yi koru
        
        foreach ($ids as $id) {
            if (wp_delete_post(intval($id), true)) {
                $deleted_count++;
            }
        }
    }

    add_action('admin_notices', function() use ($deleted_count) {
        echo '<div class="notice notice-success"><p>' . sprintf(__('%d adet mükerrer yazı silindi.'), $deleted_count) . '</p></div>';
    });
}

// Ana Sayfa
function adcc_display_page() {
    global $wpdb;
    
    // Sorgular
    $search = isset($_GET['search']) ? sanitize_text_field($_GET['search']) : '';
    
    $duplicate_titles = $wpdb->get_results($wpdb->prepare("
        SELECT post_title, GROUP_CONCAT(ID ORDER BY ID ASC) AS ids 
        FROM {$wpdb->posts} 
        WHERE post_type = 'post' 
        AND post_status = 'publish'
        " . ($search ? " AND (post_title LIKE %s OR post_content LIKE %s OR ID = %d)" : "") . "
        GROUP BY post_title 
        HAVING COUNT(*) > 1
    ", ($search ? array('%'.$wpdb->esc_like($search).'%', '%'.$wpdb->esc_like($search).'%', intval($search)) : array())));

    $duplicate_contents = $wpdb->get_results($wpdb->prepare("
        SELECT MD5(post_content) AS content_hash, GROUP_CONCAT(ID ORDER BY ID ASC) AS ids 
        FROM {$wpdb->posts} 
        WHERE post_type = 'post' 
        AND post_status = 'publish'
        " . ($search ? " AND (post_title LIKE %s OR post_content LIKE %s OR ID = %d)" : "") . "
        GROUP BY content_hash 
        HAVING COUNT(*) > 1
    ", ($search ? array('%'.$wpdb->esc_like($search).'%', '%'.$wpdb->esc_like($search).'%', intval($search)) : array())));
    ?>

    <div class="wrap">
        <h1>Gelişmiş Mükerrer Temizleyici</h1>

        <!-- Toplu Silme Formu -->
        <form method="post" id="adcc-bulk-form">
            <?php wp_nonce_field('adcc_bulk_delete_nonce', 'adcc_nonce'); ?>
            <input type="hidden" name="adcc_bulk_delete" value="1">
            
            <!-- Arama ve Butonlar -->
            <div class="adcc-action-bar">
                <div class="adcc-search-box">
                    <input type="text" name="search" value="<?php echo esc_attr($search); ?>" 
                           placeholder="Başlık, içerik veya ID ile ara...">
                    <button type="submit" class="button">Ara</button>
                    <?php if ($search) : ?>
                        <a href="<?php echo admin_url('admin.php?page=advanced-duplicate-cleaner'); ?>" class="button">Temizle</a>
                    <?php endif; ?>
                </div>
                <button type="submit" class="button button-danger" name="bulk_action" value="clean_selected">
                    Seçilenleri Temizle (İlkini Koru)
                </button>
            </div>

            <!-- Aynı Başlıklar -->
            <h2>Aynı Başlıklı Yazılar</h2>
            <?php if (!empty($duplicate_titles)) : ?>
                <table class="wp-list-table widefat fixed striped">
                    <thead>
                        <tr>
                            <th style="width: 30px;"><input type="checkbox" id="select-all-titles"></th>
                            <th>Başlık</th>
                            <th>Yazılar</th>
                            <th>İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($duplicate_titles as $dup) : ?>
                            <tr>
                                <td><input type="checkbox" name="duplicate_groups[]" value="<?php echo esc_attr($dup->ids); ?>"></td>
                                <td><?php echo esc_html($dup->post_title); ?></td>
                                <td>
                                    <?php foreach (explode(',', $dup->ids) as $id) : ?>
                                        <a href="<?php echo get_permalink($id); ?>" target="_blank" class="post-id-link">
                                            #<?php echo $id; ?>
                                        </a>
                                    <?php endforeach; ?>
                                </td>
                                <td>
                                    <a href="<?php echo admin_url('edit.php?post__in=' . $dup->ids); ?>" class="button">Yönet</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else : ?>
                <p>Sonuç bulunamadı.</p>
            <?php endif; ?>

            <!-- Aynı İçerikler -->
            <h2>Aynı İçerikli Yazılar</h2>
            <?php if (!empty($duplicate_contents)) : ?>
                <table class="wp-list-table widefat fixed striped">
                    <thead>
                        <tr>
                            <th style="width: 30px;"><input type="checkbox" id="select-all-contents"></th>
                            <th>Yazılar</th>
                            <th>İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($duplicate_contents as $dup) : ?>
                            <tr>
                                <td><input type="checkbox" name="duplicate_groups[]" value="<?php echo esc_attr($dup->ids); ?>"></td>
                                <td>
                                    <?php foreach (explode(',', $dup->ids) as $id) : ?>
                                        <a href="<?php echo get_permalink($id); ?>" target="_blank" class="post-id-link">
                                            #<?php echo $id; ?>
                                        </a>
                                    <?php endforeach; ?>
                                </td>
                                <td>
                                    <a href="<?php echo admin_url('edit.php?post__in=' . $dup->ids); ?>" class="button">Yönet</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            <?php else : ?>
                <p>Sonuç bulunamadı.</p>
            <?php endif; ?>
        </form>
    </div>
    <?php
}

// CSS ve JS
add_action('admin_head', 'adcc_admin_assets');
function adcc_admin_assets() {
    echo '<style>
        .adcc-action-bar { display: flex; justify-content: space-between; margin: 20px 0; }
        .adcc-search-box { display: flex; gap: 5px; }
        .button-danger { background: #dc3232; border-color: #dc3232; color: white !important; }
        .post-id-link { margin-right: 5px; }
    </style>';
    
    echo '<script>
        jQuery(document).ready(function($) {
            $("#select-all-titles, #select-all-contents").click(function() {
                let table = $(this).closest("table");
                table.find("input[type=checkbox]").prop("checked", this.checked);
            });
        });
    </script>';
}
Cevapla