-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin-page-gutenberg.php
More file actions
111 lines (99 loc) · 3.18 KB
/
admin-page-gutenberg.php
File metadata and controls
111 lines (99 loc) · 3.18 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
*
* Plugin Name: Admin Page Gutenberg
* Plugin URI: #
* Description: Admin Page Gutenberg Description
* Version: 1.0.0
* Requires at least: 5.6.2
* Requires PHP: 7.2
* Author: Array.codes
* Author URI: https://array.codes
* Developer: Heitor Sousa
* Developer URI: https://github.com/heitorspedroso
* Domain Path: /languages
* Text Domain: admin-page-gutenberg
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package 'admin-page-gutenberg'
*/
function add_admin_page_gutenberg() {
add_menu_page(
__( 'Admin Page Gutenberg', 'admin-page-gutenberg' ),
__( 'Admin Page Gutenberg', 'admin-page-gutenberg' ),
'manage_options',
'admin-page-gutenberg',
function () {
printf('<h2>Admin Page Gutenberg</h2><div id="admin-page-gutenberg"></div>');
}
);
}
add_action( 'admin_menu', 'add_admin_page_gutenberg' );
function add_wp_admin_scripts( $hook ) {
// Load only on ?page=admin-page-gutenberg.
if ( 'toplevel_page_admin-page-gutenberg' !== $hook ) {
return;
}
// Load the required WordPress packages.
// 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 our app.js.
wp_register_script(
'admin-page-gutenberg',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version']
);
wp_enqueue_script( 'admin-page-gutenberg' );
// Load our index.scss.
wp_register_style(
'admin-page-gutenberg',
plugins_url( 'index.scss', __FILE__ ),
array(),
$asset_file['version']
);
wp_enqueue_style( 'admin-page-gutenberg' );
}
add_action( 'admin_enqueue_scripts', 'add_wp_admin_scripts' );
/**
* Register and add settings
*/
function page_init_admin_page_gutenberg() {
register_setting(
'admin-page-guttenberg-option-group',
'admin_page_guttenberg_fields',
array(
'type' => 'object',
'show_in_rest' => array(
'schema' => array(
'type' => 'object',
'default' => array(
'field1' => '',
'field2' => 0,
),
'properties' => array(
'field1' => array(
'type' => 'string',
),
'field2' => array(
'type' => 'string',
),
),
),
),
)
);
}
add_action( 'admin_init', 'page_init_admin_page_gutenberg', 30);
add_action( 'rest_api_init', 'page_init_admin_page_gutenberg');
function show_options_admin_page_gutenberg(){
$admin_page_guttenberg_fields = get_option( 'admin_page_guttenberg_fields' );
print_r($admin_page_guttenberg_fields);
}
add_action( 'wp_head', 'show_options_admin_page_gutenberg');