PluginProbe
Extendify / 0.10.0
Extendify v0.10.0
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 / Assist / Admin.php

Admin.php in Extendify 0.10.0, at app/Assist/Admin.php

98 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin.
4 */
5
6 namespace Extendify\Assist;
7
8 use Extendify\Config;
9
10 /**
11 * This class handles any file loading for the admin area.
12 */
13 class Admin
14 {
15
16 /**
17 * The instance
18 *
19 * @var $instance
20 */
21 public static $instance = null;
22
23 /**
24 * Adds various actions to set up the page
25 *
26 * @return self|void
27 */
28 public function __construct()
29 {
30 if (self::$instance) {
31 return self::$instance;
32 }
33
34 self::$instance = $this;
35 $this->loadScripts();
36 }
37
38 /**
39 * Adds scripts to the admin
40 *
41 * @return void
42 */
43 public function loadScripts()
44 {
45 \add_action(
46 'admin_enqueue_scripts',
47 function () {
48 if (!current_user_can(Config::$requiredCapability)) {
49 return;
50 }
51
52 if (!Config::$showAssist) {
53 return;
54 }
55
56 $version = Config::$environment === 'PRODUCTION' ? Config::$version : uniqid();
57
58 \wp_enqueue_script(
59 Config::$slug . '-assist-scripts',
60 EXTENDIFY_BASE_URL . 'public/build/extendify-assist.js',
61 [
62 'wp-components',
63 'wp-element',
64 'wp-data',
65 'wp-core-data',
66 'wp-html-entities',
67 'wp-i18n',
68 'wp-polyfill',
69 ],
70 $version,
71 true
72 );
73 \wp_add_inline_script(
74 Config::$slug . '-assist-scripts',
75 'window.extAssistData = ' . wp_json_encode([
76 'devbuild' => \esc_attr(Config::$environment === 'DEVELOPMENT'),
77 'root' => \esc_url_raw(\rest_url(Config::$slug . '/' . Config::$apiVersion)),
78 'nonce' => \wp_create_nonce('wp_rest'),
79 'adminUrl' => \esc_url_raw(\admin_url()),
80 ]),
81 'before'
82 );
83
84 \wp_set_script_translations(Config::$slug . '-assist-scripts', 'extendify');
85
86 \wp_enqueue_style(
87 Config::$slug . '-assist-styles',
88 EXTENDIFY_BASE_URL . 'public/build/extendify-assist.css',
89 [],
90 $version,
91 'all'
92 );
93 }
94 );
95 }
96
97 }
98