Taxonomy.php
4.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
namespace ACP\ListScreen;
use AC;
use AC\WpListTableFactory;
use ACP\Column;
use ACP\Editing;
use ACP\Editing\BulkDelete\Deletable;
use ACP\Export;
use ACP\Filtering;
use ACP\Sorting;
use WP_Term;
use WP_Terms_List_Table;
class Taxonomy extends AC\ListScreenWP
implements Editing\ListScreen, Export\ListScreen, Filtering\ListScreen, Sorting\ListScreen, Editing\BulkDelete\ListScreen {
/**
* @var string
*/
private $taxonomy;
/**
* @param string $taxonomy
*/
public function __construct( $taxonomy ) {
$this->set_taxonomy( $taxonomy )
->set_meta_type( AC\MetaType::TERM )
->set_screen_base( 'edit-tags' )
->set_screen_id( 'edit-' . $taxonomy )
->set_key( 'wp-taxonomy_' . $taxonomy )
->set_group( 'taxonomy' );
}
public function deletable() {
return new Deletable\Taxonomy( $this->get_taxonomy() );
}
/**
* @param string $taxonomy
*
* @return self
*/
protected function set_taxonomy( $taxonomy ) {
$this->taxonomy = (string) $taxonomy;
return $this;
}
/**
* @return string
*/
public function get_taxonomy() {
return $this->taxonomy;
}
/**
* @see WP_Terms_List_Table::column_default
*/
public function set_manage_value_callback() {
add_action( "manage_" . $this->get_taxonomy() . "_custom_column", [ $this, 'manage_value' ], 10, 3 );
}
/**
* @return WP_Terms_List_Table
*/
protected function get_list_table() {
return ( new WpListTableFactory() )->create_taxonomy_table( $this->get_screen_id() );
}
/**
* @param int $term_id
*
* @return WP_Term
* @since 4.0
*/
protected function get_object( $term_id ) {
return get_term_by( 'id', $term_id, $this->get_taxonomy() );
}
/**
* @return string|false
*/
public function get_label() {
return $this->get_taxonomy_label_var( 'name' );
}
/**
* @return false|string
*/
public function get_singular_label() {
return $this->get_taxonomy_label_var( 'singular_name' );
}
/**
* @param $wp_screen
*
* @return bool
* @since 3.7.3
*/
public function is_current_screen( $wp_screen ) {
return parent::is_current_screen( $wp_screen ) && $this->get_taxonomy() === filter_input( INPUT_GET, 'taxonomy' );
}
/**
* Get screen link
* @return string Link
* @since 1.2.0
*/
public function get_screen_link() {
$post_type = null;
if ( $object_type = $this->get_taxonomy_var( 'object_type' ) ) {
if ( post_type_exists( reset( $object_type ) ) ) {
$post_type = $object_type[0];
}
}
return add_query_arg( [ 'taxonomy' => $this->get_taxonomy(), 'post_type' => $post_type ], parent::get_screen_link() );
}
/**
* Manage value
*
* @param string $value
* @param string $column_name
* @param int $term_id
*
* @return string
* @since 1.2.0
*/
public function manage_value( $value, $column_name, $term_id ) {
return $this->get_display_value_by_column_name( $column_name, $term_id, $value );
}
/**
* @param $var
*
* @return string|false
*/
private function get_taxonomy_label_var( $var ) {
$taxonomy = get_taxonomy( $this->get_taxonomy() );
return $taxonomy && isset( $taxonomy->labels->{$var} ) ? $taxonomy->labels->{$var} : false;
}
private function get_taxonomy_var( $var ) {
$taxonomy = get_taxonomy( $this->get_taxonomy() );
return $taxonomy && isset( $taxonomy->{$var} ) ? $taxonomy->{$var} : false;
}
protected function register_column_types() {
$this->register_column_types_from_list( [
Column\CustomField::class,
Column\Actions::class,
Column\Taxonomy\Count::class,
Column\Taxonomy\CountForPostType::class,
Column\Taxonomy\CustomDescription::class,
Column\Taxonomy\Description::class,
Column\Taxonomy\Excerpt::class,
Column\Taxonomy\ID::class,
Column\Taxonomy\Links::class,
Column\Taxonomy\Menu::class,
Column\Taxonomy\Name::class,
Column\Taxonomy\Posts::class,
Column\Taxonomy\Slug::class,
Column\Taxonomy\TaxonomyParent::class,
] );
}
public function editing() {
return new Editing\Strategy\Taxonomy( $this->taxonomy );
}
public function filtering( $model ) {
return new Filtering\Strategy\Taxonomy( $model );
}
public function sorting( $model ) {
return new Sorting\Strategy\Taxonomy( $model, $this->get_taxonomy() );
}
public function export() {
return new Export\Strategy\Taxonomy( $this );
}
}