PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 3.0
Admin Columns v3.0
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
Array.php 9 years ago Date.php 9 years ago File.php 9 years ago Html.php 9 years ago Icon.php 9 years ago Image.php 9 years ago Network.php 9 years ago Post.php 9 years ago String.php 9 years ago Taxonomy.php 9 years ago User.php 9 years ago
Taxonomy.php
137 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class AC_Helper_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 array();
18 }
19
20 $values = array();
21
22 foreach ( $terms as $t ) {
23 if ( ! is_a( $t, 'WP_Term' ) ) {
24 continue;
25 }
26
27 $args = array(
28 'post_type' => $post_type,
29 'taxonomy' => $t->taxonomy,
30 'term' => $t->slug,
31 );
32
33 $page = 'attachment' === $post_type ? 'upload' : 'edit';
34
35 $values[] = ac_helper()->html->link( add_query_arg( $args, $page . '.php' ), sanitize_term_field( 'name', $t->name, $t->term_id, $t->taxonomy, 'display' ) );
36 }
37
38 return $values;
39 }
40
41 /**
42 * @param WP_Term $term
43 *
44 * @return false|string
45 */
46 public function get_term_display_name( $term ) {
47 if ( ! $term || is_wp_error( $term ) ) {
48 return false;
49 }
50
51 return sanitize_term_field( 'name', $term->name, $term->term_id, $term->taxonomy, 'display' );
52 }
53
54 /**
55 * @param string $object_type post, page, user etc.
56 * @param string $taxonomy Taxonomy Name
57 *
58 * @return bool
59 */
60 public function is_taxonomy_registered( $object_type, $taxonomy = '' ) {
61 if ( ! $object_type ) {
62 return false;
63 }
64 $taxonomies = get_object_taxonomies( $object_type );
65
66 if ( ! $taxonomies ) {
67 return false;
68 }
69
70 if ( $taxonomy ) {
71 return in_array( $taxonomy, $taxonomies );
72 }
73
74 return true;
75 }
76
77 /**
78 * @since 3.0
79 */
80 public function get_taxonomy_selection_options( $post_type ) {
81 $taxonomies = get_object_taxonomies( $post_type, 'objects' );
82
83 $options = array();
84 foreach ( $taxonomies as $index => $taxonomy ) {
85 if ( $taxonomy->name == 'post_format' ) {
86 unset( $taxonomies[ $index ] );
87 }
88 $options[ $taxonomy->name ] = $taxonomy->label;
89 }
90
91 natcasesort( $options );
92
93 return $options;
94 }
95
96 /**
97 * @param string $field
98 * @param int $term_id
99 * @param string $taxonomy
100 *
101 * @since 3.0
102 */
103 public function get_term_field( $field, $term_id, $taxonomy ) {
104 $term = get_term_by( 'id', $term_id, $taxonomy );
105
106 if ( ! $term || is_wp_error( $term ) ) {
107 return false;
108 }
109
110 if ( ! isset( $term->{$field} ) ) {
111 return false;
112 }
113
114 return $term->{$field};
115 }
116
117 /**
118 * @param int $term_ids
119 * @param string $taxonomy
120 *
121 * @return WP_Term[]
122 */
123 public function get_terms_by_ids( $term_ids, $taxonomy ) {
124 $terms = array();
125
126 foreach ( (array) $term_ids as $term_id ) {
127 $term = get_term( $term_id, $taxonomy );
128 if ( $term && ! is_wp_error( $term ) ) {
129 $terms[] = $term;
130 }
131 }
132
133 return $terms;
134 }
135
136 }
137