[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/build/pages/options-connectors/ -> page.php (source)

   1  <?php
   2  /**
   3   * Page: options-connectors
   4   * Auto-generated by build process.
   5   * Do not edit this file manually.
   6   *
   7   * @package wp
   8   */
   9  
  10  // Global storage for options-connectors routes and menu items
  11  global $wp_options_connectors_routes, $wp_options_connectors_menu_items;
  12  $wp_options_connectors_routes     = array();
  13  $wp_options_connectors_menu_items = array();
  14  
  15  /**
  16   * Register a route for the options-connectors page.
  17   *
  18   * @param string      $path           Route path (e.g., '/types/$type/edit/$id').
  19   * @param string|null $content_module Script module ID for content (stage/inspector).
  20   * @param string|null $route_module   Script module ID for route lifecycle hooks.
  21   */
  22  function wp_register_options_connectors_route( $path, $content_module = null, $route_module = null ) {
  23      global $wp_options_connectors_routes;
  24  
  25      $route = array( 'path' => $path );
  26      if ( ! empty( $content_module ) ) {
  27          $route['content_module'] = $content_module;
  28      }
  29      if ( ! empty( $route_module ) ) {
  30          $route['route_module'] = $route_module;
  31      }
  32  
  33      $wp_options_connectors_routes[] = $route;
  34  }
  35  
  36  /**
  37   * Register a menu item for the options-connectors page.
  38   *
  39   * @param string $id          Menu item ID.
  40   * @param string $label       Display label.
  41   * @param string $to          Route path to navigate to.
  42   * @param string $parent_id   Optional. Parent menu item ID.
  43   * @param string $parent_type Optional. Parent type: 'drilldown' or 'dropdown'.
  44   */
  45  function wp_register_options_connectors_menu_item( $id, $label, $to, $parent_id = '', $parent_type = '' ) {
  46      global $wp_options_connectors_menu_items;
  47  
  48      $menu_item = array(
  49          'id'    => $id,
  50          'label' => $label,
  51          'to'    => $to,
  52      );
  53  
  54      if ( ! empty( $parent_id ) ) {
  55          $menu_item['parent'] = $parent_id;
  56      }
  57  
  58      if ( ! empty( $parent_type ) && in_array( $parent_type, array( 'drilldown', 'dropdown' ), true ) ) {
  59          $menu_item['parent_type'] = $parent_type;
  60      }
  61  
  62      $wp_options_connectors_menu_items[] = $menu_item;
  63  }
  64  
  65  /**
  66   * Get all registered routes for the options-connectors page.
  67   *
  68   * @return array Array of route objects.
  69   */
  70  function wp_get_options_connectors_routes() {
  71      global $wp_options_connectors_routes;
  72      return $wp_options_connectors_routes ?? array();
  73  }
  74  
  75  /**
  76   * Get all registered menu items for the options-connectors page.
  77   *
  78   * @return array Array of menu item objects.
  79   */
  80  function wp_get_options_connectors_menu_items() {
  81      global $wp_options_connectors_menu_items;
  82      return $wp_options_connectors_menu_items ?? array();
  83  }
  84  
  85  /**
  86   * Preload REST API data for the options-connectors page.
  87   * Automatically called during page rendering.
  88   */
  89  function wp_options_connectors_preload_data() {
  90      // Define paths to preload - same for all pages
  91      // Please also change packages/core-data/src/entities.js when changing this.
  92      $preload_paths = array(
  93          '/?_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',
  94          array( '/wp/v2/settings', 'OPTIONS' ),
  95      );
  96  
  97      // Use rest_preload_api_request to gather the preloaded data
  98      $preload_data = array_reduce(
  99          $preload_paths,
 100          'rest_preload_api_request',
 101          array()
 102      );
 103  
 104      // Register the preloading middleware with wp-api-fetch
 105      wp_add_inline_script(
 106          'wp-api-fetch',
 107          sprintf(
 108              'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
 109              wp_json_encode( $preload_data )
 110          ),
 111          'after'
 112      );
 113  }
 114  
 115  /**
 116   * Render the options-connectors page.
 117   * Call this function from add_menu_page or add_submenu_page.
 118   */
 119  function wp_options_connectors_render_page() {
 120      // Load build constants
 121      $build_constants = require  __DIR__ . '/../../constants.php';
 122  
 123      // Set current screen
 124      set_current_screen();
 125  
 126      // Remove unwanted deprecated handler
 127      remove_action( 'admin_head', 'wp_admin_bar_header' );
 128  
 129      // Remove unwanted scripts and styles that were enqueued during `admin_init`
 130      foreach ( wp_scripts()->queue as $script ) {
 131          wp_dequeue_script( $script );
 132      }
 133      foreach ( wp_styles()->queue as $style ) {
 134          wp_dequeue_style( $style );
 135      }
 136  
 137      /**
 138       * Fires when the options-connectors page is initialized so extensions can register routes and menu items.
 139       */
 140      do_action( 'options-connectors_init' );
 141  
 142      // Enqueue command palette assets for boot-based pages
 143      if ( function_exists( 'wp_enqueue_command_palette_assets' ) ) {
 144          wp_enqueue_command_palette_assets();
 145      }
 146  
 147      // Preload REST API data
 148      wp_options_connectors_preload_data();
 149  
 150      // Get all registered routes and menu items
 151      $menu_items = wp_get_options_connectors_menu_items();
 152      $routes = wp_get_options_connectors_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( 'options-connectors-prerequisites', '', $asset['dependencies'], $asset['version'], true );
 163  
 164          // Add inline script to initialize the app
 165          $init_modules = [];
 166          wp_add_inline_script(
 167              'options-connectors-prerequisites',
 168              sprintf(
 169                  'import("@wordpress/boot").then(mod => mod.init({mountId: "%s", menuItems: %s, routes: %s, initModules: %s, dashboardLink: "%s"}));',
 170                  'options-connectors-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                  esc_url( admin_url( '/' ) )
 175              )
 176          );
 177  
 178          // Register prerequisites style by filtering script dependencies to find registered styles
 179          $style_dependencies = array_filter(
 180              $asset['dependencies'],
 181              function ( $handle ) {
 182                  return wp_style_is( $handle, 'registered' );
 183              }
 184          );
 185          wp_register_style( 'options-connectors-prerequisites', false, $style_dependencies, $asset['version'] );
 186  
 187          // Build dependencies for options-connectors module
 188          $boot_dependencies = array(
 189              array(
 190                  'import' => 'static',
 191                  'id'     => '@wordpress/boot',
 192              ),
 193          );
 194  
 195          // Add init modules as static dependencies
 196              // No init modules configured
 197  
 198          // Add all registered routes as dependencies
 199          foreach ( $routes as $route ) {
 200              if ( isset( $route['route_module'] ) ) {
 201                  $boot_dependencies[] = array(
 202                      'import' => 'static',
 203                      'id'     => $route['route_module'],
 204                  );
 205              }
 206              if ( isset( $route['content_module'] ) ) {
 207                  $boot_dependencies[] = array(
 208                      'import' => 'dynamic',
 209                      'id'     => $route['content_module'],
 210                  );
 211              }
 212          }
 213  
 214          /**
 215           * Filters the boot script-module dependencies for the
 216           * options-connectors page.
 217           *
 218           * Surfaces extending this page can append entries to the boot
 219           * dependency list. Each entry is an array with 'import' (string
 220           * 'static' or 'dynamic') and 'id' (script-module handle) keys.
 221           *
 222           * @param array $boot_dependencies Boot dependencies for the page.
 223           */
 224          $boot_dependencies = apply_filters(
 225              'options-connectors_boot_dependencies',
 226              $boot_dependencies
 227          );
 228  
 229          // Dummy script module to ensure dependencies are loaded
 230          wp_register_script_module(
 231              'options-connectors',
 232              $build_constants['build_url'] . 'pages/options-connectors/loader.js',
 233              $boot_dependencies
 234          );
 235  
 236          // Enqueue the boot scripts and styles
 237          wp_enqueue_script( 'options-connectors-prerequisites' );
 238          wp_enqueue_script_module( 'options-connectors' );
 239          wp_enqueue_style( 'options-connectors-prerequisites' );
 240      }
 241  
 242      // Output the HTML
 243      ?>
 244      <!DOCTYPE html>
 245      <html <?php language_attributes(); ?>>
 246      <head>
 247          <meta charset="<?php bloginfo( 'charset' ); ?>">
 248          <meta name="viewport" content="width=device-width, initial-scale=1">
 249          <title><?php echo esc_html( get_admin_page_title() ); ?></title>
 250          <style>
 251              html {
 252                  background: #f1f1f1;
 253                  color: #444;
 254                  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
 255                  font-size: 13px;
 256                  line-height: 1.4em;
 257              }
 258              body {
 259                  margin: 0;
 260              }
 261              #wpadminbar { display: none; }
 262          </style>
 263      <?php
 264      global $hook_suffix;
 265      // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
 266      $hook_suffix = 'options-connectors';
 267  
 268      // BEGIN see wp-admin/admin-header.php
 269      print_admin_styles();
 270      print_head_scripts();
 271  
 272      /** This action is documented in wp-admin/admin-header.php */
 273      do_action( "admin_head-{$hook_suffix}" ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 274  
 275      /** This action is documented in wp-admin/admin-header.php */
 276      do_action( 'admin_head' );
 277      // END see wp-admin/admin-header.php
 278      ?>
 279      </head>
 280      <body class="options-connectors">
 281          <div id="options-connectors-app" style="height: 100vh; box-sizing: border-box;"></div>
 282      <?php
 283      // BEGIN see wp-admin/admin-footer.php
 284  
 285      /** This action is documented in wp-admin/admin-footer.php */
 286      do_action( 'admin_footer', '' );
 287  
 288      // Print import map first so it's available for inline scripts
 289      wp_script_modules()->print_import_map();
 290      print_footer_scripts();
 291      wp_script_modules()->print_enqueued_script_modules();
 292      wp_script_modules()->print_script_module_preloads();
 293      wp_script_modules()->print_script_module_data();
 294  
 295      /** This action is documented in wp-admin/admin-footer.php */
 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   * Intercept admin_init to render the page early.
 307   * This bypasses the default WordPress admin template.
 308   */
 309  function wp_options_connectors_intercept_render() {
 310      // phpcs:ignore WordPress.Security.NonceVerification.Recommended
 311      if ( isset( $_GET['page'] ) && 'options-connectors' === $_GET['page'] ) {
 312          wp_options_connectors_render_page();
 313          exit;
 314      }
 315  }
 316  
 317  // Hook the interceptor to admin_init
 318  add_action( 'admin_init', 'wp_options_connectors_intercept_render' );


Generated : Fri Jul 3 08:20:12 2026 Cross-referenced by PHPXref