-
Notifications
You must be signed in to change notification settings - Fork 1
/
wpui-sample-plugin.php
71 lines (64 loc) · 1.59 KB
/
wpui-sample-plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Plugin Name: WPUI Sample Plugin
* Update URI: wpui-sample-plugin
*/
/**
* Plugin admin menu and page
*
* @return void
*/
function wsp_admin_menu()
{
add_menu_page(
__('WPUI Plugin', 'wsplugin'),
__('WPUI Plugin', 'wsplugin'),
'manage_options',
'wpui-sample-plugin',
function () {
echo '<div id="wpui-sample-plugin" class="placeholder-styles"></div>';
},
'dashicons-superhero',
2
);
}
add_action('admin_menu', 'wsp_admin_menu');
/**
* Plugin Assets
*
* @param string $hook
* @return void
*/
function wsp_wp_admin_scripts($hook)
{
// Load assets only on plugin page(s)
if ('toplevel_page_wpui-sample-plugin' !== $hook) {
return;
}
// Automatically load imported dependencies and assets version.
$asset_file = include plugin_dir_path(__FILE__) . 'build/index.asset.php';
// Enqueue CSS dependencies.
foreach ($asset_file['dependencies'] as $style) {
wp_enqueue_style($style);
}
// Load plugin js
wp_register_script(
'wpui-sample-plugin',
plugins_url('build/index.js', __FILE__),
$asset_file['dependencies'],
$asset_file['version'],
[
'in_footer' => true
]
);
wp_enqueue_script('wpui-sample-plugin');
// Load our style.css.
wp_register_style(
'wpui-sample-plugin',
plugins_url('build/index.css', __FILE__),
[],
$asset_file['version']
);
wp_enqueue_style('wpui-sample-plugin');
}
add_action('admin_enqueue_scripts', 'wsp_wp_admin_scripts');