[ 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  /**
  19   * Register a route for the font-library-wp-admin page.
  20   *
  21   * @param string      $path           Route path (e.g., '/types/$type/edit/$id').
  22   * @param string|null $content_module Script module ID for content (stage/inspector).
  23   * @param string|null $route_module   Script module ID for route lifecycle hooks.
  24   */
  25  function wp_register_font_library_wp_admin_route( $path, $content_module = null, $route_module = null ) {
  26      global $wp_font_library_wp_admin_routes;
  27  
  28      $route = array( 'path' => $path );
  29      if ( ! empty( $content_module ) ) {
  30          $route['content_module'] = $content_module;
  31      }
  32      if ( ! empty( $route_module ) ) {
  33          $route['route_module'] = $route_module;
  34      }
  35  
  36      $wp_font_library_wp_admin_routes[] = $route;
  37  }
  38  
  39  /**
  40   * Register a menu item for the font-library-wp-admin page.
  41   * Note: Menu items are registered but not displayed in single-page mode.
  42   *
  43   * @param string $id        Menu item ID.
  44   * @param string $label     Display label.
  45   * @param string $to        Route path to navigate to.
  46   * @param string $parent_id Optional. Parent menu item ID.
  47   */
  48  function wp_register_font_library_wp_admin_menu_item( $id, $label, $to, $parent_id = '' ) {
  49      global $wp_font_library_wp_admin_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      $wp_font_library_wp_admin_menu_items[] = $menu_item;
  62  }
  63  
  64  /**
  65   * Get all registered routes for the font-library-wp-admin page.
  66   *
  67   * @return array Array of route objects.
  68   */
  69  function wp_get_font_library_wp_admin_routes() {
  70      global $wp_font_library_wp_admin_routes;
  71      return $wp_font_library_wp_admin_routes ?? array();
  72  }
  73  
  74  /**
  75   * Get all registered menu items for the font-library-wp-admin page.
  76   *
  77   * @return array Array of menu item objects.
  78   */
  79  function wp_get_font_library_wp_admin_menu_items() {
  80      global $wp_font_library_wp_admin_menu_items;
  81      return $wp_font_library_wp_admin_menu_items ?? array();
  82  }
  83  
  84  /**
  85   * Preload REST API data for the font-library-wp-admin page.
  86   * Automatically called during page rendering.
  87   */
  88  function wp_font_library_wp_admin_preload_data() {
  89      // Define paths to preload - same for all pages
  90      // This must exactly match the _fields list in packages/core-data/src/entities.js,
  91      // same fields in the same order, or the preload is never consumed.
  92      $preload_paths = array(
  93          '/?_fields=description,generate_animated_image_subsizes,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,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      /**
  98       * Filters the REST API paths preloaded for this page.
  99       *
 100       * Each entry is either a string path (GET) or a `[ path, method ]` tuple.
 101       * Pages that know which requests their JS will issue on mount can add
 102       * them here so the responses are embedded in the initial HTML rather
 103       * than fetched over the network after hydration.
 104       *
 105       * @param array<string|string[]> $preload_paths Paths to preload.
 106       */
 107      $preload_paths = apply_filters( 'wp_font_library_wp_admin_preload_paths', $preload_paths );
 108  
 109      // Use rest_preload_api_request to gather the preloaded data
 110      $preload_data = array_reduce(
 111          $preload_paths,
 112          'rest_preload_api_request',
 113          array()
 114      );
 115  
 116      // Register the preloading middleware with wp-api-fetch
 117      wp_add_inline_script(
 118          'wp-api-fetch',
 119          sprintf(
 120              'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
 121              wp_json_encode( $preload_data )
 122          ),
 123          'after'
 124      );
 125  }
 126  
 127  /**
 128   * Enqueue scripts and styles for the font-library-wp-admin page.
 129   * Hooked to admin_enqueue_scripts.
 130   *
 131   * @param string $hook_suffix The current admin page.
 132   */
 133  function wp_font_library_wp_admin_enqueue_scripts( $hook_suffix ) {
 134      // Check all possible ways this page can be accessed:
 135      // 1. Menu page via admin.php?page=font-library-wp-admin (plugin)
 136      // 2. Direct file via font-library.php (Core) - screen ID will be 'font-library'
 137      $current_screen = get_current_screen();
 138      $is_our_page = (
 139          ( isset( $_GET['page'] ) && 'font-library-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 140          ( $current_screen && 'font-library' === $current_screen->id )
 141      );
 142  
 143      if ( ! $is_our_page ) {
 144          return;
 145      }
 146  
 147      // Load build constants
 148      $build_constants = require  __DIR__ . '/../../constants.php';
 149  
 150      /**
 151       * Fires when the font-library admin page is initialized so extensions can register routes and menu items.
 152       */
 153      do_action( 'font-library-wp-admin_init' );
 154  
 155      // Preload REST API data
 156      wp_font_library_wp_admin_preload_data();
 157  
 158      // Get all registered routes
 159      $routes = wp_get_font_library_wp_admin_routes();
 160  
 161      // Get boot module asset file for dependencies. Plugins that build their own
 162      // boot module use it; everyone else falls back to the copy bundled with Core.
 163      $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
 164      if ( ! file_exists( $asset_file ) ) {
 165          $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
 166      }
 167      if ( file_exists( $asset_file ) ) {
 168          $asset = require $asset_file;
 169  
 170          // This script serves two purposes:
 171          // 1. It ensures all the globals that are made available to the modules are loaded.
 172          // 2. It initializes the boot module as an inline script.
 173          wp_register_script( 'font-library-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
 174  
 175          $init_modules = [];
 176  
 177          /*
 178           * Add inline script to initialize the app using initSinglePage (no menuItems).
 179           * The dynamic import is deferred until DOMContentLoaded so that all classic
 180           * script dependencies of @wordpress/boot (wp-private-apis, wp-components,
 181           * wp-theme, etc.) have finished parsing and executing before the boot module
 182           * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race
 183           * against the classic-script-printing pass on fast CDN-fronted hosts in
 184           * Chrome, evaluating before wp.theme.privateApis is defined and throwing
 185           * "Cannot unlock an undefined object". See <https://core.trac.wordpress.org/ticket/65103>.
 186           */
 187          $init_js_function = <<<'JS'
 188          ( mountId, routes, initModules ) => {
 189              const run = async () => {
 190                  const mod = await import( "@wordpress/boot" );
 191                  mod.initSinglePage( { mountId, routes, initModules } );
 192              };
 193              if ( document.readyState === "loading" ) {
 194                  document.addEventListener( "DOMContentLoaded", run );
 195              } else {
 196                  run();
 197              }
 198          }
 199          JS;
 200          wp_add_inline_script(
 201              'font-library-wp-admin-prerequisites',
 202              sprintf(
 203                  '( %s )( %s, %s, %s );',
 204                  $init_js_function,
 205                  wp_json_encode( 'font-library-wp-admin-app', JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
 206                  wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
 207                  wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
 208              )
 209          );
 210  
 211          // Register prerequisites style by filtering script dependencies to find registered styles
 212          $style_dependencies = array_filter(
 213              $asset['dependencies'],
 214              function ( $handle ) {
 215                  return wp_style_is( $handle, 'registered' );
 216              }
 217          );
 218          wp_register_style( 'font-library-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
 219  
 220          // Build dependencies for font-library-wp-admin module
 221          $boot_dependencies = array(
 222              array(
 223                  'import' => 'static',
 224                  'id'     => '@wordpress/boot',
 225              ),
 226          );
 227  
 228          // Add init modules as static dependencies
 229              // No init modules configured
 230  
 231          // Add all registered routes as dependencies
 232          foreach ( $routes as $route ) {
 233              if ( isset( $route['route_module'] ) ) {
 234                  $boot_dependencies[] = array(
 235                      'import' => 'static',
 236                      'id'     => $route['route_module'],
 237                  );
 238              }
 239              if ( isset( $route['content_module'] ) ) {
 240                  $boot_dependencies[] = array(
 241                      'import' => 'dynamic',
 242                      'id'     => $route['content_module'],
 243                  );
 244              }
 245          }
 246  
 247          /**
 248           * Filters the boot script-module dependencies for the
 249           * font-library-wp-admin page.
 250           *
 251           * Surfaces extending this page can append entries to the boot
 252           * dependency list. Each entry is an array with 'import' (string
 253           * 'static' or 'dynamic') and 'id' (script-module handle) keys.
 254           *
 255           * @param array $boot_dependencies Boot dependencies for the page.
 256           */
 257          $boot_dependencies = apply_filters(
 258              'font-library-wp-admin_boot_dependencies',
 259              $boot_dependencies
 260          );
 261  
 262          // Dummy script module to ensure dependencies are loaded
 263          wp_register_script_module(
 264              'font-library-wp-admin',
 265              $build_constants['build_url'] . 'pages/font-library/loader.js',
 266              $boot_dependencies
 267          );
 268  
 269          // Enqueue the boot scripts and styles
 270          wp_enqueue_script( 'font-library-wp-admin-prerequisites' );
 271          wp_enqueue_script_module( 'font-library-wp-admin' );
 272          wp_enqueue_style( 'font-library-wp-admin-prerequisites' );
 273      }
 274  }
 275  
 276  /**
 277   * Render the font-library-wp-admin page.
 278   * Call this function from add_menu_page or add_submenu_page.
 279   * This renders within the normal WordPress admin interface.
 280   */
 281  function wp_font_library_wp_admin_render_page() {
 282      ?>
 283      <style>
 284          /* Critical styles to prevent layout shifts - inlined for immediate application */
 285  
 286          #wpwrap {
 287              overflow-y: auto;
 288          }
 289          body.js {
 290              background: #fff;
 291          }
 292  
 293          /* Reset wp-admin padding */
 294          body.js #wpcontent {
 295              padding-inline-start: 0;
 296          }
 297          body.js #wpbody-content {
 298              padding-bottom: 0;
 299          }
 300  
 301          /* Hide legacy admin elements */
 302          body.js #wpbody-content > div:not(#font-library-wp-admin-app):not(#screen-meta) {
 303              display: none;
 304          }
 305          body.js #wpfooter {
 306              display: none;
 307          }
 308  
 309          /* Accessibility regions */
 310          .a11y-speak-region {
 311              inset-inline-start: -1px;
 312              top: -1px;
 313          }
 314  
 315          /* Admin menu indicators */
 316          ul#adminmenu a.wp-has-current-submenu::after,
 317          ul#adminmenu > li.current > a.current::after {
 318              border-inline-end-color: #fff;
 319          }
 320  
 321          /* Media frame fix */
 322          .media-frame select.attachment-filters:last-of-type {
 323              width: auto;
 324              max-width: 100%;
 325          }
 326  
 327          /* Responsive overflow fix for #wpwrap */
 328          @media (min-width: 782px) {
 329              #wpwrap {
 330                  overflow-y: initial;
 331              }
 332          }
 333      </style>
 334      <div class="wrap hide-if-js">
 335          <h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
 336          <?php
 337          wp_admin_notice(
 338              __( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
 339              array( 'type' => 'error' )
 340          );
 341          ?>
 342      </div>
 343      <?php
 344      // Core's pre-CSS Modules Boot layout uses this class for viewport sizing.
 345      // Remove it when the minimum supported WordPress version includes the Boot
 346      // changes from Gutenberg #81756.
 347      ?>
 348      <div id="font-library-wp-admin-app" class="boot-layout-container"></div>
 349      <?php
 350  }
 351  
 352  // Hook the enqueue function to admin_enqueue_scripts
 353  add_action( 'admin_enqueue_scripts', 'wp_font_library_wp_admin_enqueue_scripts' );


Generated : Tue Nov 3 08:20:36 2026 Cross-referenced by PHPXref