[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

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


Generated : Tue Jun 30 08:20:12 2026 Cross-referenced by PHPXref