-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreactadmin.php
More file actions
54 lines (49 loc) · 1.38 KB
/
reactadmin.php
File metadata and controls
54 lines (49 loc) · 1.38 KB
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
<?php
/**
* Plugin Name: Admin React Example
* Description: An example for using react for admin option pages
* Version: 1.0.0
* Author: Marcus Kober
* Author URI: https://marcuskober.de
* License: GPL-3.0+
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
* Text Domain: adminreact
*/
define('ADMIN_REACT_VERSION', '1.0.0' );
define('ADMIN_REACT_URL', plugins_url('/', __FILE__));
add_action('admin_menu', function() {
$pageHook = add_options_page(
'AdminReact',
'AdminReact',
'manage_options',
'admin-react',
function() {
?>
<div id="react-admin-app"></div>
<?php
}
);
add_action("load-{$pageHook}", function() {
wp_enqueue_script('admin-react-plugin-script', ADMIN_REACT_URL . 'dist/app.js', ['wp-api', 'wp-i18n', 'wp-components', 'wp-element'], ADMIN_REACT_VERSION, true);
wp_enqueue_style('admin-react-plugin-style', ADMIN_REACT_URL . 'dist/app.css', ['wp-components'], ADMIN_REACT_VERSION);
});
});
add_action('init', function() {
register_setting(
'admin_react_settings',
'admin_react_example_bool_1',
[
'type' => 'boolean',
'show_in_rest' => true,
'default' => false,
]
);
register_setting(
'admin_react_settings',
'admin_react_example_text_1',
[
'type' => 'string',
'show_in_rest' => true,
]
);
});