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-wp-admin.php

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

294 lines 9.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 (wp-admin integrated)
4 * Auto-generated by build process.
5 * Do not edit this file manually.
6 *
7 * This version integrates with the standard WordPress admin interface,
8 * keeping the wp-admin sidebar and scripts/styles intact.
9 *
10 * @package gutenberg
11 */
12
13 // Global storage for font-library routes and menu items
14 global $gutenberg_font_library_wp_admin_routes, $gutenberg_font_library_wp_admin_menu_items;
15 $gutenberg_font_library_wp_admin_routes = array();
16 $gutenberg_font_library_wp_admin_menu_items = array();
17
18 if ( ! function_exists( 'gutenberg_register_font_library_wp_admin_route' ) ) {
19 /**
20 * Register a route for the font-library-wp-admin page.
21 *
22 * @param string $path Route path (e.g., '/types/$type/edit/$id').
23 * @param string|null $content_module Script module ID for content (stage/inspector).
24 * @param string|null $route_module Script module ID for route lifecycle hooks.
25 */
26 function gutenberg_register_font_library_wp_admin_route( $path, $content_module = null, $route_module = null ) {
27 global $gutenberg_font_library_wp_admin_routes;
28
29 $route = array( 'path' => $path );
30 if ( ! empty( $content_module ) ) {
31 $route['content_module'] = $content_module;
32 }
33 if ( ! empty( $route_module ) ) {
34 $route['route_module'] = $route_module;
35 }
36
37 $gutenberg_font_library_wp_admin_routes[] = $route;
38 }
39 }
40
41 if ( ! function_exists( 'gutenberg_register_font_library_wp_admin_menu_item' ) ) {
42 /**
43 * Register a menu item for the font-library-wp-admin page.
44 * Note: Menu items are registered but not displayed in single-page mode.
45 *
46 * @param string $id Menu item ID.
47 * @param string $label Display label.
48 * @param string $to Route path to navigate to.
49 * @param string $parent_id Optional. Parent menu item ID.
50 */
51 function gutenberg_register_font_library_wp_admin_menu_item( $id, $label, $to, $parent_id = '' ) {
52 global $gutenberg_font_library_wp_admin_menu_items;
53
54 $menu_item = array(
55 'id' => $id,
56 'label' => $label,
57 'to' => $to,
58 );
59
60 if ( ! empty( $parent_id ) ) {
61 $menu_item['parent'] = $parent_id;
62 }
63
64 $gutenberg_font_library_wp_admin_menu_items[] = $menu_item;
65 }
66 }
67
68 if ( ! function_exists( 'gutenberg_get_font_library_wp_admin_routes' ) ) {
69 /**
70 * Get all registered routes for the font-library-wp-admin page.
71 *
72 * @return array Array of route objects.
73 */
74 function gutenberg_get_font_library_wp_admin_routes() {
75 global $gutenberg_font_library_wp_admin_routes;
76 return $gutenberg_font_library_wp_admin_routes ?? array();
77 }
78 }
79
80 if ( ! function_exists( 'gutenberg_get_font_library_wp_admin_menu_items' ) ) {
81 /**
82 * Get all registered menu items for the font-library-wp-admin page.
83 *
84 * @return array Array of menu item objects.
85 */
86 function gutenberg_get_font_library_wp_admin_menu_items() {
87 global $gutenberg_font_library_wp_admin_menu_items;
88 return $gutenberg_font_library_wp_admin_menu_items ?? array();
89 }
90 }
91
92 if ( ! function_exists( 'gutenberg_font_library_wp_admin_preload_data' ) ) {
93 /**
94 * Preload REST API data for the font-library-wp-admin page.
95 * Automatically called during page rendering.
96 */
97 function gutenberg_font_library_wp_admin_preload_data() {
98 // Define paths to preload - same for all pages
99 // Please also change packages/core-data/src/entities.js when changing this.
100 $preload_paths = array(
101 '/?_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',
102 array( '/wp/v2/settings', 'OPTIONS' ),
103 );
104
105 // Use rest_preload_api_request to gather the preloaded data
106 $preload_data = array_reduce(
107 $preload_paths,
108 'rest_preload_api_request',
109 array()
110 );
111
112 // Register the preloading middleware with wp-api-fetch
113 wp_add_inline_script(
114 'wp-api-fetch',
115 sprintf(
116 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
117 wp_json_encode( $preload_data )
118 ),
119 'after'
120 );
121 }
122 }
123
124 if ( ! function_exists( 'gutenberg_font_library_wp_admin_enqueue_scripts' ) ) {
125 /**
126 * Enqueue scripts and styles for the font-library-wp-admin page.
127 * Hooked to admin_enqueue_scripts.
128 *
129 * @param string $hook_suffix The current admin page.
130 */
131 function gutenberg_font_library_wp_admin_enqueue_scripts( $hook_suffix ) {
132 // Check all possible ways this page can be accessed:
133 // 1. Menu page via admin.php?page=font-library-wp-admin (plugin)
134 // 2. Direct file via font-library.php (Core) - screen ID will be 'font-library'
135 $current_screen = get_current_screen();
136 $is_our_page = (
137 ( isset( $_GET['page'] ) && 'font-library-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
138 ( $current_screen && 'font-library' === $current_screen->id )
139 );
140
141 if ( ! $is_our_page ) {
142 return;
143 }
144
145 // Load build constants
146 $build_constants = require __DIR__ . '/../../constants.php';
147
148 // Fire init action for extensions to register routes and menu items
149 do_action( 'font-library-wp-admin_init' );
150
151 // Preload REST API data
152 gutenberg_font_library_wp_admin_preload_data();
153
154 // Get all registered routes
155 $routes = gutenberg_get_font_library_wp_admin_routes();
156
157 // Get boot module asset file for dependencies
158 $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
159 if ( file_exists( $asset_file ) ) {
160 $asset = require $asset_file;
161
162 // This script serves two purposes:
163 // 1. It ensures all the globals that are made available to the modules are loaded.
164 // 2. It initializes the boot module as an inline script.
165 wp_register_script( 'font-library-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
166
167 // Add inline script to initialize the app using initSinglePage (no menuItems)
168 wp_add_inline_script(
169 'font-library-wp-admin-prerequisites',
170 sprintf(
171 'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));',
172 'font-library-wp-admin-app',
173 wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
174 )
175 );
176
177 // Register prerequisites style by filtering script dependencies to find registered styles
178 $style_dependencies = array_filter(
179 $asset['dependencies'],
180 function ( $handle ) {
181 return wp_style_is( $handle, 'registered' );
182 }
183 );
184 wp_register_style( 'font-library-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
185
186 // Build dependencies for font-library-wp-admin module
187 $boot_dependencies = array(
188 array(
189 'import' => 'static',
190 'id' => '@wordpress/boot',
191 ),
192 );
193
194 // Add all registered routes as dependencies
195 foreach ( $routes as $route ) {
196 if ( isset( $route['route_module'] ) ) {
197 $boot_dependencies[] = array(
198 'import' => 'static',
199 'id' => $route['route_module'],
200 );
201 }
202 if ( isset( $route['content_module'] ) ) {
203 $boot_dependencies[] = array(
204 'import' => 'dynamic',
205 'id' => $route['content_module'],
206 );
207 }
208 }
209
210 // Dummy script module to ensure dependencies are loaded
211 wp_register_script_module(
212 'font-library-wp-admin',
213 $build_constants['build_url'] . 'pages/font-library/loader.js',
214 $boot_dependencies
215 );
216
217 // Enqueue the boot scripts and styles
218 wp_enqueue_script( 'font-library-wp-admin-prerequisites' );
219 wp_enqueue_script_module( 'font-library-wp-admin' );
220 wp_enqueue_style( 'font-library-wp-admin-prerequisites' );
221 }
222 }
223 }
224
225 if ( ! function_exists( 'gutenberg_font_library_wp_admin_render_page' ) ) {
226 /**
227 * Render the font-library-wp-admin page.
228 * Call this function from add_menu_page or add_submenu_page.
229 * This renders within the normal WordPress admin interface.
230 */
231 function gutenberg_font_library_wp_admin_render_page() {
232 ?>
233 <style>
234 /* Critical styles to prevent layout shifts - inlined for immediate application */
235
236 /* Background colors */
237 #wpwrap {
238 background: var(--wpds-color-fg-content-neutral, #1e1e1e);
239 overflow-y: auto;
240 }
241 body {
242 background: #fff;
243 }
244
245 /* Reset wp-admin padding */
246 #wpcontent {
247 padding-left: 0;
248 }
249 #wpbody-content {
250 padding-bottom: 0;
251 }
252
253 /* Hide legacy admin elements */
254 #wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
255 display: none;
256 }
257 #wpfooter {
258 display: none;
259 }
260
261 /* Accessibility regions */
262 .a11y-speak-region {
263 left: -1px;
264 top: -1px;
265 }
266
267 /* Admin menu indicators */
268 ul#adminmenu a.wp-has-current-submenu::after,
269 ul#adminmenu > li.current > a.current::after {
270 border-right-color: #fff;
271 }
272
273 /* Media frame fix */
274 .media-frame select.attachment-filters:last-of-type {
275 width: auto;
276 max-width: 100%;
277 }
278
279 /* Responsive overflow fix for #wpwrap */
280 @media (min-width: 782px) {
281 #wpwrap {
282 overflow-y: initial;
283 }
284 }
285 </style>
286 <div id="font-library-wp-admin-app" class="boot-layout-container"></div>
287 <?php
288 }
289 }
290
291 // Hook the enqueue function to admin_enqueue_scripts
292 add_action( 'admin_enqueue_scripts', 'gutenberg_font_library_wp_admin_enqueue_scripts' );
293
294