PluginProbe
Admin and Site Enhancements (ASE) / 9.0.2
Admin and Site Enhancements (ASE) v9.0.2
9.1.1 9.1.0 9.0.2 9.0.1 9.0.0 8.9.2 8.9.1 8.9.0 8.8.8 8.8.7 8.8.6 8.8.5 8.8.4 8.8.3 8.8.2 8.8.1 8.8.0 8.7.3 8.7.2 8.7.1 8.2.1 8.2.2 8.2.3 8.3.0 8.3.1 All 273 releases
admin-site-enhancements / classes / class-show-custom-taxonomy-filters.php
class-show-custom-taxonomy-filters.php
72 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ASENHA\Classes;
4
5 /**
6 * Class for Show Custom Taxonomy Filters module
7 *
8 * @since 6.9.5
9 */
10 class Show_Custom_Taxonomy_Filters {
11 // Excluded taxonomies
12 private $inapplicable_taxonomies = array(
13 'category',
14 // Post Categories
15 'product_cat',
16 // WooCommerce Product Categories
17 'asenha_code_snippet_category',
18 // ASE Code Snippets Categories
19 'asenha-media-category',
20 );
21
22 /**
23 * Show custom (hierarchical) taxonomy filter(s) for all post types.
24 *
25 * @since 1.0.0
26 */
27 public function show_custom_taxonomy_filters( $post_type ) {
28 $object_taxonomies = get_object_taxonomies( $post_type, 'objects' );
29 array_walk( $object_taxonomies, [$this, 'output_taxonomy_filter'] );
30 }
31
32 /**
33 * Output filter on the post type's list table for a taxonomy
34 *
35 * @since 1.0.0
36 */
37 public function output_taxonomy_filter( $taxonomy ) {
38 // Show filter if taxonomy is hierarchical
39 if ( true === $taxonomy->hierarchical && !in_array( $taxonomy->name, $this->inapplicable_taxonomies ) ) {
40 $this->render_additional_filter( $taxonomy );
41 }
42 }
43
44 /**
45 * Render additional filter
46 *
47 * @since 6.9.7
48 */
49 public function render_additional_filter( $taxonomy ) {
50 $show_option_all_label = sprintf( 'All %s', ucwords( $taxonomy->label ) );
51 if ( property_exists( $taxonomy, 'labels' ) ) {
52 $taxonomy_labels = $taxonomy->labels;
53 if ( property_exists( $taxonomy_labels, 'all_items' ) && !empty( $taxonomy_labels->all_items ) ) {
54 $show_option_all_label = $taxonomy->labels->all_items;
55 }
56 }
57 wp_dropdown_categories( array(
58 'show_option_all' => $show_option_all_label,
59 'orderby' => 'name',
60 'order' => 'ASC',
61 'hide_empty' => false,
62 'hide_if_empty' => true,
63 'selected' => sanitize_text_field( ( isset( $_GET[$taxonomy->query_var] ) && !empty( $_GET[$taxonomy->query_var] ) ? sanitize_text_field( $_GET[$taxonomy->query_var] ) : '' ) ),
64 'hierarchical' => true,
65 'name' => $taxonomy->query_var,
66 'taxonomy' => $taxonomy->name,
67 'value_field' => 'slug',
68 ) );
69 }
70
71 }
72