ListKeysFactory.php
1.39 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
<?php
declare( strict_types=1 );
namespace ACP\Table;
use AC;
use AC\Table\ListKeyCollection;
use AC\Type\ListKey;
use ACP\ListScreen\Taxonomy;
use WP_Taxonomy;
class ListKeysFactory implements AC\Table\ListKeysFactoryInterface {
/**
* @var AC\Table\ListKeysFactory
*/
private $factory;
public function __construct( AC\Table\ListKeysFactory $factory ) {
$this->factory = $factory;
}
public function create(): ListKeyCollection {
$keys = $this->factory->create();
foreach ( $this->get_taxonomies() as $taxonomy ) {
$keys->add( new ListKey( Taxonomy::KEY_PREFIX . $taxonomy->name ) );
}
// Network
$keys->add( new ListKey( 'wp-ms_users' ) );
$keys->add( new ListKey( 'wp-ms_sites' ) );
do_action( 'acp/list_keys', $keys );
return $keys;
}
private function get_taxonomies(): array {
$taxonomies = [];
foreach ( $this->get_taxonomy_names() as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name );
if ( ! $taxonomy instanceof WP_Taxonomy ) {
continue;
}
$taxonomies[] = $taxonomy;
}
return $taxonomies;
}
/**
* @return string[]
*/
private function get_taxonomy_names(): array {
$taxonomies = get_taxonomies( [ 'show_ui' => true ] );
unset( $taxonomies['post_format'] );
if ( ! get_option( 'link_manager_enabled' ) ) {
unset( $taxonomies['link_category'] );
}
return (array) apply_filters( 'acp/taxonomies', $taxonomies );
}
}