MenuFactory.php
2.19 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
<?php
namespace ACP\Admin;
use AC;
use AC\Asset\Location;
use AC\Integration\Filter;
use AC\IntegrationRepository;
use ACP\ActivationTokenFactory;
use ACP\Admin\Page\License;
use ACP\Admin\Page\Tools;
class MenuFactory extends AC\Admin\MenuFactory {
/**
* @var ActivationTokenFactory
*/
private $activation_token_factory;
/**
* @var IntegrationRepository
*/
private $integration_repository;
public function __construct(
$url,
Location\Absolute $location,
ActivationTokenFactory $activation_token_factory,
IntegrationRepository $integration_repository
) {
parent::__construct( (string) $url, $location );
$this->activation_token_factory = $activation_token_factory;
$this->integration_repository = $integration_repository;
}
public function get_inactive_addon_count() {
return $this->integration_repository->find_all( [
IntegrationRepository::ARG_FILTER => [
new Filter\IsNotActive( is_multisite(), is_network_admin() ),
new Filter\IsInstalled(),
new Filter\IsPluginActive(),
],
] )->count();
}
public function create( $current ) {
$menu = parent::create( $current );
$menu->remove_item( 'pro' );
$menu->add_item(
new AC\Admin\Menu\Item(
Tools::NAME,
$this->create_menu_link( Tools::NAME ),
__( 'Tools', 'codepress-admin-columns' ),
$current === Tools::NAME ? '-active' : ''
)
);
$addons = $menu->get_item_by_slug( Page\Addons::NAME );
if ( $addons ) {
$menu->add_item( new AC\Admin\Menu\Item(
$addons->get_slug(),
$addons->get_url(),
$addons->get_label(),
$addons->get_class(),
$addons->get_target()
) );
}
if ( $this->show_license_section() ) {
$label = __( 'License', 'codepress-admin-columns' );
if ( ! $this->activation_token_factory->create() ) {
$label = sprintf( '%s <span class="ac-badge">%s</span>', $label, '1' );
}
$menu->add_item(
new AC\Admin\Menu\Item(
License::NAME,
$this->create_menu_link( License::NAME ),
$label,
$current === License::NAME ? '-active' : ''
)
);
}
do_action( 'acp/admin/page/menu', $menu );
return $menu;
}
private function show_license_section() {
return (bool) apply_filters( 'acp/display_licence', true );
}
}