PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.13
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.13
1.1.13 1.1.12 1.1.11 1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 All 37 releases
← All changes | includes/core/payload.php +663 -171 1.1.3 → 1.1.13 View file →
@@ -348,8 +348,11 @@
348 348 }
349 349 $sub_entry = array(
350 350 'title' => $sub_title,
351 351 'url' => $sub_url,
352 + // The registered slug, kept for the window-tab merge
353 + // below and stripped again before the payload ships.
354 + 'slug' => (string) $row['slug'],
352 355 );
353 356 if ( $row['external'] ) {
354 357 // Consumers that route a URL into a window skip these;
355 358 // the ones that can hand a link to the browser mark
@@ -399,8 +402,47 @@
399 402 if ( $parent_is_container && $url === $parent_url ) {
400 403 continue;
401 404 }
402 405
406 + // A native window in charge of this menu owns its rows too:
407 + // whatever it offers as a tab, the dock offers as a row, same
408 + // labels and same order, each one tagged with the tab it
409 + // opens. The first tab IS the menu's own page, so it becomes
410 + // the self-label rather than a second row for the tile's own
411 + // destination. See `App::menu()`.
412 + $window_tabs = openstation_app_menu_tabs( $identity_slug );
413 + if ( $window_tabs ) {
414 + $self_label = $window_tabs[0]['label'];
415 + $claimed = array();
416 + foreach ( $window_tabs as $tab ) {
417 + if ( '' !== $tab['page'] ) {
418 + $claimed[] = $tab['page'];
419 + }
420 + }
421 + // A page this window has no tab for is still a page: a
422 + // plugin's screen registered under this menu, a taxonomy
423 + // someone added. Dropping those would make them
424 + // unreachable from the dock, so they follow the window's
425 + // own rows rather than being replaced by them.
426 + $kept = array();
427 + foreach ( $sub_items as $sub_entry ) {
428 + if ( ! in_array( $sub_entry['slug'], $claimed, true ) ) {
429 + $kept[] = $sub_entry;
430 + }
431 + }
432 + $sub_items = array();
433 + foreach ( array_slice( $window_tabs, 1 ) as $tab ) {
434 + $sub_items[] = array(
435 + 'title' => $tab['label'],
436 + 'url' => add_query_arg( 'os_tab', $tab['id'], $url ),
437 + );
438 + }
439 + $sub_items = array_merge( $sub_items, $kept );
440 + }
441 + foreach ( $sub_items as $i => $sub_entry ) {
442 + unset( $sub_items[ $i ]['slug'] );
443 + }
444 +
403 445 $dock_item = array(
404 446 'id' => sanitize_key( $item[5] ?? $item[2] ),
405 447 'title' => $title,
406 448 'icon' => $icon,
@@ -454,10 +496,12 @@
454 496 * URLs) would therefore fill the dock with tiles that can only ever
455 497 * escape to a browser tab, which breaks the shell's navigation model.
456 498 * Those entries are dropped from the payload instead.
457 499 *
458 - * Both `admin_url()` and `home_url()` hosts count as ours: a site can
459 - * run its admin on a different domain than its front end.
500 + * The menu's own admin (`openstation_menu_admin_url()`), `admin_url()`
501 + * and `home_url()` hosts all count as ours: a site can run its admin on
502 + * a different domain than its front end, and the network admin lives on
503 + * the network's own.
460 504 *
461 505 * @param string $url Absolute URL, as returned by `openstation_menu_item_url()`.
462 506 * @return bool True when the URL is off-site.
463 507 */
@@ -466,9 +510,9 @@
466 510 $external = false;
467 511
468 512 if ( $host ) {
469 513 $ours = array();
470 - foreach ( array( admin_url(), home_url() ) as $known ) {
514 + foreach ( array( openstation_menu_admin_url(), admin_url(), home_url() ) as $known ) {
471 515 $known_host = wp_parse_url( $known, PHP_URL_HOST );
472 516 if ( $known_host ) {
473 517 $ours[] = strtolower( $known_host );
474 518 }
@@ -728,12 +772,13 @@
728 772
729 773 /**
730 774 * Filters whether a dock item supports multiple open windows.
731 775 *
732 - * Return true to let the user open more than one window of this page.
733 - * A "+" affordance appears on the dock icon and a "Open another" action
734 - * becomes available in the window's title-bar menu. Singletons (false)
735 - * always focus the existing window when re-opened.
776 + * Return true to advertise this page as multi-capable: an instance
777 + * rail appears under the dock icon and an "Open another" action
778 + * becomes available in the window's title-bar menu. It does not gate
779 + * the submenu, which opens a window of its own on every pick either
780 + * way; a tile click focuses the menu's open window.
736 781 *
737 782 * @param bool $multi Whether this page is multi-capable.
738 783 * @param string $menu_slug The menu slug (e.g. `edit.php?post_type=page`).
739 784 */
@@ -817,8 +862,19 @@
817 862 'link-manager.php', // Link manager (legacy)
818 863 'update-core.php', // Dashboard > Updates
819 864 );
820 865
866 + // The two top-level network menus the site admin has no filename
867 + // for: without them, Sites and Settings sat in the apps zone while
868 + // Dashboard, Users, Themes and Plugins — whose filenames the site
869 + // admin shares — grouped correctly. Gated on the context, since
870 + // `settings.php` is plausible enough as a plugin's own top-level
871 + // slug that claiming it everywhere would misfile it.
872 + if ( is_network_admin() ) {
873 + $core_files[] = 'sites.php';
874 + $core_files[] = 'settings.php';
875 + }
876 +
821 877 return in_array( $base, $core_files, true );
822 878 }
823 879
824 880 /**
@@ -971,9 +1027,9 @@
971 1027 if ( ! is_string( $file ) || '' === $file ) {
972 1028 return null;
973 1029 }
974 1030 $plugins_dir = wp_normalize_path( WP_PLUGIN_DIR );
975 - $norm = wp_normalize_path( $file );
1031 + $norm = openstation_plugin_link_path( wp_normalize_path( $file ) );
976 1032 if ( 0 !== strpos( $norm, $plugins_dir . '/' ) ) {
977 1033 return null;
978 1034 }
979 1035 if ( ! function_exists( 'get_plugins' ) ) {
@@ -1442,8 +1498,9 @@
1442 1498 $norm = wp_normalize_path( (string) $frame['file'] );
1443 1499 if ( '' !== $self_dir && 0 === strpos( $norm, $self_dir ) ) {
1444 1500 continue;
1445 1501 }
1502 + $norm = openstation_plugin_link_path( $norm );
1446 1503 foreach ( $dirs as $dir ) {
1447 1504 if ( 0 === strpos( $norm, $dir ) ) {
1448 1505 return $norm;
1449 1506 }
@@ -1451,8 +1508,36 @@
1451 1508 }
1452 1509 return null;
1453 1510 }
1454 1511
1512 +/**
1513 + * Map a path PHP reported back to the plugin folder WordPress loaded
1514 + * it through.
1515 + *
1516 + * PHP resolves symlinks in file names, so a plugin folder linked into
1517 + * `plugins/` from elsewhere shows up in backtraces and reflection outside
1518 + * `WP_PLUGIN_DIR`. WordPress.com's managed plugins are linked that way:
1519 + * `plugins/woocommerce` resolves to `/wordpress/plugins/woocommerce/<version>/`.
1520 + * Core records each active plugin's link and target in
1521 + * `$wp_plugin_paths` before loading it, and `plugin_basename()` maps
1522 + * through the same list.
1523 + *
1524 + * @param string $path Normalized absolute path.
1525 + * @return string The same file under the plugin's link, or `$path`
1526 + * when no active plugin is linked from there.
1527 + */
1528 +function openstation_plugin_link_path( $path ) {
1529 + global $wp_plugin_paths;
1530 +
1531 + foreach ( (array) $wp_plugin_paths as $link => $target ) {
1532 + $target = trailingslashit( (string) $target );
1533 + if ( 0 === strpos( $path, $target ) ) {
1534 + return trailingslashit( (string) $link ) . substr( $path, strlen( $target ) );
1535 + }
1536 + }
1537 + return $path;
1538 +}
1539 +
1455 1540 add_action(
1456 1541 'registered_post_type',
1457 1542 static function ( $post_type ) {
1458 1543 openstation_record_type_registrant( $post_type, 'post_type' );
@@ -1583,11 +1668,16 @@
1583 1668 }
1584 1669
1585 1670 $dock = array_merge( $core, $plugin );
1586 1671
1672 + // One collector call feeds both halves: the slim entry list and
1673 + // the handle-keyed script data the shell joins them with.
1674 + $native_windows = openstation_collect_native_windows_payload();
1675 +
1587 1676 $payload = array(
1588 - 'dockItems' => $dock,
1589 - 'nativeWindows' => openstation_build_native_windows_payload(),
1677 + 'dockItems' => $dock,
1678 + 'nativeWindows' => $native_windows['windows'],
1679 + 'nativeWindowScriptData' => $native_windows['scriptData'],
1590 1680 );
1591 1681
1592 1682 // Optional per-surface payload builders — each module ships a
1593 1683 // zero-arg `openstation_build_*_payload()`; modules that aren't
@@ -1645,8 +1735,15 @@
1645 1735 'url' => network_admin_url( 'update-core.php' ),
1646 1736 );
1647 1737 }
1648 1738
1739 + // The site switcher's rows: on a network, the instances this shell
1740 + // may switch to (`openstation_multisite_payload()`), null elsewhere.
1741 + // The Network app spends a menu refresh after every action that
1742 + // changes them (add, remove, join, leave, sync), so the row above
1743 + // overview's desktop tiles follows the registry without a reload.
1744 + $payload['multisite'] = openstation_multisite_payload();
1745 +
1649 1746 // A cheap structural fingerprint of the admin menu the shell uses to
1650 1747 // decide whether a live refresh is warranted. Shipped in every full
1651 1748 // payload so the shell can seed / update its last-known signature
1652 1749 // without recomputing it client-side (which would risk drift from
@@ -1653,8 +1750,13 @@
1653 1750 // the server's capability-gated view). See
1654 1751 // openstation_menu_signature().
1655 1752 $payload['menuSig'] = openstation_menu_signature();
1656 1753
1754 + // Each script dependency's payload once, entries carry handles.
1755 + $script_dep_payloads = array();
1756 + $payload = openstation_compact_script_deps( $payload, $script_dep_payloads );
1757 + $payload['scriptDepPayloads'] = (object) $script_dep_payloads;
1758 +
1657 1759 return $payload;
1658 1760 }
1659 1761
1660 1762 /**
@@ -1729,8 +1831,247 @@
1729 1831 return md5( implode( "\n", $parts ) );
1730 1832 }
1731 1833
1732 1834 /**
1835 + * A handle's dependency closure, in load order.
1836 + *
1837 + * Post-order depth-first: a handle is emitted only after everything it
1838 + * declares, which is the order `WP_Scripts::do_item()` would have
1839 + * printed them in. A handle is marked visited *before* its own
1840 + * dependencies are walked, so a dependency cycle unwinds instead of
1841 + * recursing forever, and an unregistered handle is skipped rather than
1842 + * being fatal — it contributes nothing and stops nothing.
1843 + *
1844 + * **Deliberately not `WP_Dependencies::all_deps()`.** Three reasons,
1845 + * each of which has bitten this codebase:
1846 + *
1847 + * 1. `WP_Scripts::all_deps()` applies `print_scripts_array` to its
1848 + * result whenever `$recursion` is falsy. That filter is where the
1849 + * chromeless palette trim and the asset guard live, so resolving a
1850 + * payload through it would run a print-time trim across a dependency
1851 + * list and let the guard splice this plugin's own bundles into it.
1852 + * Called from inside one of those filters it is an infinite loop.
1853 + *
1854 + * 2. Passing `$recursion = true` silences that filter but changes the
1855 + * contract: the first handle that fails aborts the entire call
1856 + * (`return false`), abandoning every handle after it in the list. The
1857 + * caller is left with a `$to_do` that is a truncated prefix of the real
1858 + * closure and indistinguishable from a complete one — a silent, partial
1859 + * answer conditional on unrelated registrations elsewhere on the page.
1860 + * A lazily-delivered bundle resolved that way loses packages it
1861 + * declared and throws on an undefined global at mount, which is the
1862 + * exact bug this whole mechanism exists to prevent.
1863 + *
1864 + * 3. `all_deps()` reports missing dependencies through
1865 + * `_doing_it_wrong()`. This is read-only analysis; the real print pass
1866 + * raises those anyway, and raising them twice turns someone else's
1867 + * pre-existing warning into our noise.
1868 + *
1869 + * O(V+E) over the graph, allocates one set, and clones nothing.
1870 + *
1871 + * @param WP_Dependencies $dependencies The scripts or styles registry.
1872 + * @param string[] $handles Roots to walk.
1873 + * @return string[] Registered handles, dependencies before dependents.
1874 + */
1875 +function openstation_script_dependency_closure( $dependencies, $handles ) {
1876 + $seen = array();
1877 + $out = array();
1878 + openstation_collect_script_dependency_closure( $dependencies, (array) $handles, $seen, $out );
1879 +
1880 + return $out;
1881 +}
1882 +
1883 +/**
1884 + * Recursive half of {@see openstation_script_dependency_closure()}.
1885 + *
1886 + * @param WP_Dependencies $dependencies The scripts or styles registry.
1887 + * @param string[] $handles Handles to walk.
1888 + * @param array $seen Handle => true, by reference.
1889 + * @param string[] $out Ordered result, by reference.
1890 + */
1891 +function openstation_collect_script_dependency_closure( $dependencies, $handles, &$seen, &$out ) {
1892 + foreach ( (array) $handles as $handle ) {
1893 + if ( isset( $seen[ $handle ] ) ) {
1894 + continue;
1895 + }
1896 + // Marked BEFORE recursing, so a cycle meets itself as visited
1897 + // and unwinds rather than recursing forever.
1898 + $seen[ $handle ] = true;
1899 + if ( ! isset( $dependencies->registered[ $handle ] ) ) {
1900 + continue;
1901 + }
1902 + openstation_collect_script_dependency_closure(
1903 + $dependencies,
1904 + $dependencies->registered[ $handle ]->deps,
1905 + $seen,
1906 + $out
1907 + );
1908 + $out[] = $handle;
1909 + }
1910 +}
1911 +
1912 +/**
1913 + * Resolve a handle's dependency closure, in load order.
1914 + *
1915 + * **Why a lazily-delivered handle needs this at all.** WordPress
1916 + * normally resolves a script's dependencies when it enqueues it — the
1917 + * packages a bundle declares are on the page before its own body runs.
1918 + * A handle that is only ever delivered lazily never goes through that:
1919 + * `loadVendorScript()` injects one URL, and a bundle declaring
1920 + * `wp-api-fetch` found `wp.apiFetch` undefined at mount.
1921 + *
1922 + * That used to work by accident. Core's ⌘K palette was enqueued on
1923 + * every admin page and its closure is the whole Gutenberg runtime, so
1924 + * `wp.apiFetch`, `wp.element` and friends happened to be globals.
1925 + * Deferring the palette took the accident away and left the contract
1926 + * exposed — see `docs/migration-wp-package-globals.md`.
1927 + *
1928 + * The closure comes from {@see openstation_script_dependency_closure()}
1929 + * rather than `WP_Dependencies::all_deps()`; that function's docblock
1930 + * records why, and the short version is that `all_deps()` answers a
1931 + * question like this one with a silently truncated list. The handle
1932 + * itself is excluded — the caller loads it separately, after these.
1933 + *
1934 + * @param string $handle Script handle.
1935 + * @return array<int,array<string,mixed>> Ordered dependency payloads.
1936 + */
1937 +function openstation_resolve_script_dependencies( $handle ) {
1938 + $handle = (string) $handle;
1939 + $wp_scripts = wp_scripts();
1940 + if ( '' === $handle || ! $wp_scripts || ! isset( $wp_scripts->registered[ $handle ] ) ) {
1941 + return array();
1942 + }
1943 + $deps = $wp_scripts->registered[ $handle ]->deps;
1944 + if ( empty( $deps ) ) {
1945 + return array();
1946 + }
1947 +
1948 + $out = array();
1949 + foreach ( openstation_script_dependency_closure( $wp_scripts, $deps ) as $dep_handle ) {
1950 + if ( $dep_handle === $handle ) {
1951 + continue;
1952 + }
1953 + $payload = openstation_resolve_script_payload( $dep_handle );
1954 + // An alias (no `src`) stays in the list when it carries inline
1955 + // data — that data is the whole reason it was declared, and a
1956 + // plugin's config blob commonly rides one. Nothing to fetch
1957 + // AND nothing to run is the only thing dropped.
1958 + if ( '' === $payload['url']
1959 + && empty( $payload['before'] )
1960 + && empty( $payload['after'] )
1961 + && empty( $payload['l10n'] ) ) {
1962 + continue;
1963 + }
1964 + // The handle rides along because the shell needs it to decide
1965 + // whether the page already has this package. A URL is not
1966 + // enough: with Core's script concatenation on — the wp-admin
1967 + // default — every package below `wp-includes/js/` is served
1968 + // from one `load-scripts.php` blob and has no `<script src>`
1969 + // of its own to match against. Re-running `wp-hooks` because
1970 + // we could not see it replaces `window.wp.hooks`, and every
1971 + // subscriber registered at boot goes deaf. See
1972 + // `src/script-presence.ts`.
1973 + $payload['handle'] = (string) $dep_handle;
1974 + $out[] = $payload;
1975 + }
1976 + return $out;
1977 +}
1978 +
1979 +/**
1980 + * Move every entry's `scriptDeps` payloads into one map.
1981 + *
1982 + * {@see openstation_resolve_script_dependencies()} returns the full
1983 + * payload of each dependency (URL, l10n, before/after), and ~20 entry
1984 + * builders call it. A dependency shared by N entries was therefore
1985 + * serialized N times: one plugin's 5.5 KB localized object became
1986 + * ~400 KB of a 489 KB `openStationConfig` (GH#892). This replaces each
1987 + * entry's `scriptDeps` list with its handles and puts each handle's
1988 + * payload in `$map` once. The shell resolves the handles back before
1989 + * any consumer reads them; see `src/script-dep-payloads.ts`.
1990 + *
1991 + * ENTRY DEPTH ONLY. `$payload` is a payload whose top-level values are
1992 + * entry lists (`serverWidgets`, `serverCommandScripts`, ...), and only
1993 + * a `scriptDeps` sitting directly on one of those entries is touched.
1994 + * The key is the shell's there. Deeper down it is a plugin's metadata
1995 + * (`settings => [ 'scriptDeps' => ... ]`), and rewriting it would hoist
1996 + * foreign data into the map first-wins and hydrate every real
1997 + * dependency of that handle to it. Scoping by depth rather than by a
1998 + * list of keys means a new builder is covered without an edit here.
1999 + * It also leaves every other branch of the payload unassigned, so
2000 + * PHP's copy-on-write never has to copy them.
2001 + *
2002 + * Every string left in a compacted list has an entry in `$map`: a bare
2003 + * handle a builder (or a filter on one) emitted is resolved here, by
2004 + * the same rule as {@see openstation_resolve_script_dependencies()}.
2005 + * A handle with nothing to fetch and nothing to run is dropped, as it
2006 + * is there. The client can then treat a string with no map entry as a
2007 + * payload from somewhere else, not a dependency this side dropped.
2008 + *
2009 + * Runs on the finished payload, so every builder, and every filter on
2010 + * a builder's output, still sees the full shape.
2011 + *
2012 + * @param array $payload Payload whose top-level values are entry lists.
2013 + * @param array $map Handle => dependency payload, filled in place.
2014 + * @return array The payload with each entry's `scriptDeps` reduced to handles.
2015 + */
2016 +function openstation_compact_script_deps( $payload, array &$map ) {
2017 + if ( ! is_array( $payload ) ) {
2018 + return $payload;
2019 + }
2020 + foreach ( $payload as $list_key => $entries ) {
2021 + if ( ! is_array( $entries ) ) {
2022 + continue;
2023 + }
2024 + foreach ( $entries as $entry_key => $entry ) {
2025 + if ( ! is_array( $entry ) || ! isset( $entry['scriptDeps'] ) || ! is_array( $entry['scriptDeps'] ) ) {
2026 + continue;
2027 + }
2028 + $payload[ $list_key ][ $entry_key ]['scriptDeps'] = openstation_compact_script_dep_list( $entry['scriptDeps'], $map );
2029 + }
2030 + }
2031 + return $payload;
2032 +}
2033 +
2034 +/**
2035 + * One entry's `scriptDeps` list, reduced to handles.
2036 + *
2037 + * @param array $deps Dependency payloads and/or bare handles.
2038 + * @param array $map Handle => dependency payload, filled in place.
2039 + * @return array Handles, in order; anything unkeyable passes through.
2040 + */
2041 +function openstation_compact_script_dep_list( array $deps, array &$map ) {
2042 + $handles = array();
2043 + foreach ( $deps as $dep ) {
2044 + if ( is_string( $dep ) && '' !== $dep ) {
2045 + if ( ! isset( $map[ $dep ] ) ) {
2046 + $payload = openstation_resolve_script_payload( $dep );
2047 + if ( '' === $payload['url']
2048 + && empty( $payload['before'] )
2049 + && empty( $payload['after'] )
2050 + && empty( $payload['l10n'] ) ) {
2051 + continue;
2052 + }
2053 + $payload['handle'] = $dep;
2054 + $map[ $dep ] = $payload;
2055 + }
2056 + $handles[] = $dep;
2057 + continue;
2058 + }
2059 + if ( is_array( $dep ) && isset( $dep['handle'] ) && '' !== (string) $dep['handle'] ) {
2060 + $handle = (string) $dep['handle'];
2061 + if ( ! isset( $map[ $handle ] ) ) {
2062 + $map[ $handle ] = $dep;
2063 + }
2064 + $handles[] = $handle;
2065 + continue;
2066 + }
2067 + // A handle-less payload has nothing to key it by.
2068 + $handles[] = $dep;
2069 + }
2070 + return $handles;
2071 +}
2072 +
2073 +/**
1733 2074 * Resolve a registered WP script handle into the full payload the
1734 2075 * shell needs to lazy-load it without going through `wp_print_scripts()`.
1735 2076 *
1736 2077 * Returns:
@@ -1754,10 +2095,14 @@
1754 2095 * around the lazy `<script src>` in the same order
1755 2096 * `WP_Scripts::do_item()` would have used.
1756 2097 *
1757 2098 * Returns an empty payload (`array( 'url' => '' )`) when the handle
1758 - * is unregistered or has no source — callers treat that as "no
1759 - * script to load."
2099 + * is unregistered. A registered handle with no source — an alias
2100 + * carrying only inline data — also comes back with an empty `url`,
2101 + * but its `before` / `after` / `l10n` are kept: callers that load a
2102 + * bundle treat an empty `url` as "nothing to fetch", and the
2103 + * dependency walk ({@see openstation_resolve_script_dependencies()})
2104 + * still replays what the alias would have printed.
1760 2105 *
1761 2106 * Shared between `openstation_register_window()` and
1762 2107 * `openstation_register_widget()` (and every other registration that
1763 2108 * relies on lazy script loading in the shell) because all of them
@@ -1785,20 +2130,31 @@
1785 2130 return $empty;
1786 2131 }
1787 2132 $registered = $wp_scripts->registered[ $handle ];
1788 2133 $src = is_string( $registered->src ) ? $registered->src : '';
1789 - if ( '' === $src ) {
1790 - return $empty;
1791 - }
1792 2134
1793 - // Normalize relative paths + attach cache-bust ver.
1794 - $resolved = $src;
1795 - if ( 0 === strpos( $resolved, '/' ) && 0 !== strpos( $resolved, '//' ) ) {
1796 - $resolved = site_url( $resolved );
2135 + // A handle with no `src` is an ALIAS — WordPress's supported way
2136 + // to ship inline-only JavaScript (`wp_register_script( $h, false )`
2137 + // plus `wp_add_inline_script()`), and a common home for a plugin's
2138 + // config blob: registering it as a *dependency* of every bundle is
2139 + // what guarantees the config runs first, whatever the enqueue
2140 + // order. `WP_Scripts::do_item()` prints an alias's localized data
2141 + // and its before/after snippets and returns before the `<script
2142 + // src>` it does not have. The payload mirrors that: `url` stays
2143 + // empty (there is nothing to fetch) and the inline data is kept,
2144 + // so a dependency walk can replay it. Translations are not: Core
2145 + // only prints those for a handle it printed a tag for.
2146 + $resolved = '';
2147 + if ( '' !== $src ) {
2148 + // Normalize relative paths + attach cache-bust ver.
2149 + $resolved = $src;
2150 + if ( 0 === strpos( $resolved, '/' ) && 0 !== strpos( $resolved, '//' ) ) {
2151 + $resolved = site_url( $resolved );
2152 + }
2153 + if ( ! empty( $registered->ver ) ) {
2154 + $resolved = add_query_arg( 'ver', $registered->ver, $resolved );
2155 + }
1797 2156 }
1798 - if ( ! empty( $registered->ver ) ) {
1799 - $resolved = add_query_arg( 'ver', $registered->ver, $resolved );
1800 - }
1801 2157
1802 2158 // Harvest `extra` data the lazy-load path would otherwise drop.
1803 2159 $before = array();
1804 2160 $after = array();
@@ -1833,9 +2189,9 @@
1833 2189 // `wp.i18n.setLocaleData( JSON, 'domain' )` snippet that the print
1834 2190 // pipeline emits before the script body. `print_translations(
1835 2191 // $handle, false )` returns the snippet without echoing.
1836 2192 $translations = '';
1837 - if ( method_exists( $wp_scripts, 'print_translations' ) ) {
2193 + if ( '' !== $resolved && method_exists( $wp_scripts, 'print_translations' ) ) {
1838 2194 $captured = $wp_scripts->print_translations( $handle, false );
1839 2195 if ( is_string( $captured ) ) {
1840 2196 $translations = $captured;
1841 2197 }
@@ -1946,12 +2302,15 @@
1946 2302 * time the palette is invoked (`src/commands/palette-assets.ts`).
1947 2303 *
1948 2304 * Handles with no `src` (pure aggregators) are kept whenever they
1949 2305 * carry inline data; dropping them would lose middleware and locale
1950 - * setup the chain depends on. Handles another plugin already
1951 - * enqueued at boot print normally and are skipped client-side by a
1952 - * same-path DOM sniff — the manifest deliberately lists them anyway,
1953 - * because which ones those are differs per site and per screen.
2306 + * setup the chain depends on. Handles the boot page already printed
2307 + * are skipped client-side, by handle as well as by path so that a
2308 + * package Core concatenated into `load-scripts.php` is recognized
2309 + * (`src/script-presence.ts`) — the manifest deliberately lists them
2310 + * anyway, because which ones those are differs per site and per
2311 + * screen. Each entry therefore carries its `handle`, and that is
2312 + * load-bearing rather than informational.
1954 2313 *
1955 2314 * Returns `null` on pre-6.9 sites (no Core palette to defer).
1956 2315 *
1957 2316 * @return array{scripts:array<int,array<string,mixed>>,styles:array<int,array<string,mixed>>}|null
@@ -2006,25 +2365,45 @@
2006 2365 $script_probe->done = array();
2007 2366 $script_probe->all_deps( $script_roots );
2008 2367 foreach ( $script_probe->to_do as $handle ) {
2009 2368 $payload = openstation_resolve_script_payload( $handle );
2010 - if ( '' === $payload['url'] ) {
2011 - // Src-less aggregator — keep it only for its inline data.
2012 - $registered = isset( $scripts->registered[ $handle ] ) ? $scripts->registered[ $handle ] : null;
2013 - if ( $registered ) {
2014 - foreach ( array( 'before', 'after' ) as $position ) {
2015 - if ( isset( $registered->extra[ $position ] ) && is_array( $registered->extra[ $position ] ) ) {
2016 - $payload[ $position ] = array_values( array_filter( array_map( 'strval', $registered->extra[ $position ] ) ) );
2017 - }
2018 - }
2019 - if ( ! empty( $registered->extra['data'] ) && is_string( $registered->extra['data'] ) ) {
2020 - $payload['l10n'][] = $registered->extra['data'];
2021 - }
2369 + // A src-less aggregator is kept only for its inline data — the
2370 + // resolver harvests that for an alias — and dropped when it
2371 + // carries none.
2372 + if ( '' === $payload['url']
2373 + && empty( $payload['before'] )
2374 + && empty( $payload['after'] )
2375 + && empty( $payload['l10n'] ) ) {
2376 + continue;
2377 + }
2378 + // Core's `initializeCommandPalette( {…} )` inline embeds the
2379 + // serialized admin-menu command list — ~20 KB that the boot
2380 + // page ALREADY carries as `window.__openStationMenuCommands`
2381 + // (the shell harvester's lookup, attached as a `before`
2382 + // inline on the main bundle, and the richer of the two: its
2383 + // URL derivation routes legacy file-path slugs through
2384 + // `menu_page_url()` where Core's regex takes them literally).
2385 + // Ship the list once: strip Core's embedded copy and
2386 + // synthesize the same call against the global, which is
2387 + // guaranteed present long before the manifest replays — it
2388 + // prints at boot, the replay waits for the first ⌘K.
2389 + if ( 'wp-core-commands' === $handle ) {
2390 + foreach ( array( 'before', 'after' ) as $position ) {
2391 + $payload[ $position ] = array_values(
2392 + array_filter(
2393 + $payload[ $position ],
2394 + static function ( $snippet ) {
2395 + return false === strpos( (string) $snippet, 'initializeCommandPalette(' );
2396 + }
2397 + )
2398 + );
2022 2399 }
2023 - if ( empty( $payload['before'] ) && empty( $payload['after'] ) && empty( $payload['l10n'] ) ) {
2024 - continue;
2025 - }
2400 + $payload['after'][] = sprintf(
2401 + 'wp.coreCommands.initializeCommandPalette({"is_network_admin":%s,"menu_commands":window.__openStationMenuCommands||[]});',
2402 + is_network_admin() ? 'true' : 'false'
2403 + );
2026 2404 }
2405 +
2027 2406 $out['scripts'][] = array(
2028 2407 'handle' => (string) $handle,
2029 2408 'url' => $payload['url'],
2030 2409 'before' => $payload['before'],
@@ -2113,9 +2492,9 @@
2113 2492 _doing_it_wrong(
2114 2493 esc_html( $function_name ),
2115 2494 sprintf(
2116 2495 /* translators: 1: kind ("Command"/"Settings-tab"/"Title-bar button"), 2: handle. */
2117 - esc_html__( '%1$s script handle "%2$s" is not registered with WordPress (no `wp_register_script` call found). The script will not load.', 'desktop-mode' ),
2496 + esc_html__( '%1$s script handle "%2$s" could not be resolved: no `wp_register_script( \'%2$s\', … )` call had run by the time the shell harvested its payload. Register the handle on `admin_enqueue_scripts` at priority 5 or earlier — the harvest itself runs at priority 10, and a handle registered alongside it may or may not exist yet depending on plugin load order. Until then the script will not load.', 'desktop-mode' ),
2118 2497 esc_html( $kind ),
2119 2498 esc_html( $handle )
2120 2499 ),
2121 2500 '0.8.1'
@@ -2157,40 +2536,136 @@
2157 2536 openstation_warn_unresolvable_script_handle( '', '', '__flush__' );
2158 2537 }
2159 2538
2160 2539 /**
2161 - * Serialize the server-declared native-window registry into the
2162 - * payload shape the shell consumes. For each entry registered via
2163 - * `openstation_register_window()`, we capture: the window's
2164 - * metadata (id/title/icon/placement/dimensions/autofocus), the
2165 - * rendered template HTML (by running the template callback into an
2166 - * output buffer), and the URL of the enqueued script handle (so
2167 - * mid-session activations can load the plugin's JS dynamically
2168 - * without a full shell reload).
2540 + * Collect the native-window payload: slim per-window entries plus a
2541 + * handle-keyed script-data map.
2169 2542 *
2170 - * @return array[]
2543 + * For each entry registered via `openstation_register_window()` the
2544 + * `windows` list captures the window's metadata
2545 + * (id/title/icon/placement/dimensions/autofocus), the rendered
2546 + * template HTML, and the HANDLE NAMES of its script, companions and
2547 + * tab scripts. The resolved data those handles stand for — URL plus
2548 + * harvested `wp_localize_script` / `wp_add_inline_script` /
2549 + * translations, see `openstation_resolve_script_payload()` — lives
2550 + * ONCE per handle in `scriptData`, and the shell joins the two on
2551 + * receipt (`hydrateServerEntries()` in `src/native-windows.ts`).
2552 + * Each loadable handle's entry also names its dependency closure in
2553 + * `deps` (ordered handles, every one of them a key of the same map)
2554 + * so the lazy loader can bring a bundle's declared packages — and
2555 + * a src-less alias carrying its config — into the tab before it.
2556 + *
2557 + * The split exists because script data is a property of the HANDLE,
2558 + * not of the window: every App Framework window rides
2559 + * `openstation-app-runtime`, and inlining each entry's resolved copy
2560 + * serialized the same localize blobs and the same shared config set
2561 + * four times over — `scriptL10n` alone was ~100 KB of the boot
2562 + * payload, most of it repetition. The synthesized
2563 + * `openStationWindowConfig[ id ]` assignments group by handle for
2564 + * the same reason they used to ride every sharing entry: the shell
2565 + * fetches a URL once, and a bundle can serve one window from inside
2566 + * another (the Users window mounts the Profile form, which reads the
2567 + * user-edit config), so whichever entry loads the bundle must
2568 + * deliver the whole handle's config set.
2569 + *
2570 + * Style data stays inline on the entries — it never had a
2571 + * duplication problem worth a second map ( companion styles across
2572 + * the whole registry total ~2 KB ).
2573 + *
2574 + * @return array{windows:array[],scriptData:array<string,array{url:string,before:string[],after:string[],l10n:string[],translations:string,deps:string[]}>}
2171 2575 */
2172 -function openstation_build_native_windows_payload() {
2576 +function openstation_collect_native_windows_payload() {
2577 + $empty = array(
2578 + 'windows' => array(),
2579 + 'scriptData' => array(),
2580 + );
2173 2581 if ( ! function_exists( 'openstation_native_window_registry' ) ) {
2174 - return array();
2582 + return $empty;
2175 2583 }
2584 +
2176 2585 $registry = openstation_native_window_registry();
2177 2586 if ( ! is_array( $registry ) ) {
2178 - return array();
2587 + return $empty;
2179 2588 }
2180 2589
2590 + // A window says which admin offers it (`admin` in its registration:
2591 + // `site`, `network` or `any`). Every native window OpenStation
2592 + // ships is site-scoped, reading the current site's REST API, so in
2593 + // the network admin a `users.php` tile meaning "everyone on the
2594 + // network" would open one site's user list; those stay off the
2595 + // network shell. A window that declares `network` (the Network app)
2596 + // is offered there and nowhere else.
2597 + //
2598 + // Dropping the site windows there is also what disarms the
2599 + // client-side URL remaps: they match on the tail of a pathname
2600 + // (`endsWith( '/users.php' )`) and the network admin serves
2601 + // same-named files one directory down, but with nothing registered
2602 + // `openById()` finds no window and the remap falls through to the
2603 + // iframe.
2604 + $registry = array_filter( $registry, 'openstation_native_window_offered_here' );
2605 +
2606 + $script_data = array();
2607 +
2608 + // Handles resolved as a bundle to LOAD (a window's script, a
2609 + // companion, a tab) and what that visit answered — the handle, or
2610 + // '' for nothing to load — as opposed to reached only as
2611 + // somebody's dependency. A handle can be both — resolved as a
2612 + // dependency first, then named as a window's own script — and
2613 + // only the bundle visit computes its own closure.
2614 + $resolved_as_bundle = array();
2615 +
2616 + // Resolve a handle into the map, once. Returns the handle when it
2617 + // resolved to something loadable, '' when it did not (never
2618 + // registered, no src) — the same silent drop the inline shape
2619 + // applied to companions and tab scripts.
2620 + //
2621 + // The handle's dependency closure rides along as `deps`: an
2622 + // ordered handle list, each of which lands in the same map. A
2623 + // bundle delivered lazily never goes through WordPress's own
2624 + // dependency resolution — the loader injects one URL — so a
2625 + // window declaring `wp-api-fetch` found `wp.apiFetch` undefined,
2626 + // and one whose config rides a src-less alias handle (a common
2627 + // shape: `wp_register_script( $h, false )` plus
2628 + // `wp_add_inline_script()`, declared as the bundle's dependency
2629 + // so it always runs first) booted with no config at all. Anything
2630 + // the document already ran is skipped on the client, so a page
2631 + // that carried the packages anyway pays nothing.
2632 + $collect_handle = static function ( $handle ) use ( &$script_data, &$resolved_as_bundle ) {
2633 + $handle = (string) $handle;
2634 + if ( '' === $handle ) {
2635 + return '';
2636 + }
2637 + if ( isset( $resolved_as_bundle[ $handle ] ) ) {
2638 + return $resolved_as_bundle[ $handle ];
2639 + }
2640 + $payload = isset( $script_data[ $handle ] )
2641 + ? $script_data[ $handle ]
2642 + : openstation_resolve_script_payload( $handle );
2643 + if ( '' === $payload['url'] ) {
2644 + $resolved_as_bundle[ $handle ] = '';
2645 + return '';
2646 + }
2647 + $resolved_as_bundle[ $handle ] = $handle;
2648 + $deps = array();
2649 + foreach ( openstation_resolve_script_dependencies( $handle ) as $dep ) {
2650 + $dep_handle = (string) $dep['handle'];
2651 + unset( $dep['handle'] );
2652 + if ( ! isset( $script_data[ $dep_handle ] ) ) {
2653 + $dep['deps'] = array();
2654 + $script_data[ $dep_handle ] = $dep;
2655 + }
2656 + $deps[] = $dep_handle;
2657 + }
2658 + $payload['deps'] = $deps;
2659 + $script_data[ $handle ] = $payload;
2660 + return $handle;
2661 + };
2662 +
2181 2663 // Synthesized `openStationWindowConfig[ id ]` assignments, grouped
2182 - // by SCRIPT HANDLE rather than kept per window. Several windows
2183 - // share one bundle (Posts / Pages / Users / Profile all ride
2184 - // `os-posts-window`), and the shell fetches a URL once — so a
2185 - // config that only travels with its own window's entry is dropped
2186 - // for every sibling after the first, and a bundle whose code
2187 - // serves one window from inside another (the Users window mounts
2188 - // the Profile form, which reads the user-edit config) never sees
2189 - // it at all. Shipping the whole handle's config set on every entry
2190 - // that names the handle means whichever entry loads the bundle
2191 - // delivers all of them; the assignments are keyed by id, so
2192 - // replaying a sibling's copy is idempotent.
2664 + // by script handle (see the function docblock). Collected first so
2665 + // they can be appended to each handle's map entry exactly once,
2666 + // after its own harvested data — the same order the print pipeline
2667 + // would have used.
2193 2668 $config_snippets_by_handle = array();
2194 2669 foreach ( $registry as $entry ) {
2195 2670 $handle = isset( $entry['script'] ) ? (string) $entry['script'] : '';
2196 2671 if ( '' === $handle || ! is_callable( $entry['template'] ) ) {
@@ -2220,40 +2695,34 @@
2220 2695 // `<template>` at mid-session plugin activation without a
2221 2696 // reload.
2222 2697 $template_html = openstation_build_native_window_template_html( $entry );
2223 2698
2224 - // Resolve script handle → full payload (URL + harvested
2225 - // `extra` data) so the shell can inject a `<script>` tag
2226 - // dynamically on mid-session activation WITHOUT dropping
2227 - // `wp_localize_script` / `wp_add_inline_script` data the way
2228 - // the bare `<script src>` lazy-load path would. See
2229 - // `openstation_resolve_script_payload()` for shape.
2230 - $script_handle = isset( $entry['script'] ) ? (string) $entry['script'] : '';
2231 - $script_payload = openstation_resolve_script_payload( $script_handle );
2699 + // `$collect_handle()` answers "is there a bundle to fetch?", and
2700 + // returns '' when the handle resolves to no URL — a src-less
2701 + // alias handle registered only to carry `preload_script` or
2702 + // inline data, for instance. That is the right answer for
2703 + // `scriptHandle`, which names something to load. It is the
2704 + // wrong answer for `ownerHandle`, which names WHO the window
2705 + // belongs to: attribution does not depend on whether the owner
2706 + // happens to ship a file. Shipping '' there broke the
2707 + // documented "always populated" contract and blanked
2708 + // `wp.os.debug.window()`.
2709 + $declared_script = isset( $entry['script'] ) ? (string) $entry['script'] : '';
2710 + $script_handle = $collect_handle( $declared_script );
2711 + $owner_handle = '' !== $script_handle ? $script_handle : $declared_script;
2232 2712
2233 2713 // Companion handles (`scripts` arg) — bundles that extend the
2234 2714 // window from outside it and must be in the tab before its
2235 - // render callback paints. Same resolved shape as the main
2236 - // script, kept as a list so the shell loads them in the
2237 - // declared order ahead of it. Handles that resolve to nothing
2238 - // (never registered) are dropped rather than shipped as an
2239 - // entry the loader would skip anyway.
2715 + // render callback paints. Kept as an ordered handle list; the
2716 + // shell loads them in declared order ahead of the window's
2717 + // own script, resolving each through `scriptData`.
2240 2718 $companion_scripts = array();
2241 2719 if ( ! empty( $entry['scripts'] ) && is_array( $entry['scripts'] ) ) {
2242 2720 foreach ( $entry['scripts'] as $companion_handle ) {
2243 - $companion_handle = (string) $companion_handle;
2244 - $companion_payload = openstation_resolve_script_payload( $companion_handle );
2245 - if ( '' === $companion_payload['url'] ) {
2246 - continue;
2721 + $companion_handle = $collect_handle( $companion_handle );
2722 + if ( '' !== $companion_handle ) {
2723 + $companion_scripts[] = $companion_handle;
2247 2724 }
2248 - $companion_scripts[] = array(
2249 - 'scriptUrl' => $companion_payload['url'],
2250 - 'scriptHandle' => $companion_handle,
2251 - 'scriptBefore' => $companion_payload['before'],
2252 - 'scriptAfter' => $companion_payload['after'],
2253 - 'scriptL10n' => $companion_payload['l10n'],
2254 - 'scriptTranslations' => $companion_payload['translations'],
2255 - );
2256 2725 }
2257 2726 }
2258 2727
2259 2728 // Resolve the optional style handle alongside the script so the
@@ -2287,109 +2756,100 @@
2287 2756 );
2288 2757 }
2289 2758 }
2290 2759
2291 - // `config` arg on `openstation_register_window()` — discoverable
2292 - // alternative to `wp_localize_script`. We synthesize a localize
2293 - // snippet so it lands through the same delivery path as native
2294 - // `wp_localize_script`. The bundle reads
2295 - // `window.openStationWindowConfig[id]` (or via
2296 - // `wp.os.getWindowConfig(id)`).
2297 - //
2298 - // The whole HANDLE's config set rides along, own window first —
2299 - // see `$config_snippets_by_handle` above for why a shared
2300 - // bundle must carry its siblings' configs too.
2301 - if ( '' !== $script_handle && isset( $config_snippets_by_handle[ $script_handle ] ) ) {
2302 - $handle_snippets = $config_snippets_by_handle[ $script_handle ];
2303 - if ( isset( $handle_snippets[ $entry['id'] ] ) ) {
2304 - $script_payload['l10n'][] = $handle_snippets[ $entry['id'] ];
2305 - unset( $handle_snippets[ $entry['id'] ] );
2306 - }
2307 - foreach ( $handle_snippets as $sibling_snippet ) {
2308 - $script_payload['l10n'][] = $sibling_snippet;
2309 - }
2310 - } elseif ( '' === $script_handle ) {
2311 - // A window with no bundle keeps the old shape: its config
2312 - // snippet is synthesized onto the (never-delivered) script
2313 - // payload, preserving behavior for declarative windows.
2314 - $window_config = openstation_filter_native_window_config( $entry );
2315 - if ( ! empty( $window_config ) ) {
2316 - $script_payload['l10n'][] = sprintf(
2317 - 'window.openStationWindowConfig=window.openStationWindowConfig||{};window.openStationWindowConfig[%s]=%s;',
2318 - wp_json_encode( $entry['id'] ),
2319 - wp_json_encode( $window_config )
2320 - );
2321 - }
2322 - }
2323 -
2324 - // Tab metadata (label + extra script payloads) ships alongside
2325 - // the template so the shell can render a picker UI or load
2326 - // additional tab scripts when a tab's activation is late.
2760 + // Tab metadata ships alongside the template so the shell can
2761 + // render a picker UI, and each tab's script handle joins the
2762 + // map so a late tab activation can still load its bundle.
2327 2763 $tab_descriptors = array();
2328 2764 if ( function_exists( 'openstation_get_native_window_tabs' ) ) {
2329 2765 foreach ( openstation_get_native_window_tabs( $entry['id'] ) as $tab ) {
2330 - // The resolver returns the empty payload shape itself
2331 - // for an empty handle — no need to hand-write it here.
2332 - $tab_payload = openstation_resolve_script_payload( $tab['script'] );
2333 2766 $tab_descriptors[] = array(
2334 - 'value' => $tab['value'],
2335 - 'label' => $tab['label'],
2336 - 'isMain' => $tab['is_main'],
2337 - 'scriptUrl' => $tab_payload['url'],
2338 - 'scriptHandle' => $tab['script'],
2339 - 'scriptBefore' => $tab_payload['before'],
2340 - 'scriptAfter' => $tab_payload['after'],
2341 - 'scriptL10n' => $tab_payload['l10n'],
2342 - 'scriptTranslations' => $tab_payload['translations'],
2767 + 'value' => $tab['value'],
2768 + 'label' => $tab['label'],
2769 + 'isMain' => $tab['is_main'],
2770 + 'scriptHandle' => $collect_handle( $tab['script'] ),
2343 2771 );
2344 2772 }
2345 2773 }
2346 2774
2347 2775 $out[] = array(
2348 - 'id' => $entry['id'],
2349 - 'title' => $entry['title'],
2350 - 'icon' => $entry['icon'],
2351 - 'placement' => $entry['placement'],
2776 + 'id' => $entry['id'],
2777 + 'title' => $entry['title'],
2778 + 'icon' => $entry['icon'],
2779 + 'placement' => $entry['placement'],
2352 2780 // `'app'` or `'control'` — the navigation kind, which
2353 2781 // decides the launcher's default placement and its dock
2354 2782 // zone. See `src/nav/defaults.ts`.
2355 - 'navKind' => isset( $entry['nav_kind'] ) ? $entry['nav_kind'] : 'app',
2783 + 'navKind' => isset( $entry['nav_kind'] ) ? $entry['nav_kind'] : 'app',
2356 2784 // Sort key among system tiles. Absent / 0 puts a plugin's
2357 2785 // launcher ahead of the shell's own trailing cluster.
2358 - 'dockOrder' => isset( $entry['dock_order'] ) ? (int) $entry['dock_order'] : 0,
2359 - 'placeable' => ! empty( $entry['placeable'] ),
2360 - 'width' => $entry['width'],
2361 - 'height' => $entry['height'],
2362 - 'minWidth' => $entry['min_width'],
2363 - 'minHeight' => $entry['min_height'],
2364 - 'autofocus' => $entry['autofocus'],
2365 - 'templateId' => 'os-native-window-' . $entry['id'],
2366 - 'templateHtml' => $template_html,
2367 - 'scriptUrl' => $script_payload['url'],
2368 - 'scriptHandle' => $script_handle,
2369 - 'ownerHandle' => $script_handle,
2370 - 'scriptBefore' => $script_payload['before'],
2371 - 'scriptAfter' => $script_payload['after'],
2372 - 'scriptL10n' => $script_payload['l10n'],
2373 - 'scriptTranslations' => $script_payload['translations'],
2374 - 'companionScripts' => $companion_scripts,
2786 + 'dockOrder' => isset( $entry['dock_order'] ) ? (int) $entry['dock_order'] : 0,
2787 + 'placeable' => ! empty( $entry['placeable'] ),
2788 + 'width' => $entry['width'],
2789 + 'height' => $entry['height'],
2790 + 'minWidth' => $entry['min_width'],
2791 + 'minHeight' => $entry['min_height'],
2792 + 'autofocus' => $entry['autofocus'],
2793 + 'templateId' => 'os-native-window-' . $entry['id'],
2794 + 'templateHtml' => $template_html,
2795 + 'scriptHandle' => $script_handle,
2796 + 'ownerHandle' => $owner_handle,
2797 + 'companionScripts' => $companion_scripts,
2375 2798 // Whether the shell loads the bundle at boot rather than on
2376 2799 // first open. Off by default: a window's script is dead
2377 2800 // weight on every admin page until the window is actually
2378 2801 // opened.
2379 - 'preloadScript' => ! empty( $entry['preload_script'] ),
2380 - 'styleUrl' => $style_payload['url'],
2381 - 'styleHandle' => $style_handle,
2382 - 'styleInline' => $style_payload['inline'],
2383 - 'companionStyles' => $companion_styles,
2384 - 'tabs' => $tab_descriptors,
2802 + 'preloadScript' => ! empty( $entry['preload_script'] ),
2803 + 'styleUrl' => $style_payload['url'],
2804 + 'styleHandle' => $style_handle,
2805 + 'styleInline' => $style_payload['inline'],
2806 + 'companionStyles' => $companion_styles,
2807 + 'tabs' => $tab_descriptors,
2808 + 'menuPages' => isset( $entry['menu_pages'] ) ? array_values( (array) $entry['menu_pages'] ) : array(),
2385 2809 );
2386 2810 }
2387 2811
2388 - return $out;
2812 + // Append each handle's synthesized config set to its map entry —
2813 + // once, after the handle's own harvested data. The snippets land
2814 + // in REGISTRY-ITERATION order for every consumer of the handle;
2815 + // the old per-entry shape put each window's own config first, an
2816 + // ordering nothing could observe (each snippet assigns a distinct
2817 + // `openStationWindowConfig[ id ]` key and none reads another), so
2818 + // it is deliberately not preserved. Configs for handles that
2819 + // resolved to nothing are undeliverable and drop, exactly as they
2820 + // always did.
2821 + foreach ( $config_snippets_by_handle as $handle => $snippets ) {
2822 + if ( ! isset( $script_data[ $handle ] ) ) {
2823 + continue;
2824 + }
2825 + foreach ( $snippets as $snippet ) {
2826 + $script_data[ $handle ]['l10n'][] = $snippet;
2827 + }
2828 + }
2829 +
2830 + return array(
2831 + 'windows' => $out,
2832 + 'scriptData' => $script_data,
2833 + );
2389 2834 }
2390 2835
2391 2836 /**
2837 + * The `windows` half of {@see openstation_collect_native_windows_payload()}.
2838 + *
2839 + * Kept as the historical entry point — tests and older call sites
2840 + * ask for the entry list alone. Anything that also needs the
2841 + * script-data map (everything that actually LOADS a bundle) should
2842 + * call the collector and take both halves from one build.
2843 + *
2844 + * @return array[]
2845 + */
2846 +function openstation_build_native_windows_payload() {
2847 + $bundle = openstation_collect_native_windows_payload();
2848 + return $bundle['windows'];
2849 +}
2850 +
2851 +/**
2392 2852 * Cleans a `$menu` / `$submenu` title for display.
2393 2853 *
2394 2854 * Strips badge spans first (`<span class="update-plugins count-3">`),
2395 2855 * then any remaining markup. An empty result means the entry has no
@@ -2447,13 +2907,45 @@
2447 2907 return file_exists( ABSPATH . 'wp-admin/' . $file );
2448 2908 }
2449 2909
2450 2910 /**
2911 + * The admin URL a menu slug resolves against.
2912 + *
2913 + * Follows the admin the request is in: the network admin's own URL there,
2914 + * because its globals carry network slugs (`sites.php`, `settings.php`)
2915 + * that exist only under `wp-admin/network/`, and the site admin's
2916 + * everywhere else.
2917 + *
2918 + * The same answer `self_admin_url()` gives, without its filter. That
2919 + * filter receives the path, so a host can use it to send one screen
2920 + * somewhere else, and WordPress.com points `plugin-install.php` at its own
2921 + * installer. Resolved through it, the wp-admin original of a menu row the
2922 + * host replaced reads as off-site, and the dock drops it along with the
2923 + * replacement, which is how Plugins > Add Plugin disappears there.
2924 + *
2925 + * @param string $path Optional. Path relative to the admin URL.
2926 + * @return string Absolute admin URL.
2927 + */
2928 +function openstation_menu_admin_url( $path = '' ) {
2929 + if ( is_network_admin() ) {
2930 + return network_admin_url( $path );
2931 + }
2932 + if ( is_user_admin() ) {
2933 + return user_admin_url( $path );
2934 + }
2935 + return admin_url( $path );
2936 +}
2937 +
2938 +/**
2451 2939 * Converts a menu item slug to a full admin URL.
2452 2940 *
2941 + * Resolution goes through {@see openstation_menu_admin_url()}, which
2942 + * follows the admin the request is in without passing through the
2943 + * filterable `self_admin_url()`.
2944 + *
2453 2945 * Handles three slug shapes:
2454 2946 * 1. Direct file references (`edit.php`, `upload.php`) — passed
2455 - * through `admin_url()` as-is.
2947 + * through `openstation_menu_admin_url()` as-is.
2456 2948 * 2. Plain plugin page slugs (`my-plugin`) — routed through
2457 2949 * `admin.php?page=<slug>` with the slug `rawurlencode()`d.
2458 2950 * 3. Plugin page slugs that embed extra query parameters
2459 2951 * (`wc-admin&path=/customers`) — split on the first `&`, the
@@ -2514,9 +3006,9 @@
2514 3006 if (
2515 3007 false !== strpos( $slug, '.php' ) &&
2516 3008 ( ! isset( $_parent_pages[ $slug ] ) || openstation_is_admin_file_slug( $slug ) )
2517 3009 ) {
2518 - return esc_url_raw( admin_url( $slug ) );
3010 + return esc_url_raw( openstation_menu_admin_url( $slug ) );
2519 3011 }
2520 3012
2521 3013 // Plugin page slug with embedded query parameters
2522 3014 // (e.g., 'wc-admin&path=/customers'). Split the page slug from
@@ -2556,9 +3048,9 @@
2556 3048 $host = add_query_arg( 'page', $slug, $parent_slug );
2557 3049 }
2558 3050 }
2559 3051
2560 - $url = admin_url( $host );
3052 + $url = openstation_menu_admin_url( $host );
2561 3053 if ( ! empty( $extra_args ) ) {
2562 3054 $url = add_query_arg( $extra_args, $url );
2563 3055 }
2564 3056 return esc_url_raw( $url );