TaxonomyParent.php
1.45 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
<?php
namespace ACP\Column\Taxonomy;
use AC;
use ACP\ConditionalFormat;
use ACP\Editing;
use ACP\Filtering;
class TaxonomyParent extends AC\Column
implements Editing\Editable, Filtering\Filterable, ConditionalFormat\Formattable {
use ConditionalFormat\ConditionalFormatTrait;
public function __construct() {
$this->set_type( 'column-term_parent' );
$this->set_label( __( 'Parent', 'codepress-admin-columns' ) );
}
public function get_value( $id ) {
$term_parent_id = $this->get_raw_value( $id );
if ( ! $term_parent_id ) {
return $this->get_empty_char();
}
$parent = get_term( $term_parent_id, $this->get_taxonomy() );
if ( ! $parent || is_wp_error( $parent ) ) {
return $this->get_empty_char();
}
return $this->get_formatted_value( $parent, $parent );
}
public function get_raw_value( $term_id ) {
$term = get_term( $term_id, $this->get_taxonomy() );
if ( ! $term || is_wp_error( $term ) || 0 === $term->parent ) {
return false;
}
return $term->parent;
}
public function editing() {
return new Editing\Service\Taxonomy\TaxonomyParent( $this->get_taxonomy() );
}
public function filtering() {
return new Filtering\Model\Taxonomy\TaxonomyParent( $this );
}
public function is_valid() {
return is_taxonomy_hierarchical( $this->get_taxonomy() );
}
public function register_settings() {
$this->add_setting( new AC\Settings\Column\Term( $this ) );
$this->add_setting( new AC\Settings\Column\TermLink( $this ) );
}
}