/**
  * Initial settings for the walker
  * Find out wether they want to show descriptions or not
  */
 private function init_settings()
 {
     $this->post_type = Beautiful_Taxonomy_Filters_Public::get_current_posttype(false);
     /*
      * If this walker gets called from a widget we need to fetch that widgets settings and apply filters
      * Otherwise just get the settings from wp_options
      */
     if ($this->call_type == 'widget') {
         $this->show_description = strip_tags($this->instance['show_description']);
         if ($this->show_description == 'inherit') {
             $this->show_description = apply_filters('beautiful_filters_show_description', get_option('beautiful_taxonomy_filters_show_description'), $this->post_type);
         } else {
             $this->show_description = $this->show_description == 'enable' ? 1 : 0;
             $this->show_description = apply_filters('beautiful_filters_show_description', $this->show_description, $this->post_type);
         }
     } else {
         $this->show_description = apply_filters('beautiful_filters_show_description', get_option('beautiful_taxonomy_filters_show_description'), $this->post_type);
     }
     $this->disable_select2 = get_option('beautiful_taxonomy_filters_disable_select2') ? get_option('beautiful_taxonomy_filters_disable_select2') : false;
 }
    /**
     * Outputs the widget with the selected settings
     *
     * @since    1.0.0
     */
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        $clear_all = strip_tags($instance['clear_all']);
        $hide_empty = strip_tags($instance['hide_empty']);
        $show_count = strip_tags($instance['show_count']);
        $post_type = strip_tags($instance['post_type']);
        $dropdown_behaviour = strip_tags($instance['dropdown_behaviour']);
        $activated_post_types = apply_filters('beautiful_filters_post_types', get_option('beautiful_taxonomy_filters_post_types'));
        $disable_select2 = get_option('beautiful_taxonomy_filters_disable_select2') ? get_option('beautiful_taxonomy_filters_disable_select2') : false;
        //Make sure we find the current post type!
        if ($post_type == 'automatic') {
            $current_post_type = Beautiful_Taxonomy_Filters_Public::get_current_posttype(false);
            $current_post_type_rewrite = Beautiful_Taxonomy_Filters_Public::get_current_posttype(true);
        } else {
            $current_post_type = $post_type;
            //Get the post type object
            $post_type_object = get_post_type_object($current_post_type);
            //Return the rewrite slug which is the one we actually want!
            $current_post_type_rewrite = $post_type_object->rewrite['slug'];
        }
        //If there is no current post type, bail early!
        if (!is_array($activated_post_types) || !$current_post_type || !in_array($current_post_type, $activated_post_types)) {
            return;
        }
        //Get the taxonomies of the current post type and the excluded taxonomies
        $excluded_taxonomies = apply_filters('beautiful_filters_taxonomies', get_option('beautiful_taxonomy_filters_taxonomies'));
        //Also make sure we don't try to output the builtin taxonomies since they cannot be supported
        if (is_array($excluded_taxonomies)) {
            array_push($excluded_taxonomies, 'category', 'post_tag', 'post_format');
        } else {
            $excluded_taxonomies = array('category', 'post_tag', 'post_format');
        }
        //Polylang support
        if (function_exists('pll_current_language')) {
            array_push($excluded_taxonomies, 'language', 'post_translations');
        }
        $current_taxonomies = get_object_taxonomies($current_post_type, 'objects');
        //If we both have taxonomies on the post type AND we've set som excluded taxonomies in the plugins settings. Loop through them and unset those we don't want!
        if ($current_taxonomies && $excluded_taxonomies) {
            foreach ($current_taxonomies as $key => $value) {
                if (in_array($key, $excluded_taxonomies)) {
                    unset($current_taxonomies[$key]);
                }
            }
        }
        //Fetch the available settings for the filter modules behaviour
        if ($clear_all == 'inherit') {
            $clear_all = apply_filters('beautiful_filters_clear_all', get_option('beautiful_taxonomy_filters_clear_all'), $current_post_type);
        } else {
            $clear_all = $clear_all == 'enable' ? 1 : 0;
            $clear_all = apply_filters('beautiful_filters_clear_all', $clear_all, $current_post_type);
        }
        if ($hide_empty == 'inherit') {
            $hide_empty = apply_filters('beautiful_filters_hide_empty', get_option('beautiful_taxonomy_filters_hide_empty'), $current_post_type);
        } else {
            $hide_empty = $hide_empty == 'enable' ? 1 : 0;
            $hide_empty = apply_filters('beautiful_filters_hide_empty', $hide_empty, $current_post_type);
        }
        if ($show_count == 'inherit') {
            $show_count = apply_filters('beautiful_filters_show_count', get_option('beautiful_taxonomy_filters_show_count'), $current_post_type);
        } else {
            $show_count = $show_count == 'enable' ? 1 : 0;
            $show_count = apply_filters('beautiful_filters_show_count', $show_count, $current_post_type);
        }
        if ($dropdown_behaviour == 'inherit') {
            $dropdown_behaviour = apply_filters('beautiful_filters_dropdown_behaviour', get_option('beautiful_taxonomy_filters_dropdown_behaviour'), $current_post_type);
        } else {
            $dropdown_behaviour = $dropdown_behaviour == 'enable' ? 1 : 0;
            $dropdown_behaviour = apply_filters('beautiful_filters_dropdown_behaviour', $dropdown_behaviour, $current_post_type);
        }
        /*
         * The content of the widget
         */
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        ?>
		<div class="beautiful-taxonomy-filters-widget" id="beautiful-taxonomy-filters-<?php 
        echo $current_post_type;
        ?>
