Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
daa2723687 | |||
4505999060 | |||
e37fd6278a |
53
README.md
53
README.md
@ -1,2 +1,53 @@
|
||||
# WP-Multi-Kategorie
|
||||
WP Multi Kategorie ist ein Plugin für WordPress, mit dem du bestimmte Kategorien aus verschiedenen Bereichen deiner Website ausblenden kannst. Du kannst auswählen, welche Kategorien auf der Startseite, in Feeds, in Archiven und in Suchergebnissen ausgeblendet werden sollen.
|
||||
|
||||
**Funktionen:**
|
||||
|
||||
- Kategorien auf der Startseite ausblenden
|
||||
- Kategorien in Feeds ausblenden
|
||||
- Kategorien in Archiven ausblenden
|
||||
- Kategorien in Suchergebnissen ausblenden
|
||||
- Benutzerfreundliches Admin-Interface
|
||||
|
||||
## Installation
|
||||
|
||||
1. Lade das Plugin herunter und entpacke es.
|
||||
2. Lade den Ordner in das Verzeichnis `wp-content/plugins` deiner WordPress-Installation hoch.
|
||||
3. Gehe zu **Plugins > Installierte Plugins** in deinem WordPress-Adminbereich und aktiviere das Plugin "WP Multi Kategorie".
|
||||
4. Das Plugin benötigt das Plugin **WP Multi Toolkit**. Stelle sicher, dass es installiert und aktiv ist, da sonst dieses Plugin nicht funktioniert.
|
||||
|
||||
## Verwendung
|
||||
|
||||
Nach der Installation findest du das Plugin unter **Beiträge > Kategorie-Filter**. Dort kannst du die Kategorien auswählen, die du in den verschiedenen Bereichen deiner Website ausblenden möchtest (Startseite, Feeds, Archive, Suche).
|
||||
|
||||
## Abhängigkeiten
|
||||
|
||||
Dieses Plugin erfordert das Plugin **WP Multi Toolkit**, um korrekt zu funktionieren.
|
||||
|
||||
Falls **WP Multi Toolkit** nicht installiert oder aktiviert ist, wirst du eine Fehlermeldung im Adminbereich sehen, die dich dazu auffordert, es herunterzuladen und zu installieren.
|
||||
|
||||
## Funktionen und Optionen
|
||||
|
||||
- **Startseite:** Blende ausgewählte Kategorien auf der Startseite aus.
|
||||
- **Feeds:** Blende Kategorien in Feeds aus.
|
||||
- **Archive:** Blende Kategorien in Archivseiten aus.
|
||||
- **Suche:** Blende Kategorien in den Suchergebnissen aus.
|
||||
|
||||
## Screenshots
|
||||
|
||||
1. **Einstellungen des Plugins**
|
||||
Screenshot von der Admin-Seite zur Auswahl der auszublendenden Kategorien.
|
||||
|
||||
2. **Fehlermeldung bei fehlender Abhängigkeit**
|
||||
Screenshot der Admin-Fehlermeldung, wenn **WP Multi Toolkit** nicht aktiv ist.
|
||||
|
||||
## Deinstallation
|
||||
|
||||
Um das Plugin zu deinstallieren, gehe zu **Plugins > Installierte Plugins**, deaktiviere "WP Multi Kategorie" und lösche das Plugin anschließend.
|
||||
|
||||
## Lizenz
|
||||
|
||||
Dieses Plugin ist unter der [GPLv2 oder später](https://www.gnu.org/licenses/gpl-2.0.html) lizenziert.
|
||||
|
||||
## Unterstützen
|
||||
|
||||
Für Unterstützung oder bei Fragen besuche die [Support-Seite](https://git.viper.ipv64.net/M_Viper/WP-Multi-Kategorie) oder kontaktiere den Autor über die [Webseite von M_Viper](https://m-viper.de).
|
@ -1,140 +1,279 @@
|
||||
<?php
|
||||
/*
|
||||
* Plugin Name: WP Multi Kategorie
|
||||
* Plugin URI: https://git.viper.ipv64.net/M_Viper/wp-multi-kategorie
|
||||
* Description: Blende einzelne Kategorien aus verschiedenen Bereichen deiner Website (Startseite, Feeds, Archive, Suche) aus. Teil der WP Multi-Reihe.
|
||||
* Version: 1.0.0
|
||||
* Author: M_Viper
|
||||
* Author URI: https://m-viper.de
|
||||
* Requires at least: 6.7.2
|
||||
* Tested up to: 6.7.2
|
||||
* License: GPLv2 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
defined('ABSPATH') or die('Kein direkter Zugriff erlaubt.');
|
||||
|
||||
// Admin-Menü und Filter
|
||||
add_action('admin_menu', 'wpmkategorie_admin_menu');
|
||||
add_filter('pre_get_posts', 'wpmkategorie_exclude_categories');
|
||||
|
||||
// Admin-Menü unter "Beiträge"
|
||||
function wpmkategorie_admin_menu() {
|
||||
add_submenu_page(
|
||||
'edit.php', // Elternmenü: "Beiträge"
|
||||
'WP Multi Kategorie', // Seitentitel
|
||||
'Kategorie-Filter', // Menüpunkt-Name
|
||||
'manage_options', // Berechtigung
|
||||
'wp-multi-kategorie', // Slug
|
||||
'wpmkategorie_options_page' // Callback-Funktion
|
||||
);
|
||||
}
|
||||
|
||||
// Optionsseite
|
||||
function wpmkategorie_options_page() {
|
||||
if (isset($_POST['wpmkategorie'])) {
|
||||
check_admin_referer('wpmkategorie_form');
|
||||
$message = wpmkategorie_process();
|
||||
}
|
||||
|
||||
$options = wpmkategorie_get_options();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>WP Multi Kategorie</h1>
|
||||
<?php if (isset($message)) { echo $message; } ?>
|
||||
<p>Wähle Kategorien aus, die du aus bestimmten Bereichen deiner Website ausblenden möchtest.</p>
|
||||
<form action="" method="post">
|
||||
<?php wp_nonce_field('wpmkategorie_form'); ?>
|
||||
<table class="widefat fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kategorie</th>
|
||||
<th>Startseite ausblenden?</th>
|
||||
<th>Feeds ausblenden?</th>
|
||||
<th>Archive ausblenden?</th>
|
||||
<th>Suche ausblenden?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$categories = get_categories(array('hide_empty' => 0, 'order' => 'ASC'));
|
||||
$alt = 0;
|
||||
foreach ($categories as $cat) :
|
||||
$alt_class = ($alt++ % 2) ? ' class="alternate"' : '';
|
||||
?>
|
||||
<tr<?php echo $alt_class; ?>>
|
||||
<td><?php echo esc_html($cat->cat_name); ?></td>
|
||||
<td><input type="checkbox" name="exclude_main[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_main'])); ?> /></td>
|
||||
<td><input type="checkbox" name="exclude_feed[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_feed'])); ?> /></td>
|
||||
<td><input type="checkbox" name="exclude_archives[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_archives'])); ?> /></td>
|
||||
<td><input type="checkbox" name="exclude_search[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_search'])); ?> /></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="submit" name="wpmkategorie" class="button button-primary" value="Aktualisieren" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Verarbeitung der Formulardaten
|
||||
function wpmkategorie_process() {
|
||||
$options = array(
|
||||
'exclude_main' => isset($_POST['exclude_main']) ? array_map('intval', $_POST['exclude_main']) : array(),
|
||||
'exclude_feed' => isset($_POST['exclude_feed']) ? array_map('intval', $_POST['exclude_feed']) : array(),
|
||||
'exclude_archives' => isset($_POST['exclude_archives']) ? array_map('intval', $_POST['exclude_archives']) : array(),
|
||||
'exclude_search' => isset($_POST['exclude_search']) ? array_map('intval', $_POST['exclude_search']) : array()
|
||||
);
|
||||
|
||||
update_option('wpmkategorie_exclusions', $options);
|
||||
return '<div class="notice notice-success is-dismissible"><p>Einstellungen erfolgreich aktualisiert.</p></div>';
|
||||
}
|
||||
|
||||
// Optionen abrufen
|
||||
function wpmkategorie_get_options() {
|
||||
$defaults = array(
|
||||
'exclude_main' => array(),
|
||||
'exclude_feed' => array(),
|
||||
'exclude_archives' => array(),
|
||||
'exclude_search' => array()
|
||||
);
|
||||
|
||||
$options = get_option('wpmkategorie_exclusions', $defaults);
|
||||
if (!is_array($options)) {
|
||||
$options = $defaults;
|
||||
update_option('wpmkategorie_exclusions', $options);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
// Kategorien ausblenden
|
||||
function wpmkategorie_exclude_categories($query) {
|
||||
if (!is_admin() && $query->is_main_query()) {
|
||||
$options = wpmkategorie_get_options();
|
||||
|
||||
if ($query->is_home() && !empty($options['exclude_main'])) {
|
||||
$query->set('category__not_in', $options['exclude_main']);
|
||||
}
|
||||
if ($query->is_feed() && !empty($options['exclude_feed'])) {
|
||||
$query->set('category__not_in', $options['exclude_feed']);
|
||||
}
|
||||
if ($query->is_archive() && !empty($options['exclude_archives'])) {
|
||||
$query->set('category__not_in', $options['exclude_archives']);
|
||||
}
|
||||
if ($query->is_search() && !empty($options['exclude_search'])) {
|
||||
$query->set('category__not_in', $options['exclude_search']);
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Deinstallation
|
||||
function wpmkategorie_uninstall() {
|
||||
delete_option('wpmkategorie_exclusions');
|
||||
}
|
||||
register_uninstall_hook(__FILE__, 'wpmkategorie_uninstall');
|
||||
<?php
|
||||
/*
|
||||
* Plugin Name: WP Multi Kategorie
|
||||
* Plugin URI: https://git.viper.ipv64.net/M_Viper/WP-Multi-Kategorie
|
||||
* Description: Blende einzelne Kategorien aus verschiedenen Bereichen deiner Website (Startseite, Feeds, Archive, Suche) aus. Teil der WP Multi-Reihe.
|
||||
* Version: 1.1
|
||||
* Author: M_Viper
|
||||
* Author URI: https://m-viper.de
|
||||
* Requires at least: 6.7.2
|
||||
* Tested up to: 6.7.2
|
||||
* License: GPLv2 or later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
defined('ABSPATH') or die('Kein direkter Zugriff erlaubt.');
|
||||
|
||||
/*
|
||||
* WP Multi Toolkit Prüfung
|
||||
*/
|
||||
|
||||
// Funktion zur Überprüfung des WP Multi Toolkit Plugins
|
||||
function wp_multi_kategorie_check_dependency() {
|
||||
if (!function_exists('is_plugin_active')) {
|
||||
include_once(ABSPATH . 'wp-admin/includes/plugin.php');
|
||||
}
|
||||
|
||||
// Prüft, ob WP Multi Toolkit installiert und aktiv ist
|
||||
if (!is_plugin_active('wp-multi-toolkit/wp-multi-toolkit.php')) {
|
||||
add_action('admin_notices', 'wp_multi_kategorie_dependency_notice');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Fehlermeldung für Admin-Bereich mit Download-Button
|
||||
function wp_multi_kategorie_dependency_notice() {
|
||||
?>
|
||||
<div class="notice notice-error">
|
||||
<p>
|
||||
<?php _e('Das Plugin "WP Multi Kategorie" benötigt "WP Multi Toolkit", um zu funktionieren. Bitte installieren und aktivieren Sie "WP Multi Toolkit".', 'wp-multi-kategorie'); ?>
|
||||
<a href="https://git.viper.ipv64.net/M_Viper/wp-multi-toolkit/releases" target="_blank" class="button button-primary" style="margin-left: 10px;">
|
||||
<?php _e('WP Multi Toolkit herunterladen', 'wp-multi-kategorie'); ?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Plugin nur initialisieren, wenn Abhängigkeit erfüllt ist
|
||||
if (wp_multi_kategorie_check_dependency()) {
|
||||
// Hier würde der restliche Plugin-Code folgen
|
||||
} else {
|
||||
// Optional: Plugin komplett deaktivieren, wenn Abhängigkeit fehlt
|
||||
add_action('admin_init', function() {
|
||||
deactivate_plugins(plugin_basename(__FILE__));
|
||||
});
|
||||
}
|
||||
|
||||
// Admin-Menü und Filter
|
||||
add_action('admin_menu', 'wpmkategorie_admin_menu');
|
||||
add_filter('pre_get_posts', 'wpmkategorie_exclude_categories');
|
||||
|
||||
// Admin-Menü unter "Beiträge"
|
||||
function wpmkategorie_admin_menu() {
|
||||
add_submenu_page(
|
||||
'edit.php', // Elternmenü: "Beiträge"
|
||||
'WP Multi Kategorie', // Seitentitel
|
||||
'Kategorie-Filter', // Menüpunkt-Name
|
||||
'manage_options', // Berechtigung
|
||||
'wp-multi-kategorie', // Slug
|
||||
'wpmkategorie_options_page' // Callback-Funktion
|
||||
);
|
||||
}
|
||||
|
||||
// CSS für modernes Design
|
||||
// CSS nur für die Seite des Plugins
|
||||
function wpmkategorie_enqueue_styles() {
|
||||
// Überprüfen, ob wir auf der Seite des Plugins sind
|
||||
if (isset($_GET['page']) && $_GET['page'] === 'wp-multi-kategorie') {
|
||||
echo '<style>
|
||||
.wrap {
|
||||
background-color: #f9f9f9;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
|
||||
font-size: 1.8rem;
|
||||
color: #333;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.button {
|
||||
background-color: #0073aa;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.button-primary {
|
||||
background-color: #00a0d2;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background-color: #006e8a;
|
||||
}
|
||||
|
||||
.widefat th, .widefat td {
|
||||
padding: 12px;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.widefat tr.alternate {
|
||||
background-color: #f1f1f1;
|
||||
}
|
||||
|
||||
.submit {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.notice-success, .notice-error {
|
||||
font-size: 16px;
|
||||
background-color: #e7f9e7;
|
||||
border: 1px solid #6ecf6e;
|
||||
padding: 15px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.notice-error {
|
||||
background-color: #fbe9e9;
|
||||
border-color: #f57c7c;
|
||||
}
|
||||
|
||||
.wp-multi-kategorie-form input[type="checkbox"] {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Banner mit Blauem Hintergrund und Logo zentriert */
|
||||
.wp-multi-kategorie-banner {
|
||||
background-color: #0073aa; /* Blaues Banner */
|
||||
color: white;
|
||||
height: 150px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.wp-multi-kategorie-banner img {
|
||||
max-height: 100px;
|
||||
max-width: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
</style>';
|
||||
}
|
||||
}
|
||||
add_action('admin_head', 'wpmkategorie_enqueue_styles');
|
||||
|
||||
// Optionsseite mit modernem Design
|
||||
function wpmkategorie_options_page() {
|
||||
if (isset($_POST['wpmkategorie'])) {
|
||||
check_admin_referer('wpmkategorie_form');
|
||||
$message = wpmkategorie_process();
|
||||
}
|
||||
|
||||
$options = wpmkategorie_get_options();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<div class="wp-multi-kategorie-banner">
|
||||
<img src="https://m-viper.de/img/logo.png" alt="Logo"> <!-- Logo im Banner zentriert -->
|
||||
</div>
|
||||
<h1>WP Multi Kategorie</h1>
|
||||
<?php if (isset($message)) { echo $message; } ?>
|
||||
<p>Wähle Kategorien aus, die du aus bestimmten Bereichen deiner Website ausblenden möchtest.</p>
|
||||
<form action="" method="post" class="wp-multi-kategorie-form">
|
||||
<?php wp_nonce_field('wpmkategorie_form'); ?>
|
||||
<table class="widefat fixed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Kategorie</th>
|
||||
<th>Startseite</th>
|
||||
<th>Feeds</th>
|
||||
<th>Archive</th>
|
||||
<th>Suche</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$categories = get_categories(array('hide_empty' => 0, 'order' => 'ASC'));
|
||||
$alt = 0;
|
||||
foreach ($categories as $cat) :
|
||||
$alt_class = ($alt++ % 2) ? ' class="alternate"' : '';
|
||||
?>
|
||||
<tr<?php echo $alt_class; ?>>
|
||||
<td><?php echo esc_html($cat->cat_name); ?></td>
|
||||
<td><input type="checkbox" name="exclude_main[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_main'])); ?> /></td>
|
||||
<td><input type="checkbox" name="exclude_feed[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_feed'])); ?> /></td>
|
||||
<td><input type="checkbox" name="exclude_archives[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_archives'])); ?> /></td>
|
||||
<td><input type="checkbox" name="exclude_search[]" value="<?php echo $cat->cat_ID; ?>" <?php checked(in_array($cat->cat_ID, $options['exclude_search'])); ?> /></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="submit" name="wpmkategorie" class="button button-primary" value="Einstellungen speichern" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Verarbeitung der Formulardaten
|
||||
function wpmkategorie_process() {
|
||||
$options = array(
|
||||
'exclude_main' => isset($_POST['exclude_main']) ? array_map('intval', $_POST['exclude_main']) : array(),
|
||||
'exclude_feed' => isset($_POST['exclude_feed']) ? array_map('intval', $_POST['exclude_feed']) : array(),
|
||||
'exclude_archives' => isset($_POST['exclude_archives']) ? array_map('intval', $_POST['exclude_archives']) : array(),
|
||||
'exclude_search' => isset($_POST['exclude_search']) ? array_map('intval', $_POST['exclude_search']) : array()
|
||||
);
|
||||
|
||||
update_option('wpmkategorie_exclusions', $options);
|
||||
return '<div class="notice notice-success is-dismissible"><p>Die Einstellungen wurden erfolgreich gespeichert.</p></div>';
|
||||
}
|
||||
|
||||
// Optionen abrufen
|
||||
function wpmkategorie_get_options() {
|
||||
$defaults = array(
|
||||
'exclude_main' => array(),
|
||||
'exclude_feed' => array(),
|
||||
'exclude_archives' => array(),
|
||||
'exclude_search' => array()
|
||||
);
|
||||
|
||||
$options = get_option('wpmkategorie_exclusions', $defaults);
|
||||
if (!is_array($options)) {
|
||||
$options = $defaults;
|
||||
update_option('wpmkategorie_exclusions', $options);
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
// Kategorien ausblenden
|
||||
function wpmkategorie_exclude_categories($query) {
|
||||
if (!is_admin() && $query->is_main_query()) {
|
||||
$options = wpmkategorie_get_options();
|
||||
|
||||
if ($query->is_home() && !empty($options['exclude_main'])) {
|
||||
$query->set('category__not_in', $options['exclude_main']);
|
||||
}
|
||||
if ($query->is_feed() && !empty($options['exclude_feed'])) {
|
||||
$query->set('category__not_in', $options['exclude_feed']);
|
||||
}
|
||||
if ($query->is_archive() && !empty($options['exclude_archives'])) {
|
||||
$query->set('category__not_in', $options['exclude_archives']);
|
||||
}
|
||||
if ($query->is_search() && !empty($options['exclude_search'])) {
|
||||
$query->set('category__not_in', $options['exclude_search']);
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
// Deinstallation
|
||||
function wpmkategorie_uninstall() {
|
||||
delete_option('wpmkategorie_exclusions');
|
||||
}
|
||||
register_uninstall_hook(__FILE__, 'wpmkategorie_uninstall');
|
||||
|
Reference in New Issue
Block a user