Update from Git Manager GUI
This commit is contained in:
@@ -54,6 +54,13 @@ if ( ! function_exists('wbf_get_settings') ) {
|
||||
'rules_content' => "**1. Respektvoller Umgang**\nBehandle alle Mitglieder freundlich und respektvoll. Beleidigungen, Mobbing und Diskriminierung sind nicht toleriert.\n\n**2. Keine Spam-Inhalte**\nWerbung, Spam und irrelevante Links sind verboten.\n\n**3. Keine illegalen Inhalte**\nJegliche Inhalte, die gegen geltendes Recht verstoßen, sind streng verboten.\n\n**4. Themenrelevanz**\nBeiträge sollten zur jeweiligen Kategorie passen.\n\n**5. Urheberrecht**\nVeröffentliche keine Inhalte, an denen du keine Rechte besitzt.\n\n**6. Datenschutz**\nTeile keine persönlichen Daten anderer Personen ohne deren Zustimmung.\n\n**7. Moderations-Entscheidungen**\nEntscheidungen der Moderatoren sind zu respektieren. Bei Fragen wende dich direkt ans Team.\n\nVerstöße können zur Verwarnung oder dauerhaften Sperrung führen.",
|
||||
// Ignore/Block-System: Rollen die nicht geblockt werden können (kommagetrennte Schlüssel)
|
||||
'ignore_blocked_roles' => 'superadmin,admin,moderator',
|
||||
// Discord-Integration
|
||||
'discord_bot_token' => '',
|
||||
'discord_guild_id' => '',
|
||||
'discord_client_id' => '',
|
||||
'discord_client_secret' => '',
|
||||
'discord_role_sync' => '0', // Rollen-Sync aktiviert?
|
||||
'discord_role_map' => '', // JSON: {"discord_role_id":"forum_role_key"}
|
||||
];
|
||||
|
||||
$saved = get_option( 'wbf_settings', [] );
|
||||
@@ -130,6 +137,27 @@ function wbf_admin_settings() {
|
||||
// rules_content separat (nicht in $fields, da textarea mit eigener Behandlung)
|
||||
$settings['rules_content'] = sanitize_textarea_field( $_POST['rules_content'] ?? '' );
|
||||
|
||||
// Discord-Einstellungen gesondert speichern (sensitiv — niemals in wbf_settings öffentlich)
|
||||
$discord_fields = ['discord_bot_token', 'discord_guild_id', 'discord_client_id', 'discord_client_secret'];
|
||||
foreach ( $discord_fields as $df ) {
|
||||
$settings[$df] = sanitize_text_field( $_POST[$df] ?? '' );
|
||||
}
|
||||
$settings['discord_role_sync'] = isset($_POST['discord_role_sync']) && $_POST['discord_role_sync'] === '1' ? '1' : '0';
|
||||
|
||||
// Discord-Rollen-Map: Array von discord_role_id => forum_role_key
|
||||
$role_map = [];
|
||||
$dc_ids = array_map('sanitize_text_field', (array)($_POST['discord_role_id'] ?? []));
|
||||
$fr_keys = array_map('sanitize_key', (array)($_POST['discord_forum_role'] ?? []));
|
||||
$valid_roles = array_keys(WBF_Roles::get_all());
|
||||
foreach ( $dc_ids as $i => $dc_id ) {
|
||||
$dc_id = trim($dc_id);
|
||||
$fr_key = $fr_keys[$i] ?? '';
|
||||
if ( $dc_id !== '' && in_array($fr_key, $valid_roles, true) ) {
|
||||
$role_map[$dc_id] = $fr_key;
|
||||
}
|
||||
}
|
||||
$settings['discord_role_map'] = json_encode($role_map);
|
||||
|
||||
// Checkbox-Felder explizit als '0' speichern wenn nicht angehakt,
|
||||
// damit array_filter(...,'strlen') sie nicht wegwirft und der Default '1' greift.
|
||||
$checkbox_fields = ['maintenance_mode', 'rules_enabled', 'rules_accept_required'];
|
||||
@@ -150,6 +178,12 @@ function wbf_admin_settings() {
|
||||
$settings['ignore_blocked_roles'] = implode( ',', $checked_roles );
|
||||
|
||||
update_option( 'wbf_settings', $settings );
|
||||
|
||||
// Superadmin WP-User-ID separat speichern (außerhalb von wbf_settings)
|
||||
$sa_wp_id = (int) ( $_POST['superadmin_wp_id'] ?? 1 );
|
||||
if ( $sa_wp_id < 1 ) $sa_wp_id = 1;
|
||||
update_option( 'wbf_superadmin_wp_id', $sa_wp_id );
|
||||
|
||||
echo '<div class="notice notice-success is-dismissible"><p>✅ Einstellungen gespeichert!</p></div>';
|
||||
}
|
||||
|
||||
@@ -251,6 +285,40 @@ function wbf_admin_settings() {
|
||||
🔒 Sicherheit
|
||||
</h2>
|
||||
<table class="form-table" role="presentation">
|
||||
|
||||
<!-- ── Superadmin WP-User-ID ─────────────────── -->
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wbf_superadmin_wp_id">Superadmin WordPress-User-ID</label>
|
||||
</th>
|
||||
<td>
|
||||
<?php
|
||||
$sa_id = (int) get_option( 'wbf_superadmin_wp_id', 1 );
|
||||
$sa_wpuser = get_userdata( $sa_id );
|
||||
?>
|
||||
<input type="number" id="wbf_superadmin_wp_id" name="superadmin_wp_id"
|
||||
value="<?php echo $sa_id; ?>"
|
||||
min="1" step="1"
|
||||
style="width:80px">
|
||||
<?php if ( $sa_wpuser ) : ?>
|
||||
<span style="margin-left:10px;color:#16a34a;font-weight:600">
|
||||
✅ <?php echo esc_html( $sa_wpuser->display_name ); ?>
|
||||
<<?php echo esc_html( $sa_wpuser->user_email ); ?>>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span style="margin-left:10px;color:#dc2626;font-weight:600">
|
||||
⚠️ Kein WordPress-User mit dieser ID gefunden!
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
<p class="description">
|
||||
Nur dieser WordPress-User erhält automatisch die Forum-Rolle <strong>Superadmin</strong>
|
||||
und kann sie nicht verlieren. Alle anderen WordPress-Admins können normale Forum-Rollen
|
||||
haben und im Mitglieder-Bereich frei zugewiesen werden.<br>
|
||||
<em>Standard: 1 (erster bei der WP-Installation angelegter User)</em>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="wbf_auto_logout_minutes">Auto-Logout nach Inaktivität</label>
|
||||
@@ -499,6 +567,170 @@ function wbf_admin_settings() {
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
<!-- ══════════════════════════════════════════════════════════
|
||||
DISCORD-INTEGRATION
|
||||
══════════════════════════════════════════════════════════ -->
|
||||
<h2 style="border-bottom:1px solid #ddd;padding-bottom:.4rem;margin-top:2rem">
|
||||
<span style="color:#5865f2">🎮</span> Discord-Integration
|
||||
</h2>
|
||||
<p class="description" style="margin-bottom:1rem">
|
||||
Bot-Token und Guild-ID findest du im <a href="https://discord.com/developers/applications" target="_blank">Discord Developer Portal</a>.
|
||||
Der Bot muss Mitglied deines Servers sein und die Berechtigung <strong>Direct Messages lesen/senden</strong> sowie
|
||||
<strong>Server-Mitglieder verwalten</strong> besitzen.
|
||||
</p>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><label for="wbf_discord_bot_token">Bot-Token</label></th>
|
||||
<td>
|
||||
<input type="password" id="wbf_discord_bot_token" name="discord_bot_token"
|
||||
value="<?php echo esc_attr($s['discord_bot_token']); ?>"
|
||||
class="regular-text" autocomplete="off" placeholder="Bot-Token aus dem Developer Portal">
|
||||
<p class="description">Niemals öffentlich teilen! Wird verschlüsselt in der Datenbank gespeichert.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="wbf_discord_guild_id">Server-ID (Guild ID)</label></th>
|
||||
<td>
|
||||
<input type="text" id="wbf_discord_guild_id" name="discord_guild_id"
|
||||
value="<?php echo esc_attr($s['discord_guild_id']); ?>"
|
||||
class="regular-text" placeholder="z. B. 123456789012345678">
|
||||
<p class="description">Rechtsklick auf deinen Server → ID kopieren (Entwicklermodus muss aktiv sein).</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="wbf_discord_client_id">Client ID (optional)</label></th>
|
||||
<td>
|
||||
<input type="text" id="wbf_discord_client_id" name="discord_client_id"
|
||||
value="<?php echo esc_attr($s['discord_client_id']); ?>"
|
||||
class="regular-text" placeholder="Application ID">
|
||||
<p class="description">Für zukünftige OAuth2-Unterstützung. Aktuell optional.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="wbf_discord_client_secret">Client Secret (optional)</label></th>
|
||||
<td>
|
||||
<input type="password" id="wbf_discord_client_secret" name="discord_client_secret"
|
||||
value="<?php echo esc_attr($s['discord_client_secret']); ?>"
|
||||
class="regular-text" autocomplete="off" placeholder="Client Secret">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">Rollen-Sync aktivieren</th>
|
||||
<td>
|
||||
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
|
||||
<input type="checkbox" name="discord_role_sync" value="1"
|
||||
<?php checked('1', $s['discord_role_sync'] ?? '0'); ?>>
|
||||
Discord-Serverrollen automatisch auf Forum-Rollen mappen
|
||||
</label>
|
||||
<p class="description">
|
||||
Wenn aktiviert, wird bei jedem Login und stündlich per Cron die Discord-Rolle des Nutzers
|
||||
geprüft und die Forum-Rolle entsprechend der unten definierten Zuordnung aktualisiert.
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- Discord Rollen-Map -->
|
||||
<h3 style="margin-top:1.5rem">🔗 Discord-Rollen → Forum-Rollen Zuordnung</h3>
|
||||
<p class="description" style="margin-bottom:.75rem">
|
||||
Trage die Discord-Rollen-ID und die gewünschte Forum-Rolle ein.
|
||||
Mehrere Einträge werden der Reihe nach geprüft — der erste Treffer gewinnt.
|
||||
</p>
|
||||
<?php
|
||||
$role_map_raw = $s['discord_role_map'] ?? '{}';
|
||||
$role_map = json_decode($role_map_raw, true) ?: [];
|
||||
$forum_roles = WBF_Roles::get_sorted();
|
||||
// Sicherstellen dass mindestens eine leere Zeile zum Hinzufügen da ist
|
||||
if ( empty($role_map) ) $role_map[''] = '';
|
||||
?>
|
||||
<table class="widefat" id="wbf-discord-role-map" style="max-width:680px;margin-bottom:.75rem">
|
||||
<thead><tr>
|
||||
<th style="width:50%">Discord Rollen-ID</th>
|
||||
<th style="width:40%">Forum-Rolle</th>
|
||||
<th style="width:10%"></th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ( $role_map as $dc_id => $fr_key ) : ?>
|
||||
<tr class="wbf-role-map-row">
|
||||
<td><input type="text" name="discord_role_id[]"
|
||||
value="<?php echo esc_attr($dc_id); ?>"
|
||||
placeholder="Discord Rollen-ID"
|
||||
class="widefat" style="font-family:monospace"></td>
|
||||
<td>
|
||||
<select name="discord_forum_role[]" class="widefat">
|
||||
<option value="">— wählen —</option>
|
||||
<?php foreach ( $forum_roles as $rk => $role ) :
|
||||
if ( $rk === 'superadmin' ) continue; ?>
|
||||
<option value="<?php echo esc_attr($rk); ?>"
|
||||
<?php selected($rk, $fr_key); ?>>
|
||||
<?php echo esc_html($role['label']); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<td><button type="button" class="button button-small wbf-rm-role-row"
|
||||
style="color:#c00">✕</button></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<button type="button" class="button" id="wbf-add-role-row">+ Zeile hinzufügen</button>
|
||||
<script>
|
||||
(function(){
|
||||
document.getElementById('wbf-add-role-row').addEventListener('click', function(){
|
||||
var tbody = document.querySelector('#wbf-discord-role-map tbody');
|
||||
var row = document.querySelector('.wbf-role-map-row').cloneNode(true);
|
||||
row.querySelectorAll('input').forEach(function(i){i.value='';});
|
||||
row.querySelectorAll('select').forEach(function(s){s.selectedIndex=0;});
|
||||
tbody.appendChild(row);
|
||||
});
|
||||
document.addEventListener('click', function(e){
|
||||
if (e.target.classList.contains('wbf-rm-role-row')) {
|
||||
var rows = document.querySelectorAll('.wbf-role-map-row');
|
||||
if (rows.length > 1) e.target.closest('tr').remove();
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<!-- Test-Verbindung -->
|
||||
<div style="margin-top:1.25rem;padding:1rem;background:#f0f7ff;border:1px solid #c3dafe;border-radius:6px;max-width:680px">
|
||||
<strong>🔌 Verbindungstest</strong><br>
|
||||
<p style="margin:.4rem 0 .75rem;color:#374151;font-size:.9rem">
|
||||
Speichere zuerst die Einstellungen, dann klicke „Testen" um zu prüfen ob der Bot erreichbar ist.
|
||||
</p>
|
||||
<button type="button" class="button button-secondary" id="wbf-discord-test-btn">
|
||||
🔌 Discord-Verbindung testen
|
||||
</button>
|
||||
<span id="wbf-discord-test-result" style="margin-left:10px;font-weight:600"></span>
|
||||
</div>
|
||||
<script>
|
||||
document.getElementById('wbf-discord-test-btn').addEventListener('click', function(){
|
||||
var btn = this;
|
||||
var res = document.getElementById('wbf-discord-test-result');
|
||||
btn.disabled = true;
|
||||
res.textContent = '⏳ Teste…';
|
||||
fetch(ajaxurl, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type':'application/x-www-form-urlencoded'},
|
||||
body: 'action=wbf_discord_test&nonce=<?php echo wp_create_nonce("wbf_discord_test"); ?>'
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(function(d){
|
||||
if (d.success) {
|
||||
res.style.color = '#16a34a';
|
||||
res.textContent = '✅ ' + (d.data.message || 'Verbunden!');
|
||||
} else {
|
||||
res.style.color = '#dc2626';
|
||||
res.textContent = '❌ ' + ((d.data && d.data.message) || 'Fehler');
|
||||
}
|
||||
btn.disabled = false;
|
||||
})
|
||||
.catch(function(){ res.style.color='#dc2626'; res.textContent='❌ Netzwerkfehler'; btn.disabled=false; });
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php submit_button(
|
||||
'💾 Einstellungen speichern',
|
||||
'primary',
|
||||
@@ -506,7 +738,6 @@ function wbf_admin_settings() {
|
||||
true,
|
||||
[ 'style' => 'margin-top:1rem' ]
|
||||
); ?>
|
||||
</form>
|
||||
|
||||
<!-- ── Vorschau-Tabelle ──────────────────────────────── -->
|
||||
<hr style="margin-top:2.5rem">
|
||||
|
||||
Reference in New Issue
Block a user