PluginProbe
Hello Plus / trunk
Hello Plus vtrunk
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.6.0 1.6.1 1.6.2 1.7.0 1.7.1 1.7.2 1.7.3 All 30 releases
hello-plus / modules / admin / components / scripts-controller.php

scripts-controller.php in Hello Plus trunk, at modules/admin/components/scripts-controller.php

78 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace HelloPlus\Modules\Admin\Components;
4
5 use HelloPlus\Includes\Utils;
6 use HelloPlus\Modules\Admin\Classes\Menu\Pages\Setup_Wizard;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 class Scripts_Controller {
13 public function enqueue_hello_plus_onboarding_scripts() {
14 $screen = get_current_screen();
15
16 if ( ! Utils::ends_with( $screen->id, Setup_Wizard::SETUP_WIZARD_PAGE_SLUG ) ) {
17 return;
18 }
19
20 $handle = 'helloplus-onboarding';
21 $asset_path = HELLOPLUS_SCRIPTS_PATH . 'helloplus-onboarding.asset.php';
22 $asset_url = HELLOPLUS_SCRIPTS_URL;
23
24 if ( ! file_exists( $asset_path ) ) {
25 throw new \Exception( 'You need to run `npm run build` for the "hello-plus" first.' );
26 }
27
28 $script_asset = require $asset_path;
29
30 $script_asset['dependencies'][] = 'wp-util';
31
32 wp_enqueue_script(
33 $handle,
34 HELLOPLUS_SCRIPTS_URL . "$handle.js",
35 $script_asset['dependencies'],
36 $script_asset['version'],
37 true
38 );
39
40 wp_set_script_translations( $handle, 'hello-plus' );
41 }
42
43 public function enqueue_whats_new_onboarding_scripts() {
44 $screen = get_current_screen();
45
46 if ( 'plugins' !== $screen->id ) {
47 return;
48 }
49
50 $handle = 'helloplus-whats-new';
51 $asset_path = HELLOPLUS_SCRIPTS_PATH . $handle . '.asset.php';
52 $asset_url = HELLOPLUS_SCRIPTS_URL;
53
54 if ( ! file_exists( $asset_path ) ) {
55 throw new \Exception( 'You need to run `npm run build` for the "hello-plus" first.' );
56 }
57
58 $script_asset = require $asset_path;
59
60 $script_asset['dependencies'][] = 'wp-util';
61
62 wp_enqueue_script(
63 $handle,
64 HELLOPLUS_SCRIPTS_URL . "$handle.js",
65 $script_asset['dependencies'],
66 $script_asset['version'],
67 true
68 );
69
70 wp_set_script_translations( $handle, 'hello-plus' );
71 }
72
73 public function __construct() {
74 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_hello_plus_onboarding_scripts' ] );
75 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_whats_new_onboarding_scripts' ] );
76 }
77 }
78