PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Helper / Taxonomy.php
codepress-admin-columns / classes / Helper Last commit date
Image 2 days ago Select 2 days ago Arrays.php 2 days ago AvailableTranslations.php 2 days ago Creatable.php 2 days ago Dashicon.php 2 days ago Date.php 2 days ago Html.php 2 days ago Icon.php 2 days ago Image.php 2 days ago LocalFile.php 2 days ago Mbstring.php 2 days ago MediaIdResolver.php 2 days ago Menu.php 2 days ago Network.php 2 days ago Post.php 2 days ago Strings.php 2 days ago Taxonomy.php 2 days ago User.php 2 days ago UserRoles.php 2 days ago WpDateFormat.php 2 days ago
Taxonomy.php
117 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Helper;
6
7 use WP_Taxonomy;
8 use WP_Term;
9
10 class Taxonomy extends Creatable
11 {
12 public function get_term_links(array $terms, ?string $post_type = null): array
13 {
14 $values = [];
15
16 foreach ($terms as $term) {
17 if (! $term instanceof WP_Term) {
18 continue;
19 }
20
21 $values[] = Html::create()->link(
22 $this->get_filter_by_term_url($term, $post_type),
23 $this->get_term_display_name($term)
24 );
25 }
26
27 return $values;
28 }
29
30 public function get_filter_by_term_url(WP_Term $term, ?string $post_type = null): string
31 {
32 $args = [
33 'taxonomy' => $term->taxonomy,
34 'term' => $term->slug,
35 ];
36
37 if ($post_type) {
38 $args['post_type'] = $post_type;
39 }
40
41 $page = 'attachment' === $post_type
42 ? 'upload.php'
43 : 'edit.php';
44
45 return add_query_arg(
46 $args,
47 $page
48 );
49 }
50
51 public function get_term_display_name(WP_Term $term): string
52 {
53 return (string)sanitize_term_field('name', $term->name, $term->term_id, $term->taxonomy, 'display');
54 }
55
56 public function get_term_field(string $field, int $term_id, string $taxonomy): ?string
57 {
58 $term = get_term_by('id', $term_id, $taxonomy);
59
60 if (! $term instanceof WP_Term) {
61 return null;
62 }
63
64 if (! isset($term->{$field})) {
65 return null;
66 }
67
68 return (string)$term->{$field};
69 }
70
71 public function get_taxonomy_selection_options(string $post_type): array
72 {
73 $taxonomies = get_object_taxonomies($post_type, 'objects');
74
75 $options = [];
76
77 foreach ($taxonomies as $taxonomy) {
78 if ($taxonomy->name === 'post_format') {
79 continue;
80 }
81
82 $options[$taxonomy->name] = $taxonomy->label;
83 }
84
85 natcasesort($options);
86
87 return $options;
88 }
89
90 public function get_terms_by_ids(array $term_ids, string $taxonomy): array
91 {
92 $terms = [];
93
94 foreach ($term_ids as $term_id) {
95 $term = get_term((int)$term_id, $taxonomy);
96
97 if ($term instanceof WP_Term) {
98 $terms[] = $term;
99 }
100 }
101
102 return $terms;
103 }
104
105 public function get_taxonomy_label(string $taxonomy, string $property = 'name'): string
106 {
107 $taxonomy_object = get_taxonomy($taxonomy);
108
109 if (! $taxonomy_object instanceof WP_Taxonomy) {
110 return $taxonomy;
111 }
112
113 return get_taxonomy_labels($taxonomy_object)->$property ?? $taxonomy;
114 }
115
116 }
117