/**
* Manuelles Aktualisieren des News-Tabs für alle Profile
* Diese Funktion kann in der Admin-Oberfläche aufgerufen werden
*/
public function update_all_news_tabs() {
global $wpdb;
// Fehlerbehandlung aktivieren
try {
// Alle Profile abrufen
$profiles = get_posts(array(
'post_type' => 'vip_profile',
'numberposts' => -1,
'post_status' => 'publish'
));
if (empty($profiles)) {
error_log('VIP Database: Keine Profile gefunden zum Aktualisieren.');
return 0;
}
$updated_count = 0;
// Frontend-Klasse instanziieren für Fallback-Inhalte
if (!class_exists('VIP_Database_Frontend')) {
require_once VIP_DB_PLUGIN_DIR . 'includes/class-vip-database-frontend.php';
}
$frontend = new VIP_Database_Frontend();
foreach ($profiles as $profile) {
$profile_id = $profile->ID;
if (empty($profile_id)) {
continue;
}
// Aktuellen News-Inhalt abrufen
$content = $this->get_profile_content($profile_id, 'news');
// Profil-Daten abrufen
$first_name = get_post_meta($profile_id, '_vip_first_name', true);
$last_name = get_post_meta($profile_id, '_vip_last_name', true);
$full_name = trim($first_name . ' ' . $last_name);
if (empty($full_name)) {
$full_name = get_the_title($profile_id);
}
// Kategorie abrufen
$categories = wp_get_post_terms($profile_id, 'vip_category');
$category = !empty($categories) && !is_wp_error($categories) ? $categories[0]->name : '';
if (!empty($content)) {
// Überprüfen, ob der Inhalt bereits HTML-Formatierung hat
if (strpos($content, '" .="" sprintf(__('aktuelle="" neuigkeiten="" über="" %s',="" 'vip-database'),="" $full_name)="" '<="" h2="">' . $content;
}
// Stellen Sie sicher, dass der Text in Absätze gegliedert ist
if (strpos($content, '
') === false) {
$content = wpautop($content);
}
} else {
// Wenn kein Inhalt vorhanden ist, Fallback-Inhalt erstellen
if (method_exists($frontend, 'generate_fallback_content')) {
$content = $frontend->generate_fallback_content($full_name, $category, 'news');
} else {
// Einfacher Fallback, falls die Methode nicht existiert
$current_date = date('d.m.Y');
$content = "
Aktuelle Neuigkeiten zu {$full_name}
{$current_date}
Aktuelle Neuigkeiten zu {$full_name} werden in Kürze hier veröffentlicht.
";
}
}
// Speichern Sie den formatierten Inhalt
$save_result = $this->save_profile_content($profile_id, 'news', $content);
if ($save_result) {
$updated_count++;
}
}
return $updated_count;
} catch (Exception $e) {
error_log('VIP Database Error: ' . $e->getMessage());
return 0;
}
}