HasTerm.php
1.37 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
<?php
namespace ACP\Column\Post;
use AC;
use ACP\Search;
use ACP\Settings;
class HasTerm extends AC\Column implements Search\Searchable {
public function __construct() {
$this->set_type( 'column-has_term' )
->set_label( __( 'Has Term', 'codepress-admin-columns' ) );
}
public function get_value( $id ) {
return ac_helper()->icon->yes_or_no( $this->get_raw_value( $id ) );
}
public function get_raw_value( $id ) {
$setting = $this->get_taxonomy_setting();
return $setting && has_term( $setting->get_term_id(), $setting->get_taxonomy(), $id );
}
/**
* @return bool True when post type has associated taxonomies
*/
public function is_valid() {
return get_object_taxonomies( $this->get_post_type() ) ? true : false;
}
/**
* @return Settings\Column\Post\TaxonomyTerm|null
*/
public function get_taxonomy_setting() {
$setting = $this->get_setting( Settings\Column\Post\TaxonomyTerm::NAME );
return $setting instanceof Settings\Column\Post\TaxonomyTerm
? $setting
: null;
}
protected function register_settings() {
parent::register_settings();
$this->add_setting( new Settings\Column\Post\TaxonomyTerm( $this, $this->get_post_type() ) );
}
public function search() {
$setting = $this->get_taxonomy_setting();
return $setting
? new Search\Comparison\Post\HasTerm( $setting->get_taxonomy(), $setting->get_term_id() )
: false;
}
}