">
			<?php 
        do_action('beautiful_actions_before_form', $current_post_type);
        //Allow custom markup before form
        ?>
			<form method="POST" class="clearfix" id="beautiful-taxonomy-filters-form">
				<input type="hidden" name="site-url" value="<?php 
        echo get_bloginfo('url');
        ?>
" />
				<input type="hidden" name="post_type_rewrite" value="<?php 
        echo $current_post_type_rewrite;
        ?>
" />
				<input type="hidden" name="post_type" value="<?php 
        echo $current_post_type;
        ?>
" />
				<?php 
        wp_nonce_field('Beutiful-taxonomy-filters-do-filter', 'btf_do_filtering_nonce');
        ?>
				<?php 
        do_action('beautiful_actions_beginning_form', $current_post_type);
        //allow custom markup at beginning of form
        ?>
				<?php 
        //Loop through the taxonomies and output their terms in a select dropdown
        $count = count($current_taxonomies);
        $taxonomies_ordered = apply_filters('beautiful_filters_taxonomy_order', array_keys($current_taxonomies), $current_post_type);
        ?>
				<div class="beautiful-taxonomy-filters-select-wrap clearfix">
					<?php 
        do_action('beautiful_actions_beginning_form_inner', $current_post_type);
        //allow custom markup at beginning of form
        ?>
					<?php 
        foreach ($taxonomies_ordered as $key) {
            ?>
						<?php 
            $taxonomy = $current_taxonomies[$key];
            $terms = get_terms($key);
            ?>
						<?php 
            if (!empty($terms) && !is_wp_error($terms)) {
                ?>
							<div class="beautiful-taxonomy-filters-tax filter-count-<?php 
                echo $count;
                if ($count > 5) {
                    echo ' filter-count-many';
                }
                ?>
" id="beautiful-taxonomy-filters-tax-<?php 
                echo $key;
                ?>
">
								<label for="select-<?php 
                echo $key;
                ?>
" class="beautiful-taxonomy-filters-label"><?php 
                echo apply_filters('beautiful_filters_taxonomy_label', $taxonomy->labels->name, $taxonomy->name);
                ?>
</label>
								<?php 
                /**
                 * Output the dropdown with the terms of the taxonomy.
                 * Uses walker found in: public/class-beautiful-taxonomy-filters-walker.php
                 */
                $dropdown_args = array('show_option_all' => __('All ', 'beautiful-taxonomy-filters') . $taxonomy->labels->name, 'taxonomy' => $key, 'name' => 'select-' . $key, 'show_count' => $show_count, 'hide_empty' => $hide_empty, 'orderby' => apply_filters('beautiful_filters_dropdown_orderby', 'name', $key), 'order' => apply_filters('beautiful_filters_dropdown_order', 'ASC', $key), 'hierarchical' => true, 'echo' => 0, 'class' => 'beautiful-taxonomy-filters-select', 'walker' => new Walker_Slug_Value_Category_Dropdown());
                //Apply filter on the arguments to let users modify them first!
                $dropdown_args = apply_filters('beautiful_filters_dropdown_categories', $dropdown_args, $taxonomy->name);
                //But if they've selected placeholder we cant use the show_option_all
                if (!$disable_select2 && $dropdown_behaviour == 'show_placeholder_option') {
                    $dropdown_args['show_option_all'] = ' ';
                }
                //create the dropdown
                $filterdropdown = wp_dropdown_categories($dropdown_args);
                //If they didnt select placeholder just output the dropdown now
                if ($disable_select2 || !$dropdown_behaviour || $dropdown_behaviour == 'show_all_option') {
                    echo $filterdropdown;
                } else {
                    //They selected placeholder so now we need to choose what to display and then alter the dropdown before output.
                    $new_label = apply_filters('beautiful_filters_dropdown_placeholder', __('All ', 'beautiful-taxonomy-filters') . $taxonomy->labels->name, $taxonomy->name);
                    $filterdropdown = str_replace("value='0' selected='selected'", "", $filterdropdown);
                    echo str_replace('<select ', '<select data-placeholder="' . $new_label . '"', $filterdropdown);
                }
                ?>
							</div>
						<?php 
            }
            ?>
					<?php 
        }
        ?>
					<?php 
        do_action('beautiful_actions_ending_form_inner', $current_post_type);
        //allow custom markup at end of inner form
        ?>
				</div>
				<?php 
        do_action('beautiful_actions_before_submit_button', $current_post_type);
        //allow custom markup before submit button
        ?>
				<button type="submit" class="beautiful-taxonomy-filters-button"><?php 
        echo apply_filters('beautiful_filters_apply_button', __('Apply filter', 'beautiful-taxonomy-filters'));
        ?>
