PluginProbe
Gutenberg / 22.7.0
Gutenberg v22.7.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / pages / font-library / page.php

page.php in Gutenberg 22.7.0, at build/pages/font-library/page.php

332 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Page: font-library
4 * Auto-generated by build process.
5 * Do not edit this file manually.
6 *
7 * @package gutenberg
8 */
9
10 // Global storage for font-library routes and menu items
11 global $gutenberg_font_library_routes, $gutenberg_font_library_menu_items;
12 $gutenberg_font_library_routes = array();
13 $gutenberg_font_library_menu_items = array();
14
15 if ( ! function_exists( 'gutenberg_register_font_library_route' ) ) {
16 /**
17 * Register a route for the font-library 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 gutenberg_register_font_library_route( $path, $content_module = null, $route_module = null ) {
24 global $gutenberg_font_library_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 }
33
34 $gutenberg_font_library_routes[] = $route;
35 }
36 }
37
38 if ( ! function_exists( 'gutenberg_register_font_library_menu_item' ) ) {
39 /**
40 * Register a menu item for the font-library 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 gutenberg_register_font_library_menu_item( $id, $label, $to, $parent_id = '', $parent_type = '' ) {
49 global $gutenberg_font_library_menu_items;
50
51 $menu_item = array(
52 'id' => $id,
53 'label' => $label,
54 'to' => $to,
55 );
56
57 if ( ! empty( $parent_id ) ) {
58 $menu_item['parent'] = $parent_id;
59 }
60
61 if ( ! empty( $parent_type ) && in_array( $parent_type, array( 'drilldown', 'dropdown' ), true ) ) {
62 $menu_item['parent_type'] = $parent_type;
63 }
64
65 $gutenberg_font_library_menu_items[] = $menu_item;
66 }
67 }
68
69 if ( ! function_exists( 'gutenberg_get_font_library_routes' ) ) {
70 /**
71 * Get all registered routes for the font-library page.
72 *
73 * @return array Array of route objects.
74 */
75 function gutenberg_get_font_library_routes() {
76 global $gutenberg_font_library_routes;
77 return $gutenberg_font_library_routes ?? array();
78 }
79 }
80
81 if ( ! function_exists( 'gutenberg_get_font_library_menu_items' ) ) {
82 /**
83 * Get all registered menu items for the font-library page.
84 *
85 * @return array Array of menu item objects.
86 */
87 function gutenberg_get_font_library_menu_items() {
88 global $gutenberg_font_library_menu_items;
89 return $gutenberg_font_library_menu_items ?? array();
90 }
91 }
92
93 if ( ! function_exists( 'gutenberg_font_library_preload_data' ) ) {
94 /**
95 * Preload REST API data for the font-library page.
96 * Automatically called during page rendering.
97 */
98 function gutenberg_font_library_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 );
105
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 );
112
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 );
122 }
123 }
124
125 if ( ! function_exists( 'gutenberg_font_library_render_page' ) ) {
126 /**
127 * Render the font-library page.
128 * Call this function from add_menu_page or add_submenu_page.
129 */
130 function gutenberg_font_library_render_page() {
131 // Load build constants
132 $build_constants = require __DIR__ . '/../../constants.php';
133
134 // Set current screen
135 set_current_screen();
136
137 // Remove unwanted deprecated handler
138 remove_action( 'admin_head', 'wp_admin_bar_header' );
139
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 }
147
148 // Fire init action for extensions to register routes and menu items
149 do_action( 'font-library_init' );
150
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 }
155
156 // Preload REST API data
157 gutenberg_font_library_preload_data();
158
159 // Get all registered routes and menu items
160 $menu_items = gutenberg_get_font_library_menu_items();
161 $routes = gutenberg_get_font_library_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( 'font-library-prerequisites', '', $asset['dependencies'], $asset['version'], true );
172
173 // Add inline script to initialize the app
174 $init_modules = [];
175 wp_add_inline_script(
176 'font-library-prerequisites',
177 sprintf(
178 'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));',
179 'font-library-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( 'font-library-prerequisites', false, $style_dependencies, $asset['version'] );
195
196 // Build dependencies for font-library module
197 $boot_dependencies = array(
198 array(
199 'import' => 'static',
200 'id' => '@wordpress/boot',
201 ),
202 );
203
204 // Add init modules as static dependencies
205 // No init modules configured
206
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 }
221 }
222
223 // Dummy script module to ensure dependencies are loaded
224 wp_register_script_module(
225 'font-library',
226 $build_constants['build_url'] . 'pages/font-library/loader.js',
227 $boot_dependencies
228 );
229
230 // Enqueue the boot scripts and styles
231 wp_enqueue_script( 'font-library-prerequisites' );
232 wp_enqueue_script_module( 'font-library' );
233 wp_enqueue_style( 'font-library-prerequisites' );
234 }
235
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 = 'font-library';
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="font-library">
283 <div id="font-library-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;
313 }
314 }
315
316 if ( ! function_exists( 'gutenberg_font_library_intercept_render' ) ) {
317 /**
318 * Intercept admin_init to render the page early.
319 * This bypasses the default WordPress admin template.
320 */
321 function gutenberg_font_library_intercept_render() {
322 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
323 if ( isset( $_GET['page'] ) && 'font-library' === $_GET['page'] ) {
324 gutenberg_font_library_render_page();
325 exit;
326 }
327 }
328 }
329
330 // Hook the interceptor to admin_init
331 add_action( 'admin_init', 'gutenberg_font_library_intercept_render' );
332