PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / app / Notifications / Admin.php

Admin.php in Extendify 3.2.1, at app/Notifications/Admin.php

101 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Admin.
5 */
6
7 namespace Extendify\Notifications;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 class Admin
12 {
13 public function __construct()
14 {
15 \add_action('admin_enqueue_scripts', [$this, 'loadScriptsAndStyles']);
16 \add_action('admin_notices', [$this, 'renderMountPoint']);
17 \add_action('admin_footer', [$this, 'renderModalMountPoint']);
18 }
19
20 /**
21 * Adds the banner bundle on eligible admin screens
22 *
23 * @return void
24 */
25 public function loadScriptsAndStyles()
26 {
27 if ($this->container() === '' && $this->modalContainer() === '') {
28 return;
29 }
30
31 Assets::enqueue();
32 }
33
34 /**
35 * Prints the banner mount node on eligible admin screens
36 *
37 * @return void
38 */
39 public function renderMountPoint()
40 {
41 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Mount escapes
42 echo $this->container();
43 }
44
45 /**
46 * Prints the modal mount node on screens admin_notices never reaches
47 *
48 * @return void
49 */
50 public function renderModalMountPoint()
51 {
52 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Mount escapes
53 echo $this->modalContainer();
54 }
55
56 /**
57 * notifications.js wraps a container carrying data-admin-notice in
58 * admin-notice spacing.
59 *
60 * @return string
61 */
62 private function container()
63 {
64 $slot = $this->currentSlot();
65 return $slot ? Mount::container($slot, ['data-admin-notice']) : '';
66 }
67
68 private function modalContainer()
69 {
70 return Mount::container(Slots::ADMIN_MODAL);
71 }
72
73 private function currentSlot()
74 {
75 $screen = \get_current_screen();
76 if (!$screen) {
77 return null;
78 }
79
80 if ($screen->id === 'dashboard') {
81 return Slots::ADMIN_DASHBOARD;
82 }
83
84 return $this->isExcludedScreen($screen) ? null : Slots::ADMIN_OTHERS;
85 }
86
87 private function isExcludedScreen($screen)
88 {
89 if ($screen->base === 'post') {
90 return true;
91 }
92
93 $excludedIds = ['site-editor', 'plugins', 'plugin-install', 'plugin-editor'];
94 if (in_array($screen->id, $excludedIds, true)) {
95 return true;
96 }
97
98 return strpos($screen->id, '_page_') !== false;
99 }
100 }
101