function wbmz_register_widget() {
register_widget( 'wbmz_widget' );
}
add_action( 'widgets_init', 'wbmz_register_widget' );
class wbmz_widget extends WP_Widget {
function __construct() {
parent::__construct(
// widget ID
'wbmzfltr_widget',
// widget name
__('Filter', ' wbmz'),
// widget description
array( 'description' => __( 'Widget om filters mee te laten zien', 'wbmz' ), )
);
}
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
$widget_id = 'fltr_'.sanitize_title($instance['title']);
$shortcode = $instance[ 'shortcode' ];
$uitklappen = ! empty( $instance['uitklappen'] ) ? $instance['uitklappen'] : false;
echo $args['before_widget'];
//if title is present
if ( ! empty( $title ) )
//echo $args['before_title'] . $title . $args['after_title'];
echo $args['before_widget'];

  if($shortcode) { ?>
    <div class="wdgt">
        <a class="ttl" data-bs-toggle="collapse" href="#<?php echo $widget_id; ?>" role="button" aria-expanded="<?php if($uitklappen == 'yes'):?>true<?php else:?>false<?php endif; ?>" aria-controls="<?php echo $widget_id; ?>">
            <?php echo $title; ?> <i class="fas fa-chevron-down rotate-icon"></i>
          </a>
                <div class="collapse <?php if($uitklappen == 'yes'):?>show<?php endif; ?>" id="<?php echo $widget_id; ?>">
                <?php echo do_shortcode($shortcode); ?>
                </div>
            </div>
  <?php }
echo $args['after_widget'];
}
public function form( $instance ) {
$instance = wp_parse_args(
    (array) $instance,
    array(
        'uitklappen' => 'yes', // checked by default
    )
);
if ( isset( $instance[ 'title' ] ) ):
$title = $instance[ 'title' ];
else:
$title = __( 'Filter titel', 'wbmz' );
endif;
if ( isset( $instance[ 'shortcode' ] ) ) {
    $shortcode = $instance[ 'shortcode' ];
}

?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( '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( $title ); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'shortcode' ); ?>"><?php _e( 'Shortcode:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'shortcode' ); ?>" name="<?php echo $this->get_field_name( 'shortcode' ); ?>" type="text" value="<?php echo esc_attr( $shortcode ); ?>" />
</p>
<p>
    <input type="checkbox" id="<?php echo $this->get_field_id( 'uitklappen' ); ?>" name="<?php echo $this->get_field_name( 'uitklappen' ); ?>" value="yes"<?php checked( 'yes', $instance['uitklappen'] ); ?>>
    <label for="<?php echo $this->get_field_id( 'uitklappen' ); ?>">Filter uitklappen</label><br>
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
$instance['shortcode'] = ( ! empty( $new_instance['shortcode'] ) ) ? strip_tags( $new_instance['shortcode'] ) : '';
$instance['uitklappen'] = isset( $new_instance['uitklappen'] ) ? 'yes' : 'no';
return $instance;
}
}
Geef een reactie 0