PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 4.4.1
Admin Columns v4.4.1
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
Select 4 years ago Arrays.php 4 years ago Date.php 4 years ago File.php 4 years ago Html.php 4 years ago Icon.php 4 years ago Image.php 4 years ago Media.php 4 years ago Menu.php 4 years ago Network.php 4 years ago Post.php 4 years ago Strings.php 4 years ago Taxonomy.php 4 years ago User.php 4 years ago
Taxonomy.php
156 lines
1 <?php
2
3 namespace AC\Helper;
4
5 use WP_Term;
6
7 class Taxonomy {
8
9 /**
10 * @param WP_Term[] $terms Term objects
11 * @param null|string $post_type
12 *
13 * @return array
14 */
15 public function get_term_links( $terms, $post_type = null ) {
16 if ( ! $terms || is_wp_error( $terms ) ) {
17 return [];
18 }
19
20 $values = [];
21
22 foreach ( $terms as $t ) {
23 if ( ! $t instanceof WP_Term ) {
24 continue;
25 }
26
27 $values[] = ac_helper()->html->link( $this->get_term_url( $t, $post_type ), sanitize_term_field( 'name', $t->name, $t->term_id, $t->taxonomy, 'display' ) );
28 }
29
30 return $values;
31 }
32
33 public function get_term_url( $term, $post_type = null ) {
34 if ( is_numeric( $term ) ) {
35 $term = get_term_by( 'term_taxonomy_id', $term );
36 }
37
38 $args = [
39 'post_type' => $post_type,
40 'taxonomy' => $term->taxonomy,
41 'term' => $term->slug,
42 ];
43
44 $page = 'attachment' === $post_type ? 'upload' : 'edit';
45
46 return add_query_arg( $args, $page . '.php' );
47 }
48
49 /**
50 * @param WP_Term $term
51 *
52 * @return false|string
53 */
54 public function get_term_display_name( $term ) {
55 if ( ! $term || is_wp_error( $term ) ) {
56 return false;
57 }
58
59 return sanitize_term_field( 'name', $term->name, $term->term_id, $term->taxonomy, 'display' );
60 }
61
62 /**
63 * @param string $object_type post, page, user etc.
64 * @param string $taxonomy Taxonomy Name
65 *
66 * @return bool
67 */
68 public function is_taxonomy_registered( $object_type, $taxonomy = '' ) {
69 if ( ! $object_type || ! $taxonomy ) {
70 return false;
71 }
72
73 return is_object_in_taxonomy( $object_type, $taxonomy );
74 }
75
76 /**
77 * @param string $field
78 * @param int $term_id
79 * @param string $taxonomy
80 *
81 * @return bool|mixed
82 * @since 3.0
83 */
84 public function get_term_field( $field, $term_id, $taxonomy ) {
85 $term = get_term_by( 'id', $term_id, $taxonomy );
86
87 if ( ! $term || is_wp_error( $term ) ) {
88 return false;
89 }
90
91 if ( ! isset( $term->{$field} ) ) {
92 return false;
93 }
94
95 return $term->{$field};
96 }
97
98 /**
99 * @param $post_type
100 *
101 * @return array
102 * @since 3.0
103 */
104 public function get_taxonomy_selection_options( $post_type ) {
105 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
106
107 $options = [];
108 foreach ( $taxonomies as $index => $taxonomy ) {
109 if ( $taxonomy->name == 'post_format' ) {
110 unset( $taxonomies[ $index ] );
111 }
112 $options[ $taxonomy->name ] = $taxonomy->label;
113 }
114
115 natcasesort( $options );
116
117 return $options;
118 }
119
120 /**
121 * @param int $term_ids
122 * @param string $taxonomy
123 *
124 * @return WP_Term[]
125 */
126 public function get_terms_by_ids( $term_ids, $taxonomy ) {
127 $terms = [];
128
129 foreach ( (array) $term_ids as $term_id ) {
130 $term = get_term( $term_id, $taxonomy );
131 if ( $term && ! is_wp_error( $term ) ) {
132 $terms[] = $term;
133 }
134 }
135
136 return $terms;
137 }
138
139 public function get_taxonomy_label( $taxonomy, $key = 'name' ) {
140 $label = $taxonomy;
141 $taxonomy_object = get_taxonomy( $taxonomy );
142
143 if ( ! $taxonomy_object ) {
144 return $label;
145 }
146
147 $labels = get_taxonomy_labels( $taxonomy_object );
148
149 if ( property_exists( $labels, $key ) ) {
150 $label = $labels->$key;
151 }
152
153 return $label;
154 }
155
156 }