WowPress-Tailwind/theme/wowpress/Frontend/Widgets/Widget.php

63 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2024-04-23 00:44:42 +02:00
<?php
namespace WoWPress\Frontend\Widgets;
use WoWPress\Models\Raid;
use WoWPress\Models\User;
use WP_Widget;
class Widget extends WP_Widget {
protected $template_path = "";
protected $title = "";
protected $base_id = "wowpress_widget";
public $name = "WoWPress Widget";
protected $restricted = false;
public function __construct() {
parent::__construct(
$this->base_id, // Base ID
$this->name // Name
);
add_action( 'widgets_init', function() {
register_widget( $this::class);
});
}
public $args = array(
'before_title' => '',
'after_title' => '',
'before_widget' => '',
'after_widget' => '',
);
private function getTemplatePath(){
return get_template_directory()."/template-parts/widgets/".$this->template_path;
}
public function widget( $args, $instance ) {
#dd($instance);
if(!$this->restricted || (current_user_can($this->restricted))){
require($this->getTemplatePath());
}
}
public function form( $instance ) {
$count = ! empty( $instance['count'] ) ? $instance['count'] : 1;
?>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>"><?php echo esc_html__( 'Anzahl', 'wowpress' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'count' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'count' ) ); ?>" min="1" max="5" type="number" value="<?php echo esc_attr( $count ); ?>">
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['count'] = ( ! empty( $new_instance['count'] ) ) ? strip_tags( $new_instance['count'] ) : '';
return $instance;
}
}