-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdashboard-wp-components.php
64 lines (52 loc) · 1.32 KB
/
dashboard-wp-components.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
<?php
/*
* Plugin Name: Dashboard WP components
* Description: Admin page with Gutenberg components
* Version: 1.0.0
* Author: Sergey Mochalov
*
*/
namespace KPFU\Plugin\Gutenbergpage;
use \add_action;
add_action('admin_menu', __NAMESPACE__ . '\dashboard_page');
# Assets function
function add_assets()
{
// Automatically load imported dependencies and assets version.
$asset_file = include plugin_dir_path(__FILE__) . 'build/index.asset.php';
// Load our app.js.
wp_register_script(
'demo-gb-app',
plugins_url('build/index.js', __FILE__),
$asset_file['dependencies'],
$asset_file['version'],
// we need it for DOM ready
array(
'strategy' => 'defer'
)
);
wp_enqueue_script('demo-gb-app');
wp_register_style(
'demo-gb-css',
plugins_url('style.css', __FILE__),
array('wp-components'),
$asset_file['version']
);
wp_enqueue_style('demo-gb-css');
}
function dashboard_page()
{
$page_hook_suffix = add_dashboard_page(
'Gutenberg components',
'GB components',
'manage_options',
'gb-components-demo',
__NAMESPACE__ . '\page_render_markup'
);
add_action("admin_print_scripts-{$page_hook_suffix}", __NAMESPACE__ . '\add_assets');
}
function page_render_markup()
{
# Root node for React mount
echo "<div id='demo-app'></div>";
}