PluginProbe
Extendify / 3.1.4
Extendify v3.1.4
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 / PartnerNotification / Admin.php

Admin.php in Extendify 3.1.4, at app/PartnerNotification/Admin.php

118 lines 3.0 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\PartnerNotification;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 use Extendify\Config;
12
13 class Admin
14 {
15 public function __construct()
16 {
17 \add_action('admin_enqueue_scripts', [$this, 'loadScriptsAndStyles']);
18 \add_action('admin_notices', [$this, 'renderMountPoint']);
19 }
20
21 /**
22 * Adds the banner bundle on eligible admin screens
23 *
24 * @return void
25 */
26 public function loadScriptsAndStyles()
27 {
28 if (!$this->currentSlot()) {
29 return;
30 }
31
32 $version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version;
33 $scriptAssetPath = EXTENDIFY_PATH . 'public/build/'
34 . Config::$assetManifest['extendify-partner-notification.php'];
35 $fallback = [
36 'dependencies' => [],
37 'version' => $version,
38 ];
39 $scriptAsset = file_exists($scriptAssetPath) ? require $scriptAssetPath : $fallback;
40
41 foreach ($scriptAsset['dependencies'] as $style) {
42 \wp_enqueue_style($style);
43 }
44
45 \wp_enqueue_script(
46 Config::$slug . '-partner-notification-scripts',
47 EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-partner-notification.js'],
48 array_merge([Config::$slug . '-shared-scripts'], $scriptAsset['dependencies']),
49 $scriptAsset['version'],
50 true
51 );
52
53 \wp_set_script_translations(
54 Config::$slug . '-partner-notification-scripts',
55 'extendify-local',
56 EXTENDIFY_PATH . 'languages/js'
57 );
58
59 \wp_enqueue_style(
60 Config::$slug . '-partner-notification-styles',
61 EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-partner-notification.css'],
62 [],
63 Config::$version,
64 'all'
65 );
66 }
67
68 /**
69 * Prints the banner mount node on eligible admin screens
70 *
71 * @return void
72 */
73 public function renderMountPoint()
74 {
75 $slot = $this->currentSlot();
76 if (!$slot) {
77 return;
78 }
79
80 ?>
81 <div
82 class="extendify-partner-notification"
83 data-ext-partner-notification
84 data-slot="<?php echo \esc_attr($slot); ?>"
85 data-test="partner-notification-<?php echo \esc_attr($slot); ?>">
86 </div>
87 <?php
88 }
89
90 private function currentSlot()
91 {
92 $screen = \get_current_screen();
93 if (!$screen) {
94 return null;
95 }
96
97 if ($screen->id === 'dashboard') {
98 return 'dashboard';
99 }
100
101 return $this->isExcludedScreen($screen) ? null : 'admin-others';
102 }
103
104 private function isExcludedScreen($screen)
105 {
106 if ($screen->base === 'post') {
107 return true;
108 }
109
110 $excludedIds = ['site-editor', 'plugins', 'plugin-install', 'plugin-editor'];
111 if (in_array($screen->id, $excludedIds, true)) {
112 return true;
113 }
114
115 return strpos($screen->id, '_page_') !== false;
116 }
117 }
118