pausera/includes/admin-ui.php

146 lines
6.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/************************************************************************************
* Pausera Admin UI renderer (hook: pausera_render_ui)
************************************************************************************/
if (!defined('ABSPATH')) exit;
add_action('pausera_render_ui', function () {
$settings = get_option('pausera_settings', []);
$enabled = !empty($settings['enable_maintenance']);
$excluded_ips = isset($settings['excluded_ips']) ? implode(',', (array) $settings['excluded_ips']) : '';
$redirect_url = $settings['redirect_url'] ?? '/maintenance';
$excluded_roles = (array)($settings['excluded_roles'] ?? []);
$allowed_users = (array)($settings['allowed_users'] ?? []);
$excluded_slugs = (array)($settings['excluded_slugs'] ?? []);
$plugin_data = function_exists('get_plugin_data') ? get_plugin_data(PAUSERA_PATH . 'pausera.php') : ['Version' => '—'];
global $wp_roles;
$all_users = get_users(['fields' => ['user_login']]);
$usernames = array_map(function ($u) {
return $u->user_login;
}, $all_users);
?>
<div class="pausera-status-bar">
Aktueller Status: <?php echo $enabled ? 'Wartungsmodus AKTIV' : 'Deaktiviert'; ?>
</div>
<div class="pausera-header">
<div class="pausera-title">Pausera</div>
</div>
<?php if (isset($_GET['settings-updated']) && $_GET['settings-updated'] === 'true') : ?>
<div class="pausera-notice success">
<?php echo esc_html(__('Settings saved successfully.', 'pausera')); ?>
</div>
<?php endif; ?>
<div class="pausera-wrap">
<div class="formular">
<form method="post" action="options.php" id="pausera-form">
<?php settings_fields('pausera_group'); ?>
<div class="pausera-card toggle-box <?php echo $enabled ? 'active' : ''; ?>" id="maintenance-toggle">
<input type="checkbox" id="maintenance_toggle_input" name="pausera_settings[enable_maintenance]" value="1" <?php checked($enabled); ?> />
<label for="maintenance_toggle_input">
<strong class="pausera-toggle-label" data-label-on="Deaktivieren" data-label-off="Aktivieren">
<?php echo $enabled ? 'Deaktivieren' : 'Aktivieren'; ?>
</strong>
</label>
</div>
<div class="pausera-card">
<h3>Weiterleitungsseite</h3>
<label>Seite auswählen</label>
<select name="pausera_settings[redirect_url]" class="acf-style-select">
<?php foreach (get_pages() as $page) :
$slug = '/' . basename(get_permalink($page->ID));
$selected = selected($redirect_url, $slug, false);
echo "<option value='{$slug}' {$selected}>" . esc_html($page->post_title) . "</option>";
endforeach; ?>
</select>
</div>
<div class="pausera-card">
<h3>Erlaubte Benutzer</h3>
<label>Mehrere Benutzernamen mit Komma trennen</label>
<select name="pausera_settings[allowed_users][]" multiple class="acf-style-select">
<?php foreach ($usernames as $username) :
$selected = in_array($username, $allowed_users, true) ? 'selected' : '';
echo "<option value='" . esc_attr($username) . "' {$selected}>" . esc_html($username) . "</option>";
endforeach; ?>
</select>
</div>
<div class="pausera-card">
<h3>Benutzerrollen</h3>
<label>Mehrfachauswahl möglich</label>
<select name="pausera_settings[excluded_roles][]" multiple class="acf-style-select">
<?php foreach ($wp_roles->roles as $key => $role) :
$selected = in_array($key, $excluded_roles, true) ? 'selected' : '';
echo "<option value='" . esc_attr($key) . "' {$selected}>" . esc_html($role['name']) . "</option>";
endforeach; ?>
</select>
</div>
<div class="pausera-card">
<h3>Ausgeschlossene Seiten (Slugs/Paths)</h3>
<label>Diese Seiten bleiben im Wartungsmodus erreichbar.</label>
<select name="pausera_settings[excluded_slugs][]" multiple class="acf-style-select">
<?php
$pages = get_pages();
foreach ($pages as $page) {
$slug = '/' . basename(get_permalink($page->ID));
$slug = trim($slug, '/');
$selected = in_array($slug, $excluded_slugs, true) ? 'selected' : '';
echo "<option value='" . esc_attr($slug) . "' {$selected}>" . esc_html($page->post_title) . " ({$slug})</option>";
}
?>
</select>
</div>
<div class="pausera-card">
<h3>Ausgeschlossene IP-Adressen</h3>
<label>Mehrere IPs mit Komma trennen</label>
<input type="text" name="pausera_settings[excluded_ips]" value="<?php echo esc_attr($excluded_ips); ?>" placeholder="127.0.0.1, 88.99.99.99">
</div>
<div class="pausera-buttons">
<button type="submit" class="pausera-save">Speichern</button>
</div>
<div class="pausera-confirm-overlay" id="pausera-confirm-box">
<div class="pausera-confirm-dialog">
<h3>Einstellungen speichern?</h3>
<p>Bitte bestätigen Sie, dass Sie die Änderungen speichern möchten.</p>
<div class="pausera-buttons">
<button type="button" id="confirm-save" class="pausera-save">Ja, speichern</button>
<button type="button" id="cancel-save" class="pausera-reset">Abbrechen</button>
</div>
</div>
</div>
</form>
</div>
<div class="pausera-sidebar">
<h4>Plugin-Informationen</h4>
<ul>
<li><strong>Version:</strong> <?php echo esc_html($plugin_data['Version']); ?></li>
<li><strong>Autor:</strong> Ihr Name</li>
<li><strong>Website:</strong> <a href="https://example.com" target="_blank" rel="noopener">example.com</a></li>
</ul>
<h4>Plugin-Links</h4>
<ul>
<li><a href="https://example.com/docs" target="_blank" rel="noopener">📄 Dokumentation</a></li>
<li><a href="mailto:support@example.com">Kontaktieren Sie uns</a></li>
</ul>
</div>
</div>
<?php });