@wordpress/build 0.9.0 → 0.10.1-next.v.202603102151.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +6 -0
- package/CHANGELOG.md +11 -0
- package/lib/build.mjs +53 -54
- package/package.json +2 -2
- package/templates/module-registration.php.template +32 -34
- package/templates/page-wp-admin.php.template +222 -236
- package/templates/page.php.template +264 -278
- package/templates/routes-page-functions.php.template +12 -16
- package/templates/routes-registration.php.template +49 -45
- package/templates/script-registration.php.template +65 -69
- package/templates/style-registration.php.template +52 -56
|
@@ -12,318 +12,304 @@ global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes, ${{PREFIX}}_{{PAGE_SLUG_UNDE
|
|
|
12
12
|
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes = array();
|
|
13
13
|
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items = array();
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes;
|
|
25
|
-
|
|
26
|
-
$route = array( 'path' => $path );
|
|
27
|
-
if ( ! empty( $content_module ) ) {
|
|
28
|
-
$route['content_module'] = $content_module;
|
|
29
|
-
}
|
|
30
|
-
if ( ! empty( $route_module ) ) {
|
|
31
|
-
$route['route_module'] = $route_module;
|
|
32
|
-
}
|
|
15
|
+
/**
|
|
16
|
+
* Register a route for the {{PAGE_SLUG}} page.
|
|
17
|
+
*
|
|
18
|
+
* @param string $path Route path (e.g., '/types/$type/edit/$id').
|
|
19
|
+
* @param string|null $content_module Script module ID for content (stage/inspector).
|
|
20
|
+
* @param string|null $route_module Script module ID for route lifecycle hooks.
|
|
21
|
+
*/
|
|
22
|
+
function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_route( $path, $content_module = null, $route_module = null ) {
|
|
23
|
+
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes;
|
|
33
24
|
|
|
34
|
-
|
|
25
|
+
$route = array( 'path' => $path );
|
|
26
|
+
if ( ! empty( $content_module ) ) {
|
|
27
|
+
$route['content_module'] = $content_module;
|
|
28
|
+
}
|
|
29
|
+
if ( ! empty( $route_module ) ) {
|
|
30
|
+
$route['route_module'] = $route_module;
|
|
35
31
|
}
|
|
36
|
-
}
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* Register a menu item for the {{PAGE_SLUG}} page.
|
|
41
|
-
*
|
|
42
|
-
* @param string $id Menu item ID.
|
|
43
|
-
* @param string $label Display label.
|
|
44
|
-
* @param string $to Route path to navigate to.
|
|
45
|
-
* @param string $parent_id Optional. Parent menu item ID.
|
|
46
|
-
* @param string $parent_type Optional. Parent type: 'drilldown' or 'dropdown'.
|
|
47
|
-
*/
|
|
48
|
-
function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_menu_item( $id, $label, $to, $parent_id = '', $parent_type = '' ) {
|
|
49
|
-
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items;
|
|
33
|
+
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes[] = $route;
|
|
34
|
+
}
|
|
50
35
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Register a menu item for the {{PAGE_SLUG}} page.
|
|
38
|
+
*
|
|
39
|
+
* @param string $id Menu item ID.
|
|
40
|
+
* @param string $label Display label.
|
|
41
|
+
* @param string $to Route path to navigate to.
|
|
42
|
+
* @param string $parent_id Optional. Parent menu item ID.
|
|
43
|
+
* @param string $parent_type Optional. Parent type: 'drilldown' or 'dropdown'.
|
|
44
|
+
*/
|
|
45
|
+
function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_menu_item( $id, $label, $to, $parent_id = '', $parent_type = '' ) {
|
|
46
|
+
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items;
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
$menu_item = array(
|
|
49
|
+
'id' => $id,
|
|
50
|
+
'label' => $label,
|
|
51
|
+
'to' => $to,
|
|
52
|
+
);
|
|
60
53
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
if ( ! empty( $parent_id ) ) {
|
|
55
|
+
$menu_item['parent'] = $parent_id;
|
|
56
|
+
}
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
if ( ! empty( $parent_type ) && in_array( $parent_type, array( 'drilldown', 'dropdown' ), true ) ) {
|
|
59
|
+
$menu_item['parent_type'] = $parent_type;
|
|
66
60
|
}
|
|
61
|
+
|
|
62
|
+
${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items[] = $menu_item;
|
|
67
63
|
}
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes ?? array();
|
|
78
|
-
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all registered routes for the {{PAGE_SLUG}} page.
|
|
67
|
+
*
|
|
68
|
+
* @return array Array of route objects.
|
|
69
|
+
*/
|
|
70
|
+
function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_routes() {
|
|
71
|
+
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes;
|
|
72
|
+
return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes ?? array();
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items ?? array();
|
|
90
|
-
}
|
|
75
|
+
/**
|
|
76
|
+
* Get all registered menu items for the {{PAGE_SLUG}} page.
|
|
77
|
+
*
|
|
78
|
+
* @return array Array of menu item objects.
|
|
79
|
+
*/
|
|
80
|
+
function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items() {
|
|
81
|
+
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items;
|
|
82
|
+
return ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items ?? array();
|
|
91
83
|
}
|
|
92
84
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Preload REST API data for the {{PAGE_SLUG}} page.
|
|
87
|
+
* Automatically called during page rendering.
|
|
88
|
+
*/
|
|
89
|
+
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data() {
|
|
90
|
+
// Define paths to preload - same for all pages
|
|
91
|
+
// Please also change packages/core-data/src/entities.js when changing this.
|
|
92
|
+
$preload_paths = array(
|
|
93
|
+
'/?_fields=description,gmt_offset,home,image_sizes,image_size_threshold,image_output_formats,jpeg_interlaced,png_interlaced,gif_interlaced,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
|
|
94
|
+
array( '/wp/v2/settings', 'OPTIONS' ),
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// Use rest_preload_api_request to gather the preloaded data
|
|
98
|
+
$preload_data = array_reduce(
|
|
99
|
+
$preload_paths,
|
|
100
|
+
'rest_preload_api_request',
|
|
101
|
+
array()
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// Register the preloading middleware with wp-api-fetch
|
|
105
|
+
wp_add_inline_script(
|
|
106
|
+
'wp-api-fetch',
|
|
107
|
+
sprintf(
|
|
108
|
+
'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
|
|
109
|
+
wp_json_encode( $preload_data )
|
|
110
|
+
),
|
|
111
|
+
'after'
|
|
112
|
+
);
|
|
113
|
+
}
|
|
105
114
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Render the {{PAGE_SLUG}} page.
|
|
117
|
+
* Call this function from add_menu_page or add_submenu_page.
|
|
118
|
+
*/
|
|
119
|
+
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
120
|
+
// Load build constants
|
|
121
|
+
$build_constants = require __DIR__ . '/../../constants.php';
|
|
112
122
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
123
|
+
// Set current screen
|
|
124
|
+
set_current_screen();
|
|
125
|
+
|
|
126
|
+
// Remove unwanted deprecated handler
|
|
127
|
+
remove_action( 'admin_head', 'wp_admin_bar_header' );
|
|
128
|
+
|
|
129
|
+
// Remove unwanted scripts and styles that were enqueued during `admin_init`
|
|
130
|
+
foreach ( wp_scripts()->queue as $script ) {
|
|
131
|
+
wp_dequeue_script( $script );
|
|
132
|
+
}
|
|
133
|
+
foreach ( wp_styles()->queue as $style ) {
|
|
134
|
+
wp_dequeue_style( $style );
|
|
122
135
|
}
|
|
123
|
-
}
|
|
124
136
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* Render the {{PAGE_SLUG}} page.
|
|
128
|
-
* Call this function from add_menu_page or add_submenu_page.
|
|
129
|
-
*/
|
|
130
|
-
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page() {
|
|
131
|
-
// Load build constants
|
|
132
|
-
$build_constants = require __DIR__ . '/../../constants.php';
|
|
137
|
+
// Fire init action for extensions to register routes and menu items
|
|
138
|
+
do_action( '{{PAGE_SLUG}}_init' );
|
|
133
139
|
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
// Enqueue command palette assets for boot-based pages
|
|
141
|
+
if ( function_exists( 'wp_enqueue_command_palette_assets' ) ) {
|
|
142
|
+
wp_enqueue_command_palette_assets();
|
|
143
|
+
}
|
|
136
144
|
|
|
137
|
-
|
|
138
|
-
|
|
145
|
+
// Preload REST API data
|
|
146
|
+
{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data();
|
|
139
147
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
foreach ( wp_styles()->queue as $style ) {
|
|
145
|
-
wp_dequeue_style( $style );
|
|
146
|
-
}
|
|
148
|
+
// Get all registered routes and menu items
|
|
149
|
+
$menu_items = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items();
|
|
150
|
+
$routes = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_routes();
|
|
147
151
|
|
|
148
|
-
|
|
149
|
-
|
|
152
|
+
// Get boot module asset file for dependencies
|
|
153
|
+
$asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
|
|
154
|
+
if ( file_exists( $asset_file ) ) {
|
|
155
|
+
$asset = require $asset_file;
|
|
150
156
|
|
|
151
|
-
//
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
157
|
+
// This script serves two purposes:
|
|
158
|
+
// 1. It ensures all the globals that are made available to the modules are loaded.
|
|
159
|
+
// 2. It initializes the boot module as an inline script.
|
|
160
|
+
wp_register_script( '{{PAGE_SLUG}}-prerequisites', '', $asset['dependencies'], $asset['version'], true );
|
|
155
161
|
|
|
156
|
-
//
|
|
157
|
-
{{
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
// 1. It ensures all the globals that are made available to the modules are loaded.
|
|
170
|
-
// 2. It initializes the boot module as an inline script.
|
|
171
|
-
wp_register_script( '{{PAGE_SLUG}}-prerequisites', '', $asset['dependencies'], $asset['version'], true );
|
|
172
|
-
|
|
173
|
-
// Add inline script to initialize the app
|
|
174
|
-
$init_modules = {{INIT_MODULES_JSON}};
|
|
175
|
-
wp_add_inline_script(
|
|
176
|
-
'{{PAGE_SLUG}}-prerequisites',
|
|
177
|
-
sprintf(
|
|
178
|
-
'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));',
|
|
179
|
-
'{{PAGE_SLUG}}-app',
|
|
180
|
-
wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
181
|
-
wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
182
|
-
wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
183
|
-
esc_url( admin_url( '/' ) )
|
|
184
|
-
)
|
|
185
|
-
);
|
|
186
|
-
|
|
187
|
-
// Register prerequisites style by filtering script dependencies to find registered styles
|
|
188
|
-
$style_dependencies = array_filter(
|
|
189
|
-
$asset['dependencies'],
|
|
190
|
-
function ( $handle ) {
|
|
191
|
-
return wp_style_is( $handle, 'registered' );
|
|
192
|
-
}
|
|
193
|
-
);
|
|
194
|
-
wp_register_style( '{{PAGE_SLUG}}-prerequisites', false, $style_dependencies, $asset['version'] );
|
|
195
|
-
|
|
196
|
-
// Build dependencies for {{PAGE_SLUG}} module
|
|
197
|
-
$boot_dependencies = array(
|
|
198
|
-
array(
|
|
199
|
-
'import' => 'static',
|
|
200
|
-
'id' => '@wordpress/boot',
|
|
201
|
-
),
|
|
202
|
-
);
|
|
162
|
+
// Add inline script to initialize the app
|
|
163
|
+
$init_modules = {{INIT_MODULES_JSON}};
|
|
164
|
+
wp_add_inline_script(
|
|
165
|
+
'{{PAGE_SLUG}}-prerequisites',
|
|
166
|
+
sprintf(
|
|
167
|
+
'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));',
|
|
168
|
+
'{{PAGE_SLUG}}-app',
|
|
169
|
+
wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
170
|
+
wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
171
|
+
wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
|
|
172
|
+
esc_url( admin_url( '/' ) )
|
|
173
|
+
)
|
|
174
|
+
);
|
|
203
175
|
|
|
204
|
-
|
|
176
|
+
// Register prerequisites style by filtering script dependencies to find registered styles
|
|
177
|
+
$style_dependencies = array_filter(
|
|
178
|
+
$asset['dependencies'],
|
|
179
|
+
function ( $handle ) {
|
|
180
|
+
return wp_style_is( $handle, 'registered' );
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
wp_register_style( '{{PAGE_SLUG}}-prerequisites', false, $style_dependencies, $asset['version'] );
|
|
184
|
+
|
|
185
|
+
// Build dependencies for {{PAGE_SLUG}} module
|
|
186
|
+
$boot_dependencies = array(
|
|
187
|
+
array(
|
|
188
|
+
'import' => 'static',
|
|
189
|
+
'id' => '@wordpress/boot',
|
|
190
|
+
),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
// Add init modules as static dependencies
|
|
205
194
|
{{INIT_MODULES_PHP_ARRAY}}
|
|
206
195
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}
|
|
196
|
+
// Add all registered routes as dependencies
|
|
197
|
+
foreach ( $routes as $route ) {
|
|
198
|
+
if ( isset( $route['route_module'] ) ) {
|
|
199
|
+
$boot_dependencies[] = array(
|
|
200
|
+
'import' => 'static',
|
|
201
|
+
'id' => $route['route_module'],
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
if ( isset( $route['content_module'] ) ) {
|
|
205
|
+
$boot_dependencies[] = array(
|
|
206
|
+
'import' => 'dynamic',
|
|
207
|
+
'id' => $route['content_module'],
|
|
208
|
+
);
|
|
221
209
|
}
|
|
222
|
-
|
|
223
|
-
// Dummy script module to ensure dependencies are loaded
|
|
224
|
-
wp_register_script_module(
|
|
225
|
-
'{{PAGE_SLUG}}',
|
|
226
|
-
$build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
|
|
227
|
-
$boot_dependencies
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
// Enqueue the boot scripts and styles
|
|
231
|
-
wp_enqueue_script( '{{PAGE_SLUG}}-prerequisites' );
|
|
232
|
-
wp_enqueue_script_module( '{{PAGE_SLUG}}' );
|
|
233
|
-
wp_enqueue_style( '{{PAGE_SLUG}}-prerequisites' );
|
|
234
210
|
}
|
|
235
211
|
|
|
236
|
-
//
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
color: #444;
|
|
248
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
249
|
-
font-size: 13px;
|
|
250
|
-
line-height: 1.4em;
|
|
251
|
-
}
|
|
252
|
-
body {
|
|
253
|
-
margin: 0;
|
|
254
|
-
}
|
|
255
|
-
#wpadminbar { display: none; }
|
|
256
|
-
</style>
|
|
257
|
-
<?php
|
|
258
|
-
global $hook_suffix;
|
|
259
|
-
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
260
|
-
$hook_suffix = '{{PAGE_SLUG}}';
|
|
261
|
-
|
|
262
|
-
// BEGIN see wp-admin/admin-header.php
|
|
263
|
-
print_admin_styles();
|
|
264
|
-
print_head_scripts();
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Fires in head section for a specific admin page.
|
|
268
|
-
*
|
|
269
|
-
* @since 2.1.0
|
|
270
|
-
*/
|
|
271
|
-
do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Fires in head section for all admin pages.
|
|
275
|
-
*
|
|
276
|
-
* @since 2.1.0
|
|
277
|
-
*/
|
|
278
|
-
do_action( 'admin_head' );
|
|
279
|
-
// END see wp-admin/admin-header.php
|
|
280
|
-
?>
|
|
281
|
-
</head>
|
|
282
|
-
<body class="{{PAGE_SLUG}}">
|
|
283
|
-
<div id="{{PAGE_SLUG}}-app" style="height: 100vh; box-sizing: border-box;"></div>
|
|
284
|
-
<?php
|
|
285
|
-
// BEGIN see wp-admin/admin-footer.php
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
* Prints scripts or data before the default footer scripts.
|
|
289
|
-
*
|
|
290
|
-
* @since 1.2.0
|
|
291
|
-
*/
|
|
292
|
-
do_action( 'admin_footer', '' );
|
|
293
|
-
|
|
294
|
-
// Print import map first so it's available for inline scripts
|
|
295
|
-
wp_script_modules()->print_import_map();
|
|
296
|
-
print_footer_scripts();
|
|
297
|
-
wp_script_modules()->print_enqueued_script_modules();
|
|
298
|
-
wp_script_modules()->print_script_module_preloads();
|
|
299
|
-
wp_script_modules()->print_script_module_data();
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Prints scripts or data after the default footer scripts.
|
|
303
|
-
*
|
|
304
|
-
* @since 2.8.0
|
|
305
|
-
*/
|
|
306
|
-
do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
|
307
|
-
// END see wp-admin/admin-footer.php
|
|
308
|
-
?>
|
|
309
|
-
</body>
|
|
310
|
-
</html>
|
|
311
|
-
<?php
|
|
312
|
-
exit;
|
|
212
|
+
// Dummy script module to ensure dependencies are loaded
|
|
213
|
+
wp_register_script_module(
|
|
214
|
+
'{{PAGE_SLUG}}',
|
|
215
|
+
$build_constants['build_url'] . 'pages/{{PAGE_SLUG}}/loader.js',
|
|
216
|
+
$boot_dependencies
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// Enqueue the boot scripts and styles
|
|
220
|
+
wp_enqueue_script( '{{PAGE_SLUG}}-prerequisites' );
|
|
221
|
+
wp_enqueue_script_module( '{{PAGE_SLUG}}' );
|
|
222
|
+
wp_enqueue_style( '{{PAGE_SLUG}}-prerequisites' );
|
|
313
223
|
}
|
|
314
|
-
}
|
|
315
224
|
|
|
316
|
-
|
|
225
|
+
// Output the HTML
|
|
226
|
+
?>
|
|
227
|
+
<!DOCTYPE html>
|
|
228
|
+
<html <?php language_attributes(); ?>>
|
|
229
|
+
<head>
|
|
230
|
+
<meta charset="<?php bloginfo( 'charset' ); ?>">
|
|
231
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
232
|
+
<title><?php echo esc_html( get_admin_page_title() ); ?></title>
|
|
233
|
+
<style>
|
|
234
|
+
html {
|
|
235
|
+
background: #f1f1f1;
|
|
236
|
+
color: #444;
|
|
237
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
238
|
+
font-size: 13px;
|
|
239
|
+
line-height: 1.4em;
|
|
240
|
+
}
|
|
241
|
+
body {
|
|
242
|
+
margin: 0;
|
|
243
|
+
}
|
|
244
|
+
#wpadminbar { display: none; }
|
|
245
|
+
</style>
|
|
246
|
+
<?php
|
|
247
|
+
global $hook_suffix;
|
|
248
|
+
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
|
|
249
|
+
$hook_suffix = '{{PAGE_SLUG}}';
|
|
250
|
+
|
|
251
|
+
// BEGIN see wp-admin/admin-header.php
|
|
252
|
+
print_admin_styles();
|
|
253
|
+
print_head_scripts();
|
|
254
|
+
|
|
317
255
|
/**
|
|
318
|
-
*
|
|
319
|
-
*
|
|
256
|
+
* Fires in head section for a specific admin page.
|
|
257
|
+
*
|
|
258
|
+
* @since 2.1.0
|
|
320
259
|
*/
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
260
|
+
do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Fires in head section for all admin pages.
|
|
264
|
+
*
|
|
265
|
+
* @since 2.1.0
|
|
266
|
+
*/
|
|
267
|
+
do_action( 'admin_head' );
|
|
268
|
+
// END see wp-admin/admin-header.php
|
|
269
|
+
?>
|
|
270
|
+
</head>
|
|
271
|
+
<body class="{{PAGE_SLUG}}">
|
|
272
|
+
<div id="{{PAGE_SLUG}}-app" style="height: 100vh; box-sizing: border-box;"></div>
|
|
273
|
+
<?php
|
|
274
|
+
// BEGIN see wp-admin/admin-footer.php
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Prints scripts or data before the default footer scripts.
|
|
278
|
+
*
|
|
279
|
+
* @since 1.2.0
|
|
280
|
+
*/
|
|
281
|
+
do_action( 'admin_footer', '' );
|
|
282
|
+
|
|
283
|
+
// Print import map first so it's available for inline scripts
|
|
284
|
+
wp_script_modules()->print_import_map();
|
|
285
|
+
print_footer_scripts();
|
|
286
|
+
wp_script_modules()->print_enqueued_script_modules();
|
|
287
|
+
wp_script_modules()->print_script_module_preloads();
|
|
288
|
+
wp_script_modules()->print_script_module_data();
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Prints scripts or data after the default footer scripts.
|
|
292
|
+
*
|
|
293
|
+
* @since 2.8.0
|
|
294
|
+
*/
|
|
295
|
+
do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
|
|
296
|
+
// END see wp-admin/admin-footer.php
|
|
297
|
+
?>
|
|
298
|
+
</body>
|
|
299
|
+
</html>
|
|
300
|
+
<?php
|
|
301
|
+
exit;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Intercept admin_init to render the page early.
|
|
306
|
+
* This bypasses the default WordPress admin template.
|
|
307
|
+
*/
|
|
308
|
+
function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() {
|
|
309
|
+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
|
310
|
+
if ( isset( $_GET['page'] ) && '{{PAGE_SLUG}}' === $_GET['page'] ) {
|
|
311
|
+
{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page();
|
|
312
|
+
exit;
|
|
327
313
|
}
|
|
328
314
|
}
|
|
329
315
|
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
// Page-specific route registration functions for {{PAGE_SLUG}}
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
{{PREFIX}}_register_page_routes( ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data, '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_route' );
|
|
9
|
-
}
|
|
2
|
+
/**
|
|
3
|
+
* Register routes for {{PAGE_SLUG}} page (full-page mode).
|
|
4
|
+
*/
|
|
5
|
+
function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_page_routes() {
|
|
6
|
+
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data;
|
|
7
|
+
{{PREFIX}}_register_page_routes( ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data, '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_route' );
|
|
10
8
|
}
|
|
11
9
|
add_action( '{{PAGE_SLUG}}_init', '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_page_routes' );
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
{{PREFIX}}_register_page_routes( ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data, '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_route' );
|
|
20
|
-
}
|
|
11
|
+
/**
|
|
12
|
+
* Register routes for {{PAGE_SLUG}} page (wp-admin mode).
|
|
13
|
+
*/
|
|
14
|
+
function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_page_routes() {
|
|
15
|
+
global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data;
|
|
16
|
+
{{PREFIX}}_register_page_routes( ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data, '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_route' );
|
|
21
17
|
}
|
|
22
18
|
add_action( '{{PAGE_SLUG}}-wp-admin_init', '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_page_routes' );
|