PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.1.4
Admin Columns v7.1.4
7.1.4 7.0.19 2.3.5 2.4 2.4.1 2.4.10 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.6.1 2.5.6.2 2.5.6.3 2.5.6.4 3.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.7 3.1 3.1.1 3.1.10 3.1.2 3.1.3 3.1.5 3.2.3 3.2.7 3.3.1 3.4.1 3.4.6 3.4.8 4.0.1 4.0.3 4.1.6 4.2.2 4.2.5 4.3 4.3.2 4.4.1 4.4.4 4.4.5 4.5.5 4.6.1 4.7.18 4.7.19 4.7.20 4.7.7 7.0.13 7.0.14 7.0.16 trunk 1.0 1.1 1.1.3 1.2 1.2.1 1.3 1.3.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.5.1 1.4.6 1.4.6.1 1.4.6.2 1.4.6.3 1.4.6.4 1.4.7 1.4.8 1.4.9 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2 2.2.1 2.2.1.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.5.1 2.2.6 2.2.6.1 2.2.6.2 2.2.6.3 2.2.6.4 2.2.7 2.2.8 2.2.8.1 2.2.9 2.3.1 2.3.2 2.3.3
codepress-admin-columns / classes / Check / Integration / IntegrationNoticeRenderer.php
codepress-admin-columns / classes / Check / Integration Last commit date
AcfBulkEditNotice.php 2 days ago AcfNotice.php 2 days ago AcfSortAndFilterNotice.php 2 days ago EventsCalendarNotice.php 2 days ago GravityFormsNotice.php 2 days ago IntegrationNotice.php 2 days ago IntegrationNoticeRenderer.php 2 days ago PostEditReferrerAware.php 2 days ago UsageAwareNotice.php 2 days ago WooCommerceOrdersFilterNotice.php 2 days ago WooCommerceOrdersNotice.php 2 days ago WooCommerceOrdersScreenAware.php 2 days ago WooCommerceOrdersSearchNotice.php 2 days ago WooCommerceProductsBulkEditNotice.php 2 days ago WooCommerceProductsFilterNotice.php 2 days ago WooCommerceProductsNotice.php 2 days ago WooCommerceProductsSearchNotice.php 2 days ago
IntegrationNoticeRenderer.php
145 lines
1 <?php
2
3 declare(strict_types=1);
4
5 namespace AC\Check\Integration;
6
7 use AC\Ajax;
8 use AC\Asset\Script;
9 use AC\Asset\Style;
10 use AC\Capabilities;
11 use AC\Notice\NoticeState;
12 use AC\Registerable;
13 use AC\Screen;
14 use AC\View;
15
16 class IntegrationNoticeRenderer implements Registerable
17 {
18 /**
19 * @var IntegrationNotice[]
20 */
21 private array $notices;
22
23 private NoticeState $state;
24
25 /**
26 * @param IntegrationNotice[] $notices
27 */
28 public function __construct(array $notices, NoticeState $state)
29 {
30 $this->notices = $notices;
31 $this->state = $state;
32 }
33
34 public function register(): void
35 {
36 if (! current_user_can(Capabilities::MANAGE)) {
37 return;
38 }
39
40 foreach ($this->notices as $notice) {
41 $handler = $this->create_ajax_handler($notice);
42 $handler->register();
43 }
44
45 add_action('ac/screen', [$this, 'display']);
46 }
47
48 public function display(Screen $screen): void
49 {
50 $notice = $this->resolve($screen);
51
52 if (! $notice) {
53 return;
54 }
55
56 $handler = $this->create_ajax_handler($notice);
57
58 add_action('admin_notices', function () use ($notice, $handler) {
59 echo $this->render($notice, $handler);
60 });
61
62 add_action('admin_enqueue_scripts', static function () {
63 (new Style('ac-message'))->enqueue();
64 (new Script('ac-message'))->enqueue();
65 });
66 }
67
68 private function resolve(Screen $screen): ?IntegrationNotice
69 {
70 foreach ($this->notices as $notice) {
71 if ($notice->is_active($screen)) {
72 $this->state->track_first_seen($notice->get_slug());
73 }
74 }
75
76 foreach ($this->notices as $notice) {
77 if ($notice->is_active($screen) && $this->is_ready_to_show($notice)) {
78 return $notice;
79 }
80 }
81
82 return null;
83 }
84
85 private function is_ready_to_show(IntegrationNotice $notice): bool
86 {
87 if ($notice instanceof UsageAwareNotice && ! $notice->is_usage_detected()) {
88 return false;
89 }
90
91 if ($this->state->is_cooldown_active(7)) {
92 return false;
93 }
94
95 if ($this->state->is_dismissed($notice->get_slug())) {
96 return false;
97 }
98
99 if (! $this->state->is_delay_met($notice->get_slug(), $notice->get_delay_days())) {
100 return false;
101 }
102
103 return true;
104 }
105
106 private function create_ajax_handler(IntegrationNotice $notice): Ajax\Handler
107 {
108 $handler = new Ajax\Handler();
109 $handler
110 ->set_action('ac_dismiss_suggestion_' . $notice->get_slug())
111 ->set_callback(function () use ($notice, $handler) {
112 $handler->verify_request();
113
114 if (! current_user_can(Capabilities::MANAGE)) {
115 wp_die('-1');
116 }
117
118 $this->state->dismiss($notice->get_slug());
119 $this->state->track_dismissal();
120 });
121
122 return $handler;
123 }
124
125 private function render(IntegrationNotice $notice, Ajax\Handler $handler): string
126 {
127 $view = new View([
128 'eyebrow' => $notice->get_eyebrow(),
129 'title' => $notice->get_title(),
130 'description' => $notice->get_description(),
131 'cta_label' => $notice->get_cta_label(),
132 'cta_url' => $notice->get_cta_url(),
133 'secondary_label' => $notice->get_secondary_label(),
134 'secondary_url' => $notice->get_secondary_url(),
135 'dismissible_callback' => $handler->get_params(),
136 'extra_classes' => $notice->get_extra_classes(),
137 ]);
138
139 $view->set_template('message/notice/integration');
140
141 return $view->render();
142 }
143
144 }
145