NativeTaxonomies.php
1.35 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
<?php
namespace ACP;
use AC\ListScreen;
use AC\ListScreenPost;
use AC\Registrable;
class NativeTaxonomies implements Registrable {
public function register() {
add_action( 'ac/column_types', [ $this, 'register_columns' ] );
}
/**
* @param ListScreen $list_screen
*/
public function register_columns( ListScreen $list_screen ) {
$this->register_column_native_taxonomies( $list_screen );
/**
* @deprecated 4.1 Use 'ac/column_types'
*/
do_action( 'acp/column_types', $list_screen );
}
/**
* Register Taxonomy columns that are set by WordPress. These native columns are registered
* by setting 'show_admin_column' to 'true' as an argument in register_taxonomy();
* Only supports Post Types.
*
* @param ListScreen $list_screen
*
* @see register_taxonomy
*/
private function register_column_native_taxonomies( ListScreen $list_screen ) {
if ( ! $list_screen instanceof ListScreenPost ) {
return;
}
$taxonomies = get_taxonomies(
[
'show_ui' => 1,
'show_admin_column' => 1,
'_builtin' => 0,
],
'object'
);
foreach ( $taxonomies as $taxonomy ) {
if ( in_array( $list_screen->get_post_type(), $taxonomy->object_type ) ) {
$column = new Column\NativeTaxonomy();
$column->set_type( 'taxonomy-' . $taxonomy->name );
$list_screen->register_column_type( $column );
}
}
}
}