@wordpress/build 0.9.0 → 0.10.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.
@@ -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
- if ( ! function_exists( '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_route' ) ) {
16
- /**
17
- * Register a route for the {{PAGE_SLUG}} page.
18
- *
19
- * @param string $path Route path (e.g., '/types/$type/edit/$id').
20
- * @param string|null $content_module Script module ID for content (stage/inspector).
21
- * @param string|null $route_module Script module ID for route lifecycle hooks.
22
- */
23
- function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_route( $path, $content_module = null, $route_module = null ) {
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
- ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes[] = $route;
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
- if ( ! function_exists( '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_menu_item' ) ) {
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
- $menu_item = array(
52
- 'id' => $id,
53
- 'label' => $label,
54
- 'to' => $to,
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
- if ( ! empty( $parent_id ) ) {
58
- $menu_item['parent'] = $parent_id;
59
- }
48
+ $menu_item = array(
49
+ 'id' => $id,
50
+ 'label' => $label,
51
+ 'to' => $to,
52
+ );
60
53
 
61
- if ( ! empty( $parent_type ) && in_array( $parent_type, array( 'drilldown', 'dropdown' ), true ) ) {
62
- $menu_item['parent_type'] = $parent_type;
63
- }
54
+ if ( ! empty( $parent_id ) ) {
55
+ $menu_item['parent'] = $parent_id;
56
+ }
64
57
 
65
- ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items[] = $menu_item;
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
- if ( ! function_exists( '{{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_routes' ) ) {
70
- /**
71
- * Get all registered routes for the {{PAGE_SLUG}} page.
72
- *
73
- * @return array Array of route objects.
74
- */
75
- function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_routes() {
76
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes;
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
- if ( ! function_exists( '{{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items' ) ) {
82
- /**
83
- * Get all registered menu items for the {{PAGE_SLUG}} page.
84
- *
85
- * @return array Array of menu item objects.
86
- */
87
- function {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items() {
88
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_menu_items;
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
- if ( ! function_exists( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data' ) ) {
94
- /**
95
- * Preload REST API data for the {{PAGE_SLUG}} page.
96
- * Automatically called during page rendering.
97
- */
98
- function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data() {
99
- // Define paths to preload - same for all pages
100
- // Please also change packages/core-data/src/entities.js when changing this.
101
- $preload_paths = array(
102
- '/?_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',
103
- array( '/wp/v2/settings', 'OPTIONS' ),
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
- // Use rest_preload_api_request to gather the preloaded data
107
- $preload_data = array_reduce(
108
- $preload_paths,
109
- 'rest_preload_api_request',
110
- array()
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
- // Register the preloading middleware with wp-api-fetch
114
- wp_add_inline_script(
115
- 'wp-api-fetch',
116
- sprintf(
117
- 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
118
- wp_json_encode( $preload_data )
119
- ),
120
- 'after'
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
- if ( ! function_exists( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page' ) ) {
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
- // Set current screen
135
- set_current_screen();
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
- // Remove unwanted deprecated handler
138
- remove_action( 'admin_head', 'wp_admin_bar_header' );
145
+ // Preload REST API data
146
+ {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data();
139
147
 
140
- // Remove unwanted scripts and styles that were enqueued during `admin_init`
141
- foreach ( wp_scripts()->queue as $script ) {
142
- wp_dequeue_script( $script );
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
- // Fire init action for extensions to register routes and menu items
149
- do_action( '{{PAGE_SLUG}}_init' );
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
- // Enqueue command palette assets for boot-based pages
152
- if ( function_exists( 'wp_enqueue_command_palette_assets' ) ) {
153
- wp_enqueue_command_palette_assets();
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
- // Preload REST API data
157
- {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_preload_data();
158
-
159
- // Get all registered routes and menu items
160
- $menu_items = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_menu_items();
161
- $routes = {{PREFIX}}_get_{{PAGE_SLUG_UNDERSCORE}}_routes();
162
-
163
- // Get boot module asset file for dependencies
164
- $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
165
- if ( file_exists( $asset_file ) ) {
166
- $asset = require $asset_file;
167
-
168
- // This script serves two purposes:
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
- // Add init modules as static dependencies
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
- // Add all registered routes as dependencies
208
- foreach ( $routes as $route ) {
209
- if ( isset( $route['route_module'] ) ) {
210
- $boot_dependencies[] = array(
211
- 'import' => 'static',
212
- 'id' => $route['route_module'],
213
- );
214
- }
215
- if ( isset( $route['content_module'] ) ) {
216
- $boot_dependencies[] = array(
217
- 'import' => 'dynamic',
218
- 'id' => $route['content_module'],
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
- // Output the HTML
237
- ?>
238
- <!DOCTYPE html>
239
- <html <?php language_attributes(); ?>>
240
- <head>
241
- <meta charset="<?php bloginfo( 'charset' ); ?>">
242
- <meta name="viewport" content="width=device-width, initial-scale=1">
243
- <title><?php echo esc_html( get_admin_page_title() ); ?></title>
244
- <style>
245
- html {
246
- background: #f1f1f1;
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
- if ( ! function_exists( '{{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render' ) ) {
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
- * Intercept admin_init to render the page early.
319
- * This bypasses the default WordPress admin template.
256
+ * Fires in head section for a specific admin page.
257
+ *
258
+ * @since 2.1.0
320
259
  */
321
- function {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_intercept_render() {
322
- // phpcs:ignore WordPress.Security.NonceVerification.Recommended
323
- if ( isset( $_GET['page'] ) && '{{PAGE_SLUG}}' === $_GET['page'] ) {
324
- {{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_render_page();
325
- exit;
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
- if ( ! function_exists( '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_page_routes' ) ) {
3
- /**
4
- * Register routes for {{PAGE_SLUG}} page (full-page mode).
5
- */
6
- function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_page_routes() {
7
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data;
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
- if ( ! function_exists( '{{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_page_routes' ) ) {
14
- /**
15
- * Register routes for {{PAGE_SLUG}} page (wp-admin mode).
16
- */
17
- function {{PREFIX}}_register_{{PAGE_SLUG_UNDERSCORE}}_wp_admin_page_routes() {
18
- global ${{PREFIX}}_{{PAGE_SLUG_UNDERSCORE}}_routes_data;
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' );