</button>
				<?php 
        if ($clear_all) {
            ?>
					<a href="<?php 
            echo get_post_type_archive_link($current_post_type);
            ?>
" class="beautiful-taxonomy-filters-clear-all" title="<?php 
            _e('Click to clear all active filters', 'beautiful-taxonomy-filters');
            ?>
"><?php 
            echo apply_filters('beautiful_filters_clear_button', __('Clear all', 'beautiful-taxonomy-filters'));
            ?>
</a>
				<?php 
        }
        ?>
				<?php 
        do_action('beautiful_actions_ending_form', $current_post_type);
        //allow custom markup at beginning of form
        ?>
			</form>
			<?php 
        do_action('beautiful_actions_after_form', $current_post_type);
        //Allow custom markup after form
        ?>
		</div>
		<?php 
        echo $after_widget;
    }
    /**
     * Outputs the widget with the selected settings
     *
     * @since    1.0.0
     */
    public function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
        global $wp_query;
        if (!empty($wp_query->tax_query->queries)) {
            $current_taxonomies = $wp_query->tax_query->queries;
        } else {
            $current_taxonomies = false;
        }
        $hide_postcount = apply_filters('beautiful_filters_disable_postcount', get_option('beautiful_taxonomy_filters_disable_postcount'));
        $activated_post_types = apply_filters('beautiful_filters_post_types', get_option('beautiful_taxonomy_filters_post_types'));
        $current_post_type = Beautiful_Taxonomy_Filters_Public::get_current_posttype(false);
        //If there is no current post type, bail early!
        if (!is_array($activated_post_types) || !$current_post_type || !in_array($current_post_type, $activated_post_types)) {
            return;
        }
        /*
         * The content of the widget
         */
        echo $before_widget;
        if (!empty($title)) {
            echo $before_title . $title . $after_title;
        }
        ?>
		<div class="beautiful-taxonomy-filters-active-filter-widget">
			<?php 
        if (!$hide_postcount) {
            ?>
				<p class="beautiful-taxonomy-filters-postcount"><?php 
            echo apply_filters('beautiful_filters_info_postcount', sprintf(__('Result of filter: %d', 'beautiful-taxonomy-filters'), $wp_query->found_posts));
            ?>
</p>
				
			<?php 
        }
        ?>
			<?php 
        $posttypes_taxonomies = get_object_taxonomies($current_post_type, 'objects');
        ?>
			<?php 
        if ($current_taxonomies) {
            ?>
				<?php 
            //Get the taxonomies of the current post type and the excluded taxonomies
            $excluded_taxonomies = apply_filters('beautiful_filters_taxonomies', get_option('beautiful_taxonomy_filters_taxonomies'));
            //Also make sure we don't try to output the builtin taxonomies since they cannot be supported
            if (is_array($excluded_taxonomies)) {
                array_push($excluded_taxonomies, 'category', 'post_tag', 'post_format');
            } else {
                $excluded_taxonomies = array('category', 'post_tag', 'post_format');
            }
            //Polylang support
            if (function_exists('pll_current_language')) {
                array_push($excluded_taxonomies, 'language', 'post_translations');
            }
            //If we both have taxonomies on the post type AND we've set som excluded taxonomies in the plugins settings. Loop through them and unset those we don't want!
            if ($current_taxonomies && $excluded_taxonomies) {
                foreach ($current_taxonomies as $key => $value) {
                    if (in_array($value['taxonomy'], $excluded_taxonomies)) {
                        unset($current_taxonomies[$key]);
                    }
                }
            }
            foreach ($posttypes_taxonomies as $key => $value) {
                if (in_array($key, $excluded_taxonomies)) {
                    unset($posttypes_taxonomies[$key]);
                }
            }
            ?>
				<?php 
            foreach ($current_taxonomies as $taxonomy) {
                ?>
					<?php 
                if (array_key_exists($taxonomy['taxonomy'], $posttypes_taxonomies)) {
                    unset($posttypes_taxonomies[$taxonomy['taxonomy']]);
                }
                ?>
					<div class="beautiful-taxonomy-filters-single-tax">
						<?php 
                //get the taxonomy object
                $taxonomy_info = get_taxonomy($taxonomy['taxonomy']);
                //Get the terms objects
                $terms = get_terms($taxonomy['taxonomy']);
                //setup an empty array for the actual terms we want.
                $active_terms = array();
                if (!is_wp_error($terms)) {
                    foreach ($terms as $term) {
                        //If the term slugs matches, put it in the array!
                        if (in_array($term->slug, $taxonomy['terms'])) {
                            $active_terms[$term->term_id] = $term->name;
                        }
                    }
                }
                //Implode that sh**t!
                $imploded_terms = implode(', ', $active_terms);
                $label = $taxonomy_info->labels->name . ':';
                ?>
						<span class="single-tax-key"><?php 
                echo apply_filters('beautiful_filters_active_taxonomy', $label, $taxonomy['taxonomy']);
                ?>
</span>
						<span class="single-tax-value"><?php 
                echo apply_filters('beautiful_filters_active_terms', $imploded_terms, $taxonomy['taxonomy']);
                ?>
</span>
					</div>
				<?php 
            }
            ?>
				<?php 
            if (!empty($posttypes_taxonomies)) {
                foreach ($posttypes_taxonomies as $taxonomy) {
                    ?>
					<div class="beautiful-taxonomy-filters-single-tax">
						<?php 
                    $label = $taxonomy->labels->name . ':';
                    $value = $taxonomy->labels->all_items;
                    ?>
						<span class="single-tax-key"><?php 
                    echo apply_filters('beautiful_filters_active_taxonomy', $label, $taxonomy->query_var);
                    ?>
</span>
						<span class="single-tax-value"><?php 
                    echo apply_filters('beautiful_filters_active_terms', $value, $taxonomy->query_var);
                    ?>
</span>
					</div>
				<?php 
                }
            }
            ?>
				
			<?php 
        } else {
            ?>
				
				<?php 
            //Get the taxonomies of the current post type and the excluded taxonomies
            $excluded_taxonomies = apply_filters('beautiful_filters_taxonomies', get_option('beautiful_taxonomy_filters_taxonomies'));
            if (is_array($excluded_taxonomies)) {
                array_push($excluded_taxonomies, 'category', 'post_tag', 'post_format');
            } else {
                $excluded_taxonomies = array('category', 'post_tag', 'post_format');
            }
            //Polylang support
            if (function_exists('pll_current_language')) {
                array_push($excluded_taxonomies, 'language', 'post_translations');
            }
            //If we both have taxonomies on the post type AND we've set som excluded taxonomies in the plugins settings. Loop through them and unset those we don't want!
            if ($posttypes_taxonomies && $excluded_taxonomies) {
                foreach ($posttypes_taxonomies as $key => $value) {
                    if (in_array($key, $excluded_taxonomies)) {
                        unset($posttypes_taxonomies[$key]);
                    }
                }
            }
            ?>
				<?php 
            if ($posttypes_taxonomies) {
                ?>
			
					<?php 
                foreach ($posttypes_taxonomies as $taxonomy) {
                    ?>
						<div class="beautiful-taxonomy-filters-single-tax">
							<?php 
                    $label = $taxonomy->labels->name . ':';
                    $value = $taxonomy->labels->all_items;
                    ?>
							<span class="single-tax-key"><?php 
                    echo apply_filters('beautiful_filters_active_taxonomy', $label, $taxonomy->query_var);
                    ?>
</span>
							<span class="single-tax-value"><?php 
                    echo apply_filters('beautiful_filters_active_terms', $value, $taxonomy->query_var);
                    ?>
</span>
						</div>
					<?php 
                }
                ?>
					
				<?php 
            }
            ?>
			
			<?php 
        }
        ?>
		</div>

		<?php 
        echo $after_widget;
    }
 * @since      1.0.0
 *
 * @package    Beautiful_Taxonomy_Filters
 * @subpackage Beautiful_Taxonomy_Filters/public/partials
 */
