Forked from elimn/Tribe__Events__Filterbar__Filters__Category_Custom.php
Created
November 4, 2022 20:21
-
-
Save kodie/8deb85f673c7beb57c3ca81a0495982a to your computer and use it in GitHub Desktop.
MT | TEC | Customized version of the Category Filter that includes CSS classes for subcategories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Customized version of the Category Filter that includes CSS classes for subcategories | |
* New filter available in WP-Admin > Events > Settings > Filters | |
*/ | |
if ( class_exists( 'Tribe__Events__Filterbar__Filters__Category' ) ) { | |
class Tribe__Events__Filterbar__Filters__Category_Custom extends Tribe__Events__Filterbar__Filters__Category { | |
/** | |
* Flatten out the hierarchical list of event categories into a single list of values, | |
* applying formatting (non-breaking spaces) to help indicate the depth of each nested | |
* item. | |
* | |
* @param array $term_items | |
* @param array $existing_list | |
* @return array | |
*/ | |
protected function flattened_term_list( array $term_items, array $existing_list = null ) { | |
// Pull in the existing list when called recursively | |
$flat_list = is_array( $existing_list ) ? $existing_list : array(); | |
// Add each item - including nested items - to the flattened list | |
foreach ( $term_items as $term ) { | |
$flat_list[] = array( | |
'name' => $term->name, | |
'value' => $term->term_id, | |
'data' => array( 'slug' => $term->slug ), | |
'class' => 'tribe-events-category-' . $term->slug . ' tribe-events-subcategory-depth-' . $term->depth, | |
); | |
if ( ! empty( $term->children ) ) { | |
$child_items = $this->flattened_term_list( $term->children, $existing_list ); | |
$flat_list = array_merge( $flat_list, $child_items ); | |
} | |
} | |
return $flat_list; | |
} | |
} | |
new Tribe__Events__Filterbar__Filters__Category_Custom( __( 'Category Custom', 'tribe-events-filter-view' ), 'categorycustom' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment