Dateien nach "/" hochladen
This commit is contained in:
parent
2d2b8404b5
commit
f69090f168
140
wp-multi-kategorie.php
Normal file
140
wp-multi-kategorie.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?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');
|
Loading…
x
Reference in New Issue
Block a user