PluginProbe
Extendify / 2.2.0
Extendify v2.2.0
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 / Draft / Admin.php

Admin.php in Extendify 2.2.0, at app/Draft/Admin.php

90 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\Draft;
8
9 defined('ABSPATH') || die('No direct access.');
10
11 use Extendify\Config;
12
13 /**
14 * This class handles any file loading for the admin area.
15 */
16
17 class Admin
18 {
19 /**
20 * Adds various actions to set up the page
21 *
22 * @return self|void
23 */
24 public function __construct()
25 {
26 \add_action('admin_init', [$this, 'loadScripts']);
27 }
28
29 /**
30 * Adds scripts to the admin
31 *
32 * @return void
33 */
34 public function loadScripts()
35 {
36 add_action('enqueue_block_editor_assets', [$this, 'enqueueGutenbergAssets']);
37 }
38
39 /**
40 * Enqueues Gutenberg stuff on a non-Gutenberg page.
41 *
42 * @return void
43 */
44 public function enqueueGutenbergAssets()
45 {
46 $currentScreen = get_current_screen();
47 // Only load in the post editor.
48 if ($currentScreen->base !== 'post') {
49 return;
50 }
51
52 $version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version;
53 $scriptAssetPath = EXTENDIFY_PATH . 'public/build/' . Config::$assetManifest['extendify-draft.php'];
54 $fallback = [
55 'dependencies' => [],
56 'version' => $version,
57 ];
58
59 $scriptAsset = file_exists($scriptAssetPath) ? require $scriptAssetPath : $fallback;
60 foreach ($scriptAsset['dependencies'] as $style) {
61 wp_enqueue_style($style);
62 }
63
64 \wp_enqueue_script(
65 Config::$slug . '-draft-scripts',
66 EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-draft.js'],
67 array_merge([Config::$slug . '-shared-scripts'], $scriptAsset['dependencies']),
68 $scriptAsset['version'],
69 true
70 );
71
72 \wp_set_script_translations(
73 Config::$slug . '-draft-scripts',
74 'extendify-local',
75 EXTENDIFY_PATH . 'languages/js'
76 );
77
78 $version = constant('EXTENDIFY_DEVMODE') ? uniqid() : Config::$version;
79 if (isset(Config::$assetManifest['extendify-draft.css'])) {
80 \wp_enqueue_style(
81 Config::$slug . '-draft-styles',
82 EXTENDIFY_BASE_URL . 'public/build/' . Config::$assetManifest['extendify-draft.css'],
83 [],
84 $version,
85 'all'
86 );
87 }
88 }
89 }
90