/*
 * Filters in this file
 * @ beautiful_filters_active_taxonomy
 * @ beautiful_filters_active_terms
 */
$hide_heading = apply_filters('beautiful_filters_disable_heading', get_option('beautiful_taxonomy_filters_disable_heading'));
$hide_postcount = apply_filters('beautiful_filters_disable_postcount', get_option('beautiful_taxonomy_filters_disable_postcount'));
global $wp_query;
$current_taxonomies = $wp_query->tax_query->queries;
$activated_post_types = apply_filters('beautiful_filters_post_types', get_option('beautiful_taxonomy_filters_post_types'));
$current_post_type = Beautiful_Taxonomy_Filters_Public::get_current_posttype(false);
//If there is no current post type, bail early!
if (!$current_post_type || !in_array($current_post_type, $activated_post_types)) {
    return;
}
?>
<div class="beautiful-taxonomy-filters-active-filter">
	<?php 
do_action('beautiful_actions_beginning_filterinfo', $current_post_type);
//Allow custom markup before filter info
?>
	<?php 
if (!$hide_heading) {
    ?>
		<h3 class="beautiful-taxonomy-filters-info-heading"><?php 
    echo apply_filters('beautiful_filters_info_heading', __('Active filters', 'beautiful-taxonomy-filters'));