| @@ -2,9 +2,9 @@ | ||
| 2 | 2 | /** |
| 3 | 3 | * Desktop title-bar button registration API. |
| 4 | 4 | * |
| 5 | 5 | * Mirrors the command-script / settings-tab-script registration |
| 6 | - * pattern: minimum-ceremony PHP opt-in (`desktop_mode_register_titlebar_button_script`) | |
| 6 | + * pattern: minimum-ceremony PHP opt-in (`openstation_register_titlebar_button_script`) | |
| 7 | 7 | * tells the shell which enqueued scripts contribute title-bar |
| 8 | 8 | * buttons. The shell injects the script URL into the live-refresh |
| 9 | 9 | * payload so a plugin activated mid-session paints its button |
| 10 | 10 | * immediately, no F5 needed. |
| @@ -9,13 +9,12 @@ | ||
| 9 | 9 | * payload so a plugin activated mid-session paints its button |
| 10 | 10 | * immediately, no F5 needed. |
| 11 | 11 | * |
| 12 | 12 | * Buttons themselves are declared JS-side via |
| 13 | - * `wp.desktop.registerTitleBarButton( … )` — the predicate, render, | |
| 13 | + * `wp.os.registerTitleBarButton( … )` — the predicate, render, | |
| 14 | 14 | * and onClick all live in the plugin's TypeScript / JavaScript. |
| 15 | 15 | * |
| 16 | - * @since 0.17.0 | |
| 17 | - * @package WPDesktopMode | |
| 16 | + * @package OpenStation | |
| 18 | 17 | */ |
| 19 | 18 | |
| 20 | 19 | defined( 'ABSPATH' ) || exit; |
| 21 | 20 | |
| @@ -29,15 +28,15 @@ | ||
| 29 | 28 | * add_action( 'admin_enqueue_scripts', function () { |
| 30 | 29 | * wp_register_script( |
| 31 | 30 | * 'my-plugin-titlebar', |
| 32 | 31 | * plugins_url( 'js/titlebar.js', __FILE__ ), |
| 33 | - * array( 'desktop-mode' ), | |
| 32 | + * array( 'openstation' ), | |
| 34 | 33 | * '1.0.0', |
| 35 | 34 | * true |
| 36 | 35 | * ); |
| 37 | 36 | * wp_enqueue_script( 'my-plugin-titlebar' ); |
| 38 | - * } ); | |
| 39 | - * desktop_mode_register_titlebar_button_script( 'my-plugin-titlebar' ); | |
| 37 | + * }, 5 ); // Before the shell harvests the payload at priority 10. | |
| 38 | + * openstation_register_titlebar_button_script( 'my-plugin-titlebar' ); | |
| 40 | 39 | * ``` |
| 41 | 40 | * |
| 42 | 41 | * For live unregistration on deactivation, the plugin's JS should |
| 43 | 42 | * set `owner: 'my-plugin-titlebar'` on each `registerTitleBarButton` |
| @@ -43,32 +42,28 @@ | ||
| 43 | 42 | * set `owner: 'my-plugin-titlebar'` on each `registerTitleBarButton` |
| 44 | 43 | * call. Otherwise the button stays until the next page reload — |
| 45 | 44 | * graceful backwards-compat. |
| 46 | 45 | * |
| 47 | - * @since 0.17.0 | |
| 48 | - * | |
| 49 | 46 | * @param string $handle WP-registered script handle. |
| 50 | 47 | * @return true|WP_Error `true` on success; `WP_Error` on validation failure. |
| 51 | 48 | */ |
| 52 | -function desktop_mode_register_titlebar_button_script( $handle ) { | |
| 49 | +function openstation_register_titlebar_button_script( $handle ) { | |
| 53 | 50 | $handle = (string) $handle; |
| 54 | 51 | if ( '' === $handle ) { |
| 55 | - return desktop_mode_registration_error( | |
| 56 | - 'desktop_mode_missing_handle', | |
| 52 | + return openstation_registration_error( | |
| 53 | + 'openstation_missing_handle', | |
| 57 | 54 | __( 'Title-bar button script registration requires a non-empty script handle.', 'desktop-mode' ) |
| 58 | 55 | ); |
| 59 | 56 | } |
| 60 | 57 | |
| 61 | - desktop_mode_desktop_titlebar_button_script_registry( $handle, true ); | |
| 58 | + openstation_desktop_titlebar_button_script_registry( $handle, true ); | |
| 62 | 59 | |
| 63 | 60 | /** |
| 64 | 61 | * Fires after a desktop title-bar button script handle is registered. |
| 65 | 62 | * |
| 66 | - * @since 0.17.0 | |
| 67 | - * | |
| 68 | 63 | * @param string $handle The registered script handle. |
| 69 | 64 | */ |
| 70 | - do_action( 'desktop_mode_titlebar_button_script_registered', $handle ); | |
| 65 | + do_action( 'openstation_titlebar_button_script_registered', $handle ); | |
| 71 | 66 | |
| 72 | 67 | return true; |
| 73 | 68 | } |
| 74 | 69 | |
| @@ -74,9 +69,8 @@ | ||
| 74 | 69 | |
| 75 | 70 | /** |
| 76 | 71 | * Internal module-level registry for title-bar button script handles. |
| 77 | 72 | * |
| 78 | - * @since 0.17.0 | |
| 79 | 73 | * @internal |
| 80 | 74 | * |
| 81 | 75 | * @param string $handle Script handle to read or write. |
| 82 | 76 | * @param bool|null $value Pass `true` to register; `null` to read only. |
| @@ -81,9 +75,9 @@ | ||
| 81 | 75 | * @param string $handle Script handle to read or write. |
| 82 | 76 | * @param bool|null $value Pass `true` to register; `null` to read only. |
| 83 | 77 | * @return array|bool When called with no args returns the full store. |
| 84 | 78 | */ |
| 85 | -function desktop_mode_desktop_titlebar_button_script_registry( $handle = '', $value = null ) { | |
| 79 | +function openstation_desktop_titlebar_button_script_registry( $handle = '', $value = null ) { | |
| 86 | 80 | static $store = array(); |
| 87 | 81 | |
| 88 | 82 | if ( '__flush__' === (string) $handle ) { |
| 89 | 83 | $store = array(); |
| @@ -99,14 +93,12 @@ | ||
| 99 | 93 | } |
| 100 | 94 | |
| 101 | 95 | /** |
| 102 | 96 | * Test-only: clear the registry between PHPUnit cases. See |
| 103 | - * {@see desktop_mode_flush_script_handle_registries()}. | |
| 104 | - * | |
| 105 | - * @since 0.18.0 | |
| 97 | + * {@see openstation_flush_script_handle_registries()}. | |
| 106 | 98 | */ |
| 107 | -function desktop_mode_flush_desktop_titlebar_button_script_registry() { | |
| 108 | - desktop_mode_desktop_titlebar_button_script_registry( '__flush__' ); | |
| 99 | +function openstation_flush_desktop_titlebar_button_script_registry() { | |
| 100 | + openstation_desktop_titlebar_button_script_registry( '__flush__' ); | |
| 109 | 101 | } |
| 110 | 102 | |
| 111 | 103 | /** |
| 112 | 104 | * Build the script-handle payload fed to the shell. Handles that |
| @@ -111,14 +103,12 @@ | ||
| 111 | 103 | /** |
| 112 | 104 | * Build the script-handle payload fed to the shell. Handles that |
| 113 | 105 | * aren't currently enqueued resolve to an empty URL and are dropped. |
| 114 | 106 | * |
| 115 | - * @since 0.17.0 | |
| 116 | - * | |
| 117 | - * @return array[] List of `{ handle, scriptUrl }` entries. | |
| 107 | + * @return array[] List of `{ handle, scriptUrl, scriptBefore, scriptAfter, scriptL10n, scriptTranslations }` entries. | |
| 118 | 108 | */ |
| 119 | -function desktop_mode_build_desktop_titlebar_button_scripts_payload() { | |
| 120 | - $registry = desktop_mode_desktop_titlebar_button_script_registry(); | |
| 109 | +function openstation_build_desktop_titlebar_button_scripts_payload() { | |
| 110 | + $registry = openstation_desktop_titlebar_button_script_registry(); | |
| 121 | 111 | if ( ! is_array( $registry ) || empty( $registry ) ) { |
| 122 | 112 | return array(); |
| 123 | 113 | } |
| 124 | 114 | |
| @@ -127,19 +117,19 @@ | ||
| 127 | 117 | foreach ( $registry as $handle => $active ) { |
| 128 | 118 | if ( ! $active || isset( $seen[ $handle ] ) ) { |
| 129 | 119 | continue; |
| 130 | 120 | } |
| 131 | - $payload = desktop_mode_resolve_script_payload( $handle ); | |
| 121 | + $payload = openstation_resolve_script_payload( $handle ); | |
| 132 | 122 | if ( '' === $payload['url'] ) { |
| 133 | 123 | // Loud diagnostic — visible under WP_DEBUG. Plugin |
| 134 | 124 | // authors who pass a typo'd handle, or call our |
| 135 | 125 | // register helper before `wp_register_script()`, used |
| 136 | 126 | // to silently register nothing and stare at an empty |
| 137 | - // title bar. Deduped by `desktop_mode_warn_unresolvable_script_handle` | |
| 127 | + // title bar. Deduped by `openstation_warn_unresolvable_script_handle` | |
| 138 | 128 | // so the notice fires exactly once per handle per |
| 139 | 129 | // request, not on every shell-config rebuild. |
| 140 | - desktop_mode_warn_unresolvable_script_handle( | |
| 141 | - 'desktop_mode_register_titlebar_button_script', | |
| 130 | + openstation_warn_unresolvable_script_handle( | |
| 131 | + 'openstation_register_titlebar_button_script', | |
| 142 | 132 | 'Title-bar button', |
| 143 | 133 | (string) $handle |
| 144 | 134 | ); |
| 145 | 135 | continue; |
| @@ -150,8 +140,11 @@ | ||
| 150 | 140 | 'scriptBefore' => $payload['before'], |
| 151 | 141 | 'scriptAfter' => $payload['after'], |
| 152 | 142 | 'scriptL10n' => $payload['l10n'], |
| 153 | 143 | 'scriptTranslations' => $payload['translations'], |
| 144 | + // The handle's dependency closure, replayed before the bundle | |
| 145 | + // on its lazy load — see `openstation_resolve_script_dependencies()`. | |
| 146 | + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ), | |
| 154 | 147 | ); |
| 155 | 148 | $seen[ $handle ] = true; |
| 156 | 149 | } |
| 157 | 150 | return $out; |