[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/build/pages/font-library/ -> page-wp-admin.php (source)

   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 wp
  11   */
  12  
  13  // Global storage for font-library routes and menu items
  14  global $wp_font_library_wp_admin_routes, $wp_font_library_wp_admin_menu_items;
  15  $wp_font_library_wp_admin_routes = array();
  16  $wp_font_library_wp_admin_menu_items = array();
  17  
  18  if ( ! function_exists( '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 register_font_library_wp_admin_route( $path, $content_module = null, $route_module = null ) {
  27          global $wp_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          $wp_font_library_wp_admin_routes[] = $route;
  38      }
  39  }
  40  
  41  if ( ! function_exists( '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 register_font_library_wp_admin_menu_item( $id, $label, $to, $parent_id = '' ) {
  52          global $wp_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          $wp_font_library_wp_admin_menu_items[] = $menu_item;
  65      }
  66  }
  67  
  68  if ( ! function_exists( '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 get_font_library_wp_admin_routes() {
  75          global $wp_font_library_wp_admin_routes;
  76          return $wp_font_library_wp_admin_routes ?? array();
  77      }
  78  }
  79  
  80  if ( ! function_exists( '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 get_font_library_wp_admin_menu_items() {
  87          global $wp_font_library_wp_admin_menu_items;
  88          return $wp_font_library_wp_admin_menu_items ?? array();
  89      }
  90  }
  91  
  92  if ( ! function_exists( '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 font_library_wp_admin_preload_data() {
  98          // Define paths to preload - same for all pages
  99          $preload_paths = array(
 100              '/?_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',
 101              array( '/wp/v2/settings', 'OPTIONS' ),
 102          );
 103  
 104          // Use rest_preload_api_request to gather the preloaded data
 105          $preload_data = array_reduce(
 106              $preload_paths,
 107              'rest_preload_api_request',
 108              array()
 109          );
 110  
 111          // Register the preloading middleware with wp-api-fetch
 112          wp_add_inline_script(
 113              'wp-api-fetch',
 114              sprintf(
 115                  'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
 116                  wp_json_encode( $preload_data )
 117              ),
 118              'after'
 119          );
 120      }
 121  }
 122  
 123  if ( ! function_exists( 'font_library_wp_admin_enqueue_scripts' ) ) {
 124      /**
 125       * Enqueue scripts and styles for the font-library-wp-admin page.
 126       * Hooked to admin_enqueue_scripts.
 127       *
 128       * @param string $hook_suffix The current admin page.
 129       */
 130  	function font_library_wp_admin_enqueue_scripts( $hook_suffix ) {
 131          // Check all possible ways this page can be accessed:
 132          // 1. Menu page via admin.php?page=font-library-wp-admin (plugin)
 133          // 2. Direct file via font-library.php (Core) - screen ID will be 'font-library'
 134          $current_screen = get_current_screen();
 135          $is_our_page = (
 136              ( isset( $_GET['page'] ) && 'font-library-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 137              ( $current_screen && 'font-library' === $current_screen->id )
 138          );
 139  
 140          if ( ! $is_our_page ) {
 141              return;
 142          }
 143  
 144          // Fire init action for extensions to register routes and menu items
 145          do_action( 'font-library-wp-admin_init' );
 146  
 147          // Preload REST API data
 148          font_library_wp_admin_preload_data();
 149  
 150          // Get all registered routes
 151          $routes = get_font_library_wp_admin_routes();
 152  
 153          // Get boot module asset file for dependencies
 154          $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
 155          if ( file_exists( $asset_file ) ) {
 156              $asset = require $asset_file;
 157  
 158              // This script serves two purposes:
 159              // 1. It ensures all the globals that are made available to the modules are loaded.
 160              // 2. It initializes the boot module as an inline script.
 161              wp_register_script( 'font-library-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
 162  
 163              // Add inline script to initialize the app using initSinglePage (no menuItems)
 164              wp_add_inline_script(
 165                  'font-library-wp-admin-prerequisites',
 166                  sprintf(
 167                      'import("@wordpress/boot").then(mod => mod.initSinglePage({mountId: "%s", routes: %s}));',
 168                      'font-library-wp-admin-app',
 169                      wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
 170                  )
 171              );
 172  
 173              // Register prerequisites style by filtering script dependencies to find registered styles
 174              $style_dependencies = array_filter(
 175                  $asset['dependencies'],
 176                  function ( $handle ) {
 177                      return wp_style_is( $handle, 'registered' );
 178                  }
 179              );
 180              wp_register_style( 'font-library-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
 181  
 182              // Build dependencies for font-library-wp-admin module
 183              $boot_dependencies = array(
 184                  array(
 185                      'import' => 'static',
 186                      'id'     => '@wordpress/boot',
 187                  ),
 188              );
 189  
 190              // Add all registered routes as dependencies
 191              foreach ( $routes as $route ) {
 192                  if ( isset( $route['route_module'] ) ) {
 193                      $boot_dependencies[] = array(
 194                          'import' => 'static',
 195                          'id'     => $route['route_module'],
 196                      );
 197                  }
 198                  if ( isset( $route['content_module'] ) ) {
 199                      $boot_dependencies[] = array(
 200                          'import' => 'dynamic',
 201                          'id'     => $route['content_module'],
 202                      );
 203                  }
 204              }
 205  
 206              // Dummy script module to ensure dependencies are loaded
 207              wp_register_script_module(
 208                  'font-library-wp-admin',
 209                  includes_url( 'build' ) . '/pages/font-library/loader.js',
 210                  $boot_dependencies
 211              );
 212  
 213              // Enqueue the boot scripts and styles
 214              wp_enqueue_script( 'font-library-wp-admin-prerequisites' );
 215              wp_enqueue_script_module( 'font-library-wp-admin' );
 216              wp_enqueue_style( 'font-library-wp-admin-prerequisites' );
 217          }
 218      }
 219  }
 220  
 221  if ( ! function_exists( 'font_library_wp_admin_render_page' ) ) {
 222      /**
 223       * Render the font-library-wp-admin page.
 224       * Call this function from add_menu_page or add_submenu_page.
 225       * This renders within the normal WordPress admin interface.
 226       */
 227  	function font_library_wp_admin_render_page() {
 228          ?>
 229          <style>
 230              /* Critical styles to prevent layout shifts - inlined for immediate application */
 231  
 232              /* Background colors */
 233              #wpwrap {
 234                  background: var(--wpds-color-fg-content-neutral, #1e1e1e);
 235                  overflow-y: auto;
 236              }
 237              body {
 238                  background: #fff;
 239              }
 240  
 241              /* Reset wp-admin padding */
 242              #wpcontent {
 243                  padding-left: 0;
 244              }
 245              #wpbody-content {
 246                  padding-bottom: 0;
 247              }
 248  
 249              /* Hide legacy admin elements */
 250              #wpbody-content > div:not(.boot-layout-container):not(#screen-meta) {
 251                  display: none;
 252              }
 253              #wpfooter {
 254                  display: none;
 255              }
 256  
 257              /* Accessibility regions */
 258              .a11y-speak-region {
 259                  left: -1px;
 260                  top: -1px;
 261              }
 262  
 263              /* Admin menu indicators */
 264              ul#adminmenu a.wp-has-current-submenu::after,
 265              ul#adminmenu > li.current > a.current::after {
 266                  border-right-color: #fff;
 267              }
 268  
 269              /* Media frame fix */
 270              .media-frame select.attachment-filters:last-of-type {
 271                  width: auto;
 272                  max-width: 100%;
 273              }
 274  
 275              /* Responsive overflow fix for #wpwrap */
 276              @media (min-width: 782px) {
 277                  #wpwrap {
 278                      overflow-y: initial;
 279                  }
 280              }
 281          </style>
 282          <div id="font-library-wp-admin-app" class="boot-layout-container"></div>
 283          <?php
 284      }
 285  }
 286  
 287  // Hook the enqueue function to admin_enqueue_scripts
 288  add_action( 'admin_enqueue_scripts', 'font_library_wp_admin_enqueue_scripts' );
 289  


Generated : Thu Jan 15 08:20:04 2026 Cross-referenced by PHPXref