Term.php
1.32 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
<?php
namespace ACP\Settings\Column;
use AC;
use AC\View;
class Term extends AC\Settings\Column {
const NAME = 'term_id';
/**
* @var int
*/
private $term_id;
/**
* @var string
*/
private $taxonomy;
public function __construct( AC\Column $column, $taxonomy ) {
$this->taxonomy = $taxonomy;
parent::__construct( $column );
}
/**
* @return string
*/
protected function get_taxonomy() {
return $this->taxonomy;
}
protected function define_options() {
return [ self::NAME ];
}
/**
* @return View
*/
public function create_view() {
$taxonomy = $this->create_element( 'select', 'term_id' );
$taxonomy->set_no_result( __( 'No terms available.', 'codepress-admin-columns' ) )
->set_options( $this->get_term_for_post_type() );
return new View( [
'setting' => $taxonomy,
'label' => __( 'Term', 'codepress-admin-columns' ),
] );
}
/**
* @return int
*/
public function get_term_id() {
return $this->term_id;
}
/**
* @param int $term_id
*
* @return bool
*/
public function set_term_id( $term_id ) {
$this->term_id = $term_id;
return true;
}
private function get_term_for_post_type() {
$terms = get_terms( $this->get_taxonomy() );
$options = [];
foreach ( $terms as $term ) {
$options[ $term->term_id ] = $term->name;
}
return $options;
}
}