PluginProbe
Extendify / 3.1.5
Extendify v3.1.5
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 0.7.0 All 126 releases
extendify / app / Notifications / Admin.php

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

84 lines 1.8 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 }
18
19 /**
20 * Adds the banner bundle on eligible admin screens
21 *
22 * @return void
23 */
24 public function loadScriptsAndStyles()
25 {
26 if ($this->container() === '') {
27 return;
28 }
29
30 Assets::enqueue();
31 }
32
33 /**
34 * Prints the banner mount node on eligible admin screens
35 *
36 * @return void
37 */
38 public function renderMountPoint()
39 {
40 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Mount escapes
41 echo $this->container();
42 }
43
44 /**
45 * notifications.js wraps a container carrying data-admin-notice in
46 * admin-notice spacing.
47 *
48 * @return string
49 */
50 private function container()
51 {
52 $slot = $this->currentSlot();
53 return $slot ? Mount::container($slot, ['data-admin-notice']) : '';
54 }
55
56 private function currentSlot()
57 {
58 $screen = \get_current_screen();
59 if (!$screen) {
60 return null;
61 }
62
63 if ($screen->id === 'dashboard') {
64 return Slots::ADMIN_DASHBOARD;
65 }
66
67 return $this->isExcludedScreen($screen) ? null : Slots::ADMIN_OTHERS;
68 }
69
70 private function isExcludedScreen($screen)
71 {
72 if ($screen->base === 'post') {
73 return true;
74 }
75
76 $excludedIds = ['site-editor', 'plugins', 'plugin-install', 'plugin-editor'];
77 if (in_array($screen->id, $excludedIds, true)) {
78 return true;
79 }
80
81 return strpos($screen->id, '_page_') !== false;
82 }
83 }
84