PluginProbe ʕ •ᴥ•ʔ
Admin Columns / 7.0.19
Admin Columns v7.0.19
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 / Promotion.php
codepress-admin-columns / classes / Check Last commit date
Integration 1 month ago Promotion.php 1 month ago Review.php 1 month ago
Promotion.php
83 lines
1 <?php
2
3 namespace AC\Check;
4
5 use AC\Ajax;
6 use AC\Capabilities;
7 use AC\Message\Notice\Dismissible;
8 use AC\Preferences;
9 use AC\Preferences\UserFactory;
10 use AC\Registerable;
11 use AC\Screen;
12 use AC\Type\Promo;
13
14 final class Promotion implements Registerable
15 {
16
17 private Promo $promo;
18
19 private UserFactory $preferences_factory;
20
21 public function __construct(Promo $promo, UserFactory $preferences_factory)
22 {
23 $this->promo = $promo;
24 $this->preferences_factory = $preferences_factory;
25 }
26
27 public function register(): void
28 {
29 add_action('ac/screen', [$this, 'display']);
30
31 $this->get_ajax_handler()->register();
32 }
33
34 private function get_ajax_handler(): Ajax\Handler
35 {
36 $handler = new Ajax\Handler();
37
38 $handler
39 ->set_action('ac_dismiss_notice_promo_' . $this->get_individual_slug())
40 ->set_callback([$this, 'ajax_dismiss_notice']);
41
42 return $handler;
43 }
44
45 private function get_individual_slug(): string
46 {
47 return $this->promo->get_slug() . $this->promo->get_date_range()->get_start()->format('Ymd');
48 }
49
50 private function get_preferences(): Preferences\Preference
51 {
52 return $this->preferences_factory->create(
53 'check-promo-' . $this->get_individual_slug()
54 );
55 }
56
57 public function ajax_dismiss_notice(): void
58 {
59 $this->get_ajax_handler()->verify_request();
60 $this->get_preferences()->save('dismiss-notice', true);
61 }
62
63 private function is_promo_screen(Screen $screen): bool
64 {
65 return $screen->has_screen() && ($screen->is_table_screen() || $screen->is_admin_screen());
66 }
67
68 public function display(Screen $screen): void
69 {
70 if ( ! current_user_can(Capabilities::MANAGE) ||
71 ! $this->is_promo_screen($screen) ||
72 $this->get_preferences()->find('dismiss-notice')
73 ) {
74 return;
75 }
76
77 $notice = new Dismissible(
78 $this->promo->get_notice_message(),
79 $this->get_ajax_handler()
80 );
81 $notice->register();
82 }
83 }