wp-rules.php aktualisiert
This commit is contained in:
85
wp-rules.php
85
wp-rules.php
@@ -2,13 +2,13 @@
|
||||
/**
|
||||
* Plugin Name: WP Rules
|
||||
* Description: Erstellt einen anpassbaren Regelbereich mit Tabs, Shortcode [meine_regeln] sowie Styling- und Import/Export-Funktionen.
|
||||
* Version: 1.0
|
||||
* Version: 1.1
|
||||
* Author: M_Viper
|
||||
* Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-regel-plugin/releases
|
||||
* Author URI: https://m-viper.de
|
||||
* Tags: rules, tabs, shortcode, settings, admin, frontend, styling, import-export, responsive, accessibility
|
||||
* Requires at least: 6.7.2
|
||||
* Tested up to: 6.7.2
|
||||
* Requires at least: 6.8.3
|
||||
* Tested up to: 6.8.3
|
||||
* Requires PHP: 7.4
|
||||
* License: GPL2
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
@@ -24,12 +24,14 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
// 1. Backend-Menüpunkt hinzufügen
|
||||
function mrp_add_admin_menu() {
|
||||
add_options_page(
|
||||
add_menu_page(
|
||||
'Regeln-Plugin Einstellungen',
|
||||
'Regeln-Plugin',
|
||||
'WP Rules',
|
||||
'manage_options',
|
||||
'mein-regel-plugin',
|
||||
'mrp_options_page_html'
|
||||
'mrp_options_page_html',
|
||||
'dashicons-admin-generic',
|
||||
25
|
||||
);
|
||||
}
|
||||
add_action('admin_menu', 'mrp_add_admin_menu');
|
||||
@@ -61,6 +63,8 @@ function mrp_settings_init() {
|
||||
add_settings_section('mrp_advanced_section', 'Erweiterte Funktionen', 'mrp_advanced_section_callback', 'mrp_plugin_page');
|
||||
add_settings_field('mrp_enable_animations', 'Animationen', 'mrp_enable_animations_render', 'mrp_plugin_page', 'mrp_advanced_section');
|
||||
add_settings_field('mrp_enable_drag_drop', 'Sortierung', 'mrp_enable_drag_drop_render', 'mrp_plugin_page', 'mrp_advanced_section');
|
||||
// NEU: Einstellungsfeld zum Anzeigen/Ausblenden des "Zuletzt aktualisiert"-Datums
|
||||
add_settings_field('mrp_show_last_updated', 'Anzeige "Zuletzt aktualisiert"', 'mrp_show_last_updated_render', 'mrp_plugin_page', 'mrp_advanced_section');
|
||||
}
|
||||
add_action('admin_init', 'mrp_settings_init');
|
||||
|
||||
@@ -70,19 +74,23 @@ function mrp_rules_section_callback() { echo 'Erstellen und verwalten Sie hier I
|
||||
function mrp_style_section_callback() { echo 'Passen Sie das Erscheinungsbild der Regeln im Frontend an. Änderungen werden sofort angewendet.'; }
|
||||
function mrp_advanced_section_callback() { echo 'Aktivieren oder deaktivieren Sie hier erweiterte Funktionen des Plugins.'; }
|
||||
|
||||
// NEU: Render-Funktionen für erweiterte Funktionen
|
||||
// KORRIGIERT: Render-Funktionen für erweiterte Funktionen
|
||||
function mrp_enable_animations_render() {
|
||||
$options = get_option('mrp_settings');
|
||||
$enabled = isset($options['enable_animations']) ? $options['enable_animations'] : '1';
|
||||
$enabled = ($options === false || !is_array($options)) ? '1' : (isset($options['enable_animations']) ? $options['enable_animations'] : '0');
|
||||
echo '<label><input type="checkbox" name="mrp_settings[enable_animations]" value="1" ' . checked(1, $enabled, false) . ' /> Sanfte Animationen für das Auf- und Zuklappen der Regeln aktivieren.</label>';
|
||||
}
|
||||
function mrp_enable_drag_drop_render() {
|
||||
$options = get_option('mrp_settings');
|
||||
$enabled = isset($options['enable_drag_drop']) ? $options['enable_drag_drop'] : '1';
|
||||
$enabled = ($options === false || !is_array($options)) ? '1' : (isset($options['enable_drag_drop']) ? $options['enable_drag_drop'] : '0');
|
||||
echo '<label><input type="checkbox" name="mrp_settings[enable_drag_drop]" value="1" ' . checked(1, $enabled, false) . ' /> Drag-and-Drop zum Sortieren von Tabs und Regeln im Backend aktivieren.</label>';
|
||||
}
|
||||
function mrp_show_last_updated_render() {
|
||||
$options = get_option('mrp_settings');
|
||||
$is_checked = ($options === false || !is_array($options)) ? '1' : (isset($options['show_last_updated']) ? $options['show_last_updated'] : '0');
|
||||
echo '<label><input type="checkbox" name="mrp_settings[show_last_updated]" value="1" ' . checked(1, $is_checked, false) . ' "Zuletzt aktualisiert"-Datum im Frontend anzeigen</label>';
|
||||
}
|
||||
|
||||
// Render-Funktion für die Checkbox des Willkommens-Tabs
|
||||
function mrp_show_welcome_tab_render() {
|
||||
$options = get_option('mrp_settings');
|
||||
if ($options === false || !is_array($options)) {
|
||||
@@ -96,7 +104,18 @@ function mrp_show_welcome_tab_render() {
|
||||
// Render-Funktion für den Willkommens-Tab
|
||||
function mrp_welcome_tab_render() {
|
||||
$options = get_option('mrp_settings');
|
||||
$welcome_content = isset($options['welcome_tab_content']) ? $options['welcome_tab_content'] : '';
|
||||
|
||||
// NEU: Standard-Willkommenstext als Vorlage
|
||||
$default_welcome_text = "Willkommen in unserer Community! 🎉
|
||||
|
||||
Es freut uns riesig, dass du den Weg zu uns gefunden hast. Damit alle hier eine tolle Zeit haben, haben wir einige einfache Regeln aufgestellt. Sie sind kein strenges Gesetz, sondern eher eine gemeinsame Vereinbarung, wie wir miteinander umgehen wollen – mit Respekt, Fairness und einer guten Portion Spaß.
|
||||
|
||||
Nimm dir einen Moment Zeit, sie durchzulesen. Solltest du Fragen haben, zögere nicht, ein Mitglied unseres Teams oder einen Moderator anzusprechen.
|
||||
|
||||
Wir wünschen dir eine fantastische Zeit hier!";
|
||||
|
||||
// Wenn noch kein Inhalt gespeichert ist, wird die Vorlage verwendet
|
||||
$welcome_content = isset($options['welcome_tab_content']) ? $options['welcome_tab_content'] : $default_welcome_text;
|
||||
|
||||
echo '<br>'; // Abstand zur Checkbox
|
||||
|
||||
@@ -168,8 +187,8 @@ function mrp_options_page_html() {
|
||||
// Lade Einstellungen für die Live-Vorschau
|
||||
$options = get_option('mrp_settings');
|
||||
|
||||
// Lade jQuery UI Sortable, falls Drag-and-Drop aktiv ist
|
||||
$enable_drag_drop = isset($options['enable_drag_drop']) ? $options['enable_drag_drop'] : '1';
|
||||
// KORRIGIERT: Standardwert für Drag-and-Drop auf '0' (inaktiv) gesetzt
|
||||
$enable_drag_drop = isset($options['enable_drag_drop']) ? $options['enable_drag_drop'] : '0';
|
||||
if ($enable_drag_drop === '1') {
|
||||
wp_enqueue_script('jquery-ui-sortable');
|
||||
}
|
||||
@@ -181,7 +200,6 @@ function mrp_options_page_html() {
|
||||
<form action="options.php" method="post" id="mrp-settings-form">
|
||||
<?php settings_fields('mrp_plugin_page'); ?>
|
||||
|
||||
<!-- NEU: Container für nebeneinander liegende Boxen -->
|
||||
<div class="mrp-two-column-container">
|
||||
<div class="mrp-column">
|
||||
<div class="postbox">
|
||||
@@ -562,6 +580,15 @@ function mrp_ajax_import_settings() {
|
||||
}
|
||||
}
|
||||
|
||||
// NEU: Funktion zum Speichern des letzten Aktualisierungsdatums
|
||||
add_filter('pre_update_option_mrp_settings', 'mrp_add_last_updated_timestamp', 10, 2);
|
||||
|
||||
function mrp_add_last_updated_timestamp($new_value, $old_value) {
|
||||
// Fügt den aktuellen Zeitstempel hinzu, bevor die Option gespeichert wird
|
||||
// Wir verwenden current_time('timestamp'), um die WordPress-Zeitzone zu berücksichtigen
|
||||
$new_value['last_updated'] = current_time('timestamp');
|
||||
return $new_value;
|
||||
}
|
||||
|
||||
// 6. Shortcode für die Frontend-Anzeige
|
||||
function mrp_display_rules_shortcode($atts) {
|
||||
@@ -575,7 +602,11 @@ function mrp_display_rules_shortcode($atts) {
|
||||
$show_welcome_tab = isset($options['show_welcome_tab']);
|
||||
}
|
||||
|
||||
$enable_animations = isset($options['enable_animations']) ? $options['enable_animations'] : '1';
|
||||
// KORRIGIERT: Logik für die Checkbox "Zuletzt aktualisiert" (Standard ist jetzt '0')
|
||||
$show_last_updated = isset($options['show_last_updated']) ? $options['show_last_updated'] : '0';
|
||||
|
||||
// KORRIGIERT: Logik für die Checkbox "Animationen" (Standard ist jetzt '0')
|
||||
$enable_animations = isset($options['enable_animations']) ? $options['enable_animations'] : '0';
|
||||
|
||||
if (empty($tabs) && !$show_welcome_tab) {
|
||||
return '<p style="text-align:center; padding: 40px; color: #666;">Keine Regeln wurden im Backend konfiguriert.</p>';
|
||||
@@ -592,6 +623,15 @@ function mrp_display_rules_shortcode($atts) {
|
||||
|
||||
// Beginne die Ausgabepufferung
|
||||
ob_start();
|
||||
|
||||
// NEU: Datum der letzten Aktualisierung abrufen und formatieren, NUR wenn die Option aktiv ist
|
||||
$last_updated_html = '';
|
||||
if ($show_last_updated && isset($options['last_updated']) && is_numeric($options['last_updated'])) {
|
||||
$last_updated_timestamp = $options['last_updated'];
|
||||
// Verwendet das im WordPress-Backend eingestellte Datumsformat
|
||||
$formatted_date = date_i18n(get_option('date_format'), $last_updated_timestamp);
|
||||
$last_updated_html = '<p class="mrp-last-updated">Zuletzt aktualisiert am: ' . esc_html($formatted_date) . '</p>';
|
||||
}
|
||||
?>
|
||||
<style id="mrp-custom-inline-styles">
|
||||
/* Dynamische Stile für die Tab-Titel */
|
||||
@@ -613,6 +653,17 @@ function mrp_display_rules_shortcode($atts) {
|
||||
<?php if ($show_welcome_tab): ?>
|
||||
#tab-welcome { background-color: <?php echo esc_attr(hex_to_rgba($options['welcome_tab_bg_color'] ?? '#f0f0f0', 0.4)); ?> !important; padding: 15px; border-radius: 5px; }
|
||||
<?php endif; ?>
|
||||
|
||||
.mrp-last-updated {
|
||||
text-align: left;
|
||||
padding-left: 550px;
|
||||
font-size: 0.9em;
|
||||
color: #aaaaaacc;
|
||||
margin-top: 20px;
|
||||
font-style: italic;
|
||||
/* Gravur-Effekt (stark) */
|
||||
text-shadow: 1px 1px 2px rgba(255, 255, 255, 0.9), -1px -1px 2px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
</style>
|
||||
<div class="regel-plugin-container">
|
||||
<div class="regel-tabs-nav">
|
||||
@@ -665,6 +716,10 @@ function mrp_display_rules_shortcode($atts) {
|
||||
</div>
|
||||
<?php $first_panel = false; endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
// GEÄNDERT: Das Datum jetzt ganz unten ausgeben
|
||||
echo $last_updated_html;
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
|
||||
Reference in New Issue
Block a user