AddonAvailable.php
1.97 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
<?php
namespace AC\Check;
use AC\Ajax;
use AC\Capabilities;
use AC\Integration;
use AC\Message\Notice\Dismissible;
use AC\Preferences;
use AC\Registerable;
use AC\Screen;
final class AddonAvailable
implements Registerable
{
private $integration;
public function __construct(Integration $integration)
{
$this->integration = $integration;
}
public function register(): void
{
add_action('ac/screen', [$this, 'display']);
$this->get_ajax_handler()->register();
}
private function get_ajax_handler(): Ajax\Handler
{
$handler = new Ajax\Handler();
$handler
->set_action('ac_dismiss_notice_addon_' . $this->integration->get_slug())
->set_callback([$this, 'ajax_dismiss_notice']);
return $handler;
}
private function get_preferences(): Preferences\User
{
return new Preferences\User('check-addon-available-' . $this->integration->get_slug());
}
public function ajax_dismiss_notice(): void
{
$this->get_ajax_handler()->verify_request();
$this->get_preferences()->set('dismiss-notice', true);
}
public function display(Screen $screen): void
{
if (
! current_user_can(Capabilities::MANAGE)
|| ! $this->integration->show_notice($screen)
|| $this->get_preferences()->get('dismiss-notice')
) {
return;
}
$support_text = sprintf(
__('Did you know Admin Columns Pro has full support for %s?', 'codepress-admin-columns'),
sprintf('<strong>%s</strong>', $this->integration->get_title())
);
$link = sprintf(
'<a href="%s">%s</a>',
'https://www.google.com',
__('Get Admin Columns Pro', 'codepress-admin-columns')
);
$message = sprintf('%s %s', $support_text, $link);
$notice = new Dismissible($message, $this->get_ajax_handler());
$notice->register();
}
}