| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Page: site-editor 4 * Auto-generated by build process. 5 * Do not edit this file manually. 6 * 7 * @package wp 8 */ 9 10 // Global storage for site-editor routes and menu items 11 global $wp_site_editor_routes, $wp_site_editor_menu_items; 12 $wp_site_editor_routes = array(); 13 $wp_site_editor_menu_items = array(); 14 15 if ( ! function_exists( 'register_site_editor_route' ) ) { 16 /** 17 * Register a route for the site-editor 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 register_site_editor_route( $path, $content_module = null, $route_module = null ) { 24 global $wp_site_editor_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 $wp_site_editor_routes[] = $route; 35 } 36 } 37 38 if ( ! function_exists( 'register_site_editor_menu_item' ) ) { 39 /** 40 * Register a menu item for the site-editor 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 register_site_editor_menu_item( $id, $label, $to, $parent_id = '', $parent_type = '' ) { 49 global $wp_site_editor_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 $wp_site_editor_menu_items[] = $menu_item; 66 } 67 } 68 69 if ( ! function_exists( 'get_site_editor_routes' ) ) { 70 /** 71 * Get all registered routes for the site-editor page. 72 * 73 * @return array Array of route objects. 74 */ 75 function get_site_editor_routes() { 76 global $wp_site_editor_routes; 77 return $wp_site_editor_routes ?? array(); 78 } 79 } 80 81 if ( ! function_exists( 'get_site_editor_menu_items' ) ) { 82 /** 83 * Get all registered menu items for the site-editor page. 84 * 85 * @return array Array of menu item objects. 86 */ 87 function get_site_editor_menu_items() { 88 global $wp_site_editor_menu_items; 89 return $wp_site_editor_menu_items ?? array(); 90 } 91 } 92 93 if ( ! function_exists( 'site_editor_preload_data' ) ) { 94 /** 95 * Preload REST API data for the site-editor page. 96 * Automatically called during page rendering. 97 */ 98 function site_editor_preload_data() { 99 // Define paths to preload - same for all pages 100 $preload_paths = array( 101 '/?_fields=description,gmt_offset,home,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( 'site_editor_render_page' ) ) { 125 /** 126 * Render the site-editor page. 127 * Call this function from add_menu_page or add_submenu_page. 128 */ 129 function site_editor_render_page() { 130 // Set current screen 131 set_current_screen(); 132 133 // Remove unwanted deprecated handler 134 remove_action( 'admin_head', 'wp_admin_bar_header' ); 135 136 // Remove unwanted scripts and styles that were enqueued during `admin_init` 137 foreach ( wp_scripts()->queue as $script ) { 138 wp_dequeue_script( $script ); 139 } 140 foreach ( wp_styles()->queue as $style ) { 141 wp_dequeue_style( $style ); 142 } 143 144 // Fire init action for extensions to register routes and menu items 145 do_action( 'site-editor_init' ); 146 147 // Preload REST API data 148 site_editor_preload_data(); 149 150 // Get all registered routes and menu items 151 $menu_items = get_site_editor_menu_items(); 152 $routes = get_site_editor_routes(); 153 154 // Get boot module asset file for dependencies 155 $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php'; 156 if ( file_exists( $asset_file ) ) { 157 $asset = require $asset_file; 158 159 // This script serves two purposes: 160 // 1. It ensures all the globals that are made available to the modules are loaded. 161 // 2. It initializes the boot module as an inline script. 162 wp_register_script( 'site-editor-prerequisites', '', $asset['dependencies'], $asset['version'], true ); 163 164 // Add inline script to initialize the app 165 $init_modules = ["@wordpress/edit-site-init"]; 166 wp_add_inline_script( 167 'site-editor-prerequisites', 168 sprintf( 169 'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s}));', 170 'site-editor-app', 171 wp_json_encode( $menu_items, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), 172 wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ), 173 wp_json_encode( $init_modules, 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( 'site-editor-prerequisites', false, $style_dependencies, $asset['version'] ); 185 186 // Build dependencies for site-editor module 187 $boot_dependencies = array( 188 array( 189 'import' => 'static', 190 'id' => '@wordpress/boot', 191 ), 192 ); 193 194 // Add init modules as static dependencies 195 $boot_dependencies[] = array( 'import' => 'static', 'id' => '@wordpress/edit-site-init' ); 196 197 // Add all registered routes as dependencies 198 foreach ( $routes as $route ) { 199 if ( isset( $route['route_module'] ) ) { 200 $boot_dependencies[] = array( 201 'import' => 'static', 202 'id' => $route['route_module'], 203 ); 204 } 205 if ( isset( $route['content_module'] ) ) { 206 $boot_dependencies[] = array( 207 'import' => 'dynamic', 208 'id' => $route['content_module'], 209 ); 210 } 211 } 212 213 // Dummy script module to ensure dependencies are loaded 214 wp_register_script_module( 215 'site-editor', 216 includes_url( 'build' ) . '/pages/site-editor/loader.js', 217 $boot_dependencies 218 ); 219 220 // Enqueue the boot scripts and styles 221 wp_enqueue_script( 'site-editor-prerequisites' ); 222 wp_enqueue_script_module( 'site-editor' ); 223 wp_enqueue_style( 'site-editor-prerequisites' ); 224 } 225 226 // Output the HTML 227 ?> 228 <!DOCTYPE html> 229 <html <?php language_attributes(); ?>> 230 <head> 231 <meta charset="<?php bloginfo( 'charset' ); ?>"> 232 <meta name="viewport" content="width=device-width, initial-scale=1"> 233 <title><?php echo esc_html( get_admin_page_title() ); ?></title> 234 <style> 235 html { 236 background: #f1f1f1; 237 color: #444; 238 font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; 239 font-size: 13px; 240 line-height: 1.4em; 241 } 242 body { 243 margin: 0; 244 } 245 #wpadminbar { display: none; } 246 </style> 247 <?php 248 global $hook_suffix; 249 // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited 250 $hook_suffix = 'site-editor'; 251 252 // BEGIN see wp-admin/admin-header.php 253 print_admin_styles(); 254 print_head_scripts(); 255 256 /** 257 * Fires in head section for a specific admin page. 258 * 259 * @since 2.1.0 260 */ 261 do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 262 263 /** 264 * Fires in head section for all admin pages. 265 * 266 * @since 2.1.0 267 */ 268 do_action( 'admin_head' ); 269 // END see wp-admin/admin-header.php 270 ?> 271 </head> 272 <body class="site-editor"> 273 <div id="site-editor-app" style="height: 100vh; box-sizing: border-box;"></div> 274 <?php 275 // BEGIN see wp-admin/admin-footer.php 276 277 /** 278 * Prints scripts or data before the default footer scripts. 279 * 280 * @since 1.2.0 281 */ 282 do_action( 'admin_footer', '' ); 283 284 // Print import map first so it's available for inline scripts 285 wp_script_modules()->print_import_map(); 286 print_footer_scripts(); 287 wp_script_modules()->print_enqueued_script_modules(); 288 wp_script_modules()->print_script_module_preloads(); 289 wp_script_modules()->print_script_module_data(); 290 291 /** 292 * Prints scripts or data after the default footer scripts. 293 * 294 * @since 2.8.0 295 */ 296 do_action( "admin_footer-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores 297 // END see wp-admin/admin-footer.php 298 ?> 299 </body> 300 </html> 301 <?php 302 exit; 303 } 304 } 305 306 if ( ! function_exists( 'site_editor_intercept_render' ) ) { 307 /** 308 * Intercept admin_init to render the page early. 309 * This bypasses the default WordPress admin template. 310 */ 311 function site_editor_intercept_render() { 312 // phpcs:ignore WordPress.Security.NonceVerification.Recommended 313 if ( isset( $_GET['page'] ) && 'site-editor' === $_GET['page'] ) { 314 site_editor_render_page(); 315 exit; 316 } 317 } 318 } 319 320 // Hook the interceptor to admin_init 321 add_action( 'admin_init', 'site_editor_intercept_render' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Jan 15 08:20:04 2026 | Cross-referenced by PHPXref |