| |
| <?php
|
| <?php
|
| if (!defined('ABSPATH')) {
|
| exit;
|
| }
|
|
|
| if (!function_exists('pn_fc_greek_slugify_repair')) {
|
| function pn_fc_greek_slugify_repair($text) {
|
| $text = trim((string) $text);
|
|
|
| if ($text === '') {
|
| return '';
|
| }
|
|
|
| $map = array(
|
| 'Α'=>'a','Ά'=>'a','Β'=>'v','Γ'=>'g','Δ'=>'d','Ε'=>'e','Έ'=>'e','Ζ'=>'z',
|
| 'Η'=>'i','Ή'=>'i','Θ'=>'th','Ι'=>'i','Ί'=>'i','Ϊ'=>'i','Κ'=>'k','Λ'=>'l',
|
| 'Μ'=>'m','Ν'=>'n','Ξ'=>'x','Ο'=>'o','Ό'=>'o','Π'=>'p','Ρ'=>'r','Σ'=>'s',
|
| 'Τ'=>'t','Υ'=>'y','Ύ'=>'y','Ϋ'=>'y','Φ'=>'f','Χ'=>'ch','Ψ'=>'ps','Ω'=>'o','Ώ'=>'o',
|
|
|
| 'α'=>'a','ά'=>'a','β'=>'v','γ'=>'g','δ'=>'d','ε'=>'e','έ'=>'e','ζ'=>'z',
|
| 'η'=>'i','ή'=>'i','θ'=>'th','ι'=>'i','ί'=>'i','ϊ'=>'i','ΐ'=>'i','κ'=>'k',
|
| 'λ'=>'l','μ'=>'m','ν'=>'n','ξ'=>'x','ο'=>'o','ό'=>'o','π'=>'p','ρ'=>'r',
|
| 'σ'=>'s','ς'=>'s','τ'=>'t','υ'=>'y','ύ'=>'y','ϋ'=>'y','ΰ'=>'y','φ'=>'f',
|
| 'χ'=>'ch','ψ'=>'ps','ω'=>'o','ώ'=>'o',
|
| );
|
|
|
| $text = strtr($text, $map);
|
|
|
|
|
| $text = preg_replace('/(?<=\b[a-zA-Z])\.(?=[a-zA-Z]\b)/', '', $text);
|
| $text = str_replace('.', ' ', $text);
|
|
|
| $text = strtolower($text);
|
| $text = preg_replace('/[^a-z0-9\s_-]+/', ' ', $text);
|
| $text = preg_replace('/[\s_-]+/', '-', $text);
|
| $text = trim($text, '-');
|
|
|
| return $text;
|
| }
|
| }
|
|
|
| add_action('admin_init', function () {
|
| if (!current_user_can('manage_options')) {
|
| return;
|
| }
|
|
|
| if (empty($_GET['repair_fluent_feed_slugs']) || $_GET['repair_fluent_feed_slugs'] !== '1') {
|
| return;
|
| }
|
|
|
| if (!class_exists('\FluentCommunity\App\Models\Feed')) {
|
| wp_die('FluentCommunity Feed model not found.');
|
| }
|
|
|
| $feeds = \FluentCommunity\App\Models\Feed::where('slug', 'like', 'post-%')->get();
|
|
|
| if (!$feeds || !$feeds->count()) {
|
| wp_die('No feeds found with slug like post-%.');
|
| }
|
|
|
| $updated = 0;
|
| $skipped = 0;
|
| $log = array();
|
|
|
| foreach ($feeds as $feed) {
|
| $source = '';
|
|
|
| if (!empty($feed->title)) {
|
| $source = $feed->title;
|
| } elseif (!empty($feed->message)) {
|
| $source = wp_strip_all_tags($feed->message);
|
| }
|
|
|
| $slug = pn_fc_greek_slugify_repair($source);
|
|
|
| if (!$slug) {
|
| $skipped++;
|
| $log[] = 'Skipped feed ID ' . $feed->id . ' (empty slug source)';
|
| continue;
|
| }
|
|
|
| $base_slug = $slug;
|
| $unique_slug = $base_slug;
|
| $count = 1;
|
|
|
| while (
|
| \FluentCommunity\App\Models\Feed::where('slug', $unique_slug)
|
| ->where('id', '!=', $feed->id)
|
| ->exists()
|
| ) {
|
| $unique_slug = $base_slug . '-' . $count;
|
| $count++;
|
| }
|
|
|
| try {
|
|
|
| \FluentCommunity\App\Models\Feed::where('id', $feed->id)->update([
|
| 'slug' => $unique_slug
|
| ]);
|
|
|
| $updated++;
|
| $log[] = 'Updated feed ID ' . $feed->id . ' => ' . $unique_slug;
|
| } catch (\Throwable $e) {
|
| $skipped++;
|
| $log[] = 'Failed feed ID ' . $feed->id . ': ' . $e->getMessage();
|
| }
|
| }
|
|
|
| echo '<div style="padding:20px;font-family:Arial,sans-serif;">';
|
| echo '<h2>FluentCommunity Feed Slug Repair</h2>';
|
| echo '<p><strong>Updated:</strong> ' . intval($updated) . '</p>';
|
| echo '<p><strong>Skipped/Failed:</strong> ' . intval($skipped) . '</p>';
|
| echo '<hr>';
|
| echo '<pre style="white-space:pre-wrap;">' . esc_html(implode("\n", $log)) . '</pre>';
|
| echo '</div>';
|
| exit;
|
| });
|
| |
| |
Comments