wp-ingame-shop/wp-ingame-shop.php aktualisiert
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
/*
|
/*
|
||||||
Plugin Name: WP Ingame Shop Pro - NO RCON & CUSTOM CURRENCY
|
Plugin Name: WP Ingame Shop Pro - NO RCON & CUSTOM CURRENCY
|
||||||
Description: Vollautomatischer Shop mit Warenkorb.
|
Description: Vollautomatischer Shop mit Warenkorb.
|
||||||
Version: 1.0.0
|
Version: 1.0.1
|
||||||
Author: M_Viper
|
Author: M_Viper
|
||||||
*/
|
*/
|
||||||
if (!defined('ABSPATH')) exit;
|
if (!defined('ABSPATH')) exit;
|
||||||
@@ -1616,4 +1616,187 @@ add_filter('handle_bulk_actions-edit-wis_coupon', [WIS_Bulk_Actions::class, 'han
|
|||||||
add_filter('handle_bulk_actions-edit-wis_server', [WIS_Bulk_Actions::class, 'handle_bulk_actions'], 10, 3);
|
add_filter('handle_bulk_actions-edit-wis_server', [WIS_Bulk_Actions::class, 'handle_bulk_actions'], 10, 3);
|
||||||
|
|
||||||
add_action('admin_notices', [WIS_Bulk_Actions::class, 'admin_notices']);
|
add_action('admin_notices', [WIS_Bulk_Actions::class, 'admin_notices']);
|
||||||
|
|
||||||
|
/* ================= SIDEBAR WIDGET: SHOP ANGEBOT (ERWEITERT) ================= */
|
||||||
|
class WIS_Sidebar_Offer_Widget extends WP_Widget {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
parent::__construct(
|
||||||
|
'wis_sidebar_offer', // Basis ID
|
||||||
|
'WIS Shop Angebot', // Name
|
||||||
|
array( 'description' => 'Zeigt das aktuelle Angebot oder Daily Deal an mit anpassbarem Link.' ) // Args
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backend: Formular im Widget-Bereich
|
||||||
|
public function form( $instance ) {
|
||||||
|
// Standardwerte definieren
|
||||||
|
$defaults = [
|
||||||
|
'title' => '🔥 Angebot des Tages',
|
||||||
|
'btn_text' => 'Zum Shop',
|
||||||
|
'shop_url' => ''
|
||||||
|
];
|
||||||
|
// Werte mergen (falls noch nichts gespeichert wurde)
|
||||||
|
$instance = wp_parse_args( (array) $instance, $defaults );
|
||||||
|
|
||||||
|
?>
|
||||||
|
<p>
|
||||||
|
<label for="<?php echo $this->get_field_id( 'title' ); ?>">Titel:</label>
|
||||||
|
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="<?php echo $this->get_field_id( 'btn_text' ); ?>">Button Text:</label>
|
||||||
|
<input class="widefat" id="<?php echo $this->get_field_id( 'btn_text' ); ?>" name="<?php echo $this->get_field_name( 'btn_text' ); ?>" type="text" value="<?php echo esc_attr( $instance['btn_text'] ); ?>">
|
||||||
|
<small style="color:#666;">Standard: "Zum Shop"</small>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<label for="<?php echo $this->get_field_id( 'shop_url' ); ?>">Shop URL (Link Ziel):</label>
|
||||||
|
<input class="widefat" id="<?php echo $this->get_field_id( 'shop_url' ); ?>" name="<?php echo $this->get_field_name( 'shop_url' ); ?>" type="text" value="<?php echo esc_attr( $instance['shop_url'] ); ?>">
|
||||||
|
<small style="color:#666;">Wenn leer, wird zur Startseite verlinkt.</small>
|
||||||
|
</p>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backend: Speichern
|
||||||
|
public function update( $new_instance, $old_instance ) {
|
||||||
|
$instance = array();
|
||||||
|
|
||||||
|
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? sanitize_text_field( $new_instance['title'] ) : '🔥 Angebot des Tages';
|
||||||
|
$instance['btn_text'] = ( ! empty( $new_instance['btn_text'] ) ) ? sanitize_text_field( $new_instance['btn_text'] ) : 'Zum Shop';
|
||||||
|
$instance['shop_url'] = ( ! empty( $new_instance['shop_url'] ) ) ? esc_url_raw( $new_instance['shop_url'] ) : '';
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Frontend: Ausgabe
|
||||||
|
public function widget( $args, $instance ) {
|
||||||
|
echo $args['before_widget'];
|
||||||
|
|
||||||
|
// Standardwerte definieren
|
||||||
|
$defaults = [
|
||||||
|
'title' => '🔥 Angebot des Tages',
|
||||||
|
'btn_text' => 'Zum Shop',
|
||||||
|
'shop_url' => ''
|
||||||
|
];
|
||||||
|
$instance = wp_parse_args( (array) $instance, $defaults );
|
||||||
|
|
||||||
|
if ( ! empty( $instance['title'] ) ) {
|
||||||
|
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$currency = get_option('wis_currency_name', 'Coins');
|
||||||
|
$img_base = get_option('wis_image_base_url', 'https://assets.minecraft-ids.com/1_21.10/');
|
||||||
|
|
||||||
|
// 1. Suche Daily Deal (Prio 1)
|
||||||
|
$daily_deal = get_posts([
|
||||||
|
'post_type' => 'wis_item',
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
'meta_key' => '_wis_daily_deal',
|
||||||
|
'meta_value' => 1
|
||||||
|
]);
|
||||||
|
|
||||||
|
$item = null;
|
||||||
|
$is_daily = false;
|
||||||
|
|
||||||
|
if (!empty($daily_deal)) {
|
||||||
|
$item = $daily_deal[0];
|
||||||
|
$is_daily = true;
|
||||||
|
} else {
|
||||||
|
// 2. Fallback: Suche normales Angebot (Prio 2)
|
||||||
|
$offers = get_posts([
|
||||||
|
'post_type' => 'wis_item',
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
'meta_key' => '_wis_is_offer',
|
||||||
|
'meta_value' => 1,
|
||||||
|
'orderby' => 'modified',
|
||||||
|
'order' => 'DESC'
|
||||||
|
]);
|
||||||
|
if (!empty($offers)) {
|
||||||
|
$item = $offers[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ziel-URL für den Button bestimmen
|
||||||
|
$target_url = !empty($instance['shop_url']) ? $instance['shop_url'] : home_url();
|
||||||
|
|
||||||
|
if ($item) {
|
||||||
|
$price = get_post_meta($item->ID, '_wis_price', true);
|
||||||
|
$offer_price = get_post_meta($item->ID, '_wis_offer_price', true);
|
||||||
|
$item_id_code = get_post_meta($item->ID, '_wis_item_id', true);
|
||||||
|
|
||||||
|
$final_price = ($offer_price > 0) ? $offer_price : $price;
|
||||||
|
$show_old_price = ($offer_price > 0 && $offer_price < $price);
|
||||||
|
|
||||||
|
// Bild URL generieren
|
||||||
|
$img_name = str_replace(':', '_', $item_id_code) . '.png';
|
||||||
|
$full_img_url = $img_base . $img_name;
|
||||||
|
|
||||||
|
// Modernes Card Design
|
||||||
|
?>
|
||||||
|
<div id="wis-offer-<?php echo esc_attr($item->ID); ?>" style="background:#fff; border-radius:10px; border:1px solid #eee; padding:0; overflow:hidden; box-shadow:0 4px 10px rgba(0,0,0,0.05); text-align:center; font-family:-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;">
|
||||||
|
|
||||||
|
<!-- Bild Bereich -->
|
||||||
|
<div style="position:relative; background:#2d2d2d; padding:15px; height:160px; display:flex; align-items:center; justify-content:center;">
|
||||||
|
<?php if($is_daily): ?>
|
||||||
|
<div style="position:absolute; top:10px; left:10px; background:linear-gradient(135deg, #6f42c1, #8e44ad); color:#fff; padding:4px 10px; font-size:10px; border-radius:20px; font-weight:bold; z-index:2; box-shadow:0 2px 4px rgba(0,0,0,0.3);">🎁 DAILY DEAL</div>
|
||||||
|
<?php elseif($offer_price > 0): ?>
|
||||||
|
<div style="position:absolute; top:10px; left:10px; background:linear-gradient(135deg, #ff416c, #ff4b2b); color:#fff; padding:4px 10px; font-size:10px; border-radius:20px; font-weight:bold; z-index:2; box-shadow:0 2px 4px rgba(0,0,0,0.3);">🔥 ANGEBOT</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<img src="<?php echo esc_url($full_img_url); ?>" alt="<?php echo esc_attr($item->post_title); ?>" style="max-width:90%; max-height:90%; object-fit:contain; filter:drop-shadow(0 4px 8px rgba(0,0,0,0.6)); transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Inhalt -->
|
||||||
|
<div style="padding:15px;">
|
||||||
|
<h4 style="margin:0 0 8px 0; font-size:15px; color:#333; line-height:1.3; font-weight:700; white-space:nowrap; overflow:hidden; text-overflow:ellipsis;"><?php echo esc_html($item->post_title); ?></h4>
|
||||||
|
|
||||||
|
<div style="margin-bottom:12px; min-height:24px; display:flex; align-items:center; justify-content:center; gap:5px;">
|
||||||
|
<?php if($show_old_price): ?>
|
||||||
|
<span style="text-decoration:line-through; color:#999; font-size:11px;"><?php echo esc_html($price); ?> <?php echo esc_html($currency); ?></span>
|
||||||
|
<?php endif; ?>
|
||||||
|
<span style="font-size:20px; font-weight:800; color:#28a745; line-height:1;"><?php echo esc_html($final_price); ?> <span style="font-size:12px; font-weight:400; color:#666;"><?php echo esc_html($currency); ?></span></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Button mit URL -->
|
||||||
|
<a href="<?php echo esc_url($target_url); ?>" style="display:block; padding:10px 0; background:linear-gradient(135deg, #667eea 0%, #764ba2 100%); color:#fff; text-decoration:none; border-radius:6px; font-weight:bold; font-size:13px; transition:opacity 0.2s; letter-spacing:0.5px;">
|
||||||
|
<?php echo esc_html($instance['btn_text']); ?> 🛒
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
(function(){
|
||||||
|
var widget = document.getElementById('wis-offer-<?php echo esc_js($item->ID); ?>');
|
||||||
|
if(widget) {
|
||||||
|
var img = widget.querySelector('img');
|
||||||
|
var btn = widget.querySelector('a');
|
||||||
|
|
||||||
|
if(img) {
|
||||||
|
widget.addEventListener('mouseenter', function(){
|
||||||
|
img.style.transform = 'scale(1.15) rotate(5deg)';
|
||||||
|
widget.style.borderColor = '#667eea';
|
||||||
|
});
|
||||||
|
widget.addEventListener('mouseleave', function(){
|
||||||
|
img.style.transform = 'scale(1) rotate(0deg)';
|
||||||
|
widget.style.borderColor = '#eee';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?php
|
||||||
|
} else {
|
||||||
|
echo '<div style="background:#f8f9fa; border:1px dashed #ddd; border-radius:8px; padding:20px; text-align:center;"><p style="margin:0; color:#888; font-size:13px;">Kein Angebot verfügbar.</p></div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo $args['after_widget'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Widget registrieren
|
||||||
|
add_action( 'widgets_init', function(){
|
||||||
|
register_widget( 'WIS_Sidebar_Offer_Widget' );
|
||||||
|
});
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user