taxonomy.php
2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* Taxonomy column, displaying terms from a taxonomy for any object type (i.e. posts)
* supporting WordPress' native way of handling terms.
*
* @since 2.0
*/
class CPAC_Column_Taxonomy extends CPAC_Column {
/**
* @see CPAC_Column::init()
* @since 2.2.1
*/
public function init() {
parent::init();
// Properties
$this->properties['type'] = 'column-taxonomy';
$this->properties['label'] = __( 'Taxonomy', 'codepress-admin-columns' );
$this->properties['is_cloneable'] = true;
// Options
$this->options['taxonomy'] = ''; // Taxonomy slug
}
/**
* @see CPAC_Column::get_value()
* @since 2.0
*/
public function get_value( $post_id ) {
$term_ids = $this->get_raw_value( $post_id );
return $this->get_terms_for_display( $term_ids, $this->options->taxonomy );
}
/**
* @see CPAC_Column::get_raw_value()
* @since 2.0.3
*/
public function get_raw_value( $post_id ) {
return wp_get_post_terms( $post_id, $this->options->taxonomy, array( 'fields' => 'ids' ) );
}
/**
* @see CPAC_Column::get_value()
* @since 2.3.4
*/
public function get_taxonomy() {
return $this->options->taxonomy;
}
/**
* @see CPAC_Column::apply_conditional()
* @since 2.0
*/
public function apply_conditional() {
$post_type = $this->get_post_type();
if ( ! $post_type || ! get_object_taxonomies( $post_type ) ) {
return false;
}
return true;
}
/**
* Display Settings
*
* @see CPAC_Column::display_settings()
* @since 2.0
*/
public function display_settings() {
$taxonomies = get_object_taxonomies( $this->get_post_type(), 'objects' );
foreach ( $taxonomies as $index => $taxonomy ) {
if ( $taxonomy->name == 'post_format' ) {
unset( $taxonomies[ $index ] );
}
}
?>
<tr class="column_taxonomy">
<?php $this->label_view( __( "Taxonomy", 'codepress-admin-columns' ), '', 'taxonomy' ); ?>
<td class="input">
<select name="<?php $this->attr_name( 'taxonomy' ); ?>" id="<?php $this->attr_id( 'taxonomy' ); ?>">
<?php foreach ( $taxonomies as $taxonomy ) : ?>
<option value="<?php echo $taxonomy->name; ?>"<?php selected( $taxonomy->name, $this->options->taxonomy ) ?>><?php echo $taxonomy->label; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php
}
}