PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
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 0.8.9 0.8.8 0.8.7 All 34 releases
← All changes | includes/window-chrome.php +235 -179 0.9.81.1.10 View file →
@@ -5,43 +5,45 @@
5 5 * Mirrors the commands / settings-tabs / title-bar-buttons registration
6 6 * pattern across four surfaces:
7 7 *
8 8 * - **Themes** (Layer 1) — per-window CSS-variable maps.
9 - * `desktop_mode_register_window_theme_script()` /
10 - * `desktop_mode_register_window_theme()`.
9 + * `openstation_register_window_theme_script()` /
10 + * `openstation_register_window_theme()`.
11 11 *
12 12 * - **Controls** (Layer 2) — title-bar buttons (close / minimize /
13 13 * maximize plus plugin custom controls).
14 - * `desktop_mode_register_window_control_script()` /
15 - * `desktop_mode_register_window_control()`.
14 + * `openstation_register_window_control_script()` /
15 + * `openstation_register_window_control()`.
16 16 *
17 17 * - **Slots** (Layer 3) — named title-bar regions plugins can
18 18 * replace (icon, title, before-controls, …).
19 - * `desktop_mode_register_window_slot_script()` /
20 - * `desktop_mode_register_window_slot()`.
19 + * `openstation_register_window_slot_script()` /
20 + * `openstation_register_window_slot()`.
21 21 *
22 22 * - **Chrome** (Layer 4, Experimental) — full title-bar render
23 23 * replacement.
24 - * `desktop_mode_register_window_chrome_script()` /
25 - * `desktop_mode_register_window_chrome()`.
24 + * `openstation_register_window_chrome_script()` /
25 + * `openstation_register_window_chrome()`.
26 26 *
27 27 * Each surface contributes a `serverWindow*Scripts` and (optionally)
28 28 * `serverWindow*` array to the shell payload, consumed by the matching
29 29 * sync module under `src/window-chrome/{themes,controls,slots,chrome}/server-sync.ts`.
30 30 *
31 - * @package WPDesktopMode
31 + * @package OpenStation
32 32 */
33 33
34 34 defined( 'ABSPATH' ) || exit;
35 35
36 -/* ============================================================
36 +/*
37 +============================================================
37 38 * Layer 1 — Themes
38 - * ============================================================ */
39 + * ============================================================
40 + */
39 41
40 42 /**
41 43 * Declare a WP-registered script handle as a window-theme provider.
42 44 *
43 - * The script's JS calls `wp.desktop.registerWindowTheme( { id, tokens,
45 + * The script's JS calls `wp.os.registerWindowTheme( { id, tokens,
44 46 * match, owner } )` as usual. Plugins that pass `owner` matching this
45 47 * handle get live unregister on deactivation.
46 48 *
47 49 * @param string $handle WP-registered script handle.
@@ -46,18 +48,18 @@
46 48 *
47 49 * @param string $handle WP-registered script handle.
48 50 * @return true|WP_Error `true` on success; `WP_Error` on validation failure.
49 51 */
50 -function desktop_mode_register_window_theme_script( $handle ) {
52 +function openstation_register_window_theme_script( $handle ) {
51 53 $handle = (string) $handle;
52 54 if ( '' === $handle ) {
53 - return desktop_mode_registration_error(
54 - 'desktop_mode_missing_handle',
55 + return openstation_registration_error(
56 + 'openstation_missing_handle',
55 57 __( 'Window theme script registration requires a non-empty script handle.', 'desktop-mode' )
56 58 );
57 59 }
58 60
59 - desktop_mode_window_theme_script_registry( $handle, true );
61 + openstation_window_theme_script_registry( $handle, true );
60 62
61 63 /**
62 64 * Fires after a desktop window-theme script handle is registered.
63 65 *
@@ -62,9 +64,9 @@
62 64 * Fires after a desktop window-theme script handle is registered.
63 65 *
64 66 * @param string $handle The registered script handle.
65 67 */
66 - do_action( 'desktop_mode_window_theme_script_registered', $handle );
68 + do_action( 'openstation_window_theme_script_registered', $handle );
67 69
68 70 return true;
69 71 }
70 72
@@ -69,9 +71,9 @@
69 71 }
70 72
71 73 /**
72 74 * Declare a window theme server-side. Optional companion to
73 - * `desktop_mode_register_window_theme_script()` for plugins that want
75 + * `openstation_register_window_theme_script()` for plugins that want
74 76 * to ship a tokens map without writing JS — designers can hand off
75 77 * a single PHP-array of CSS variables and call it done.
76 78 *
77 79 * @param array $args {
@@ -82,9 +84,9 @@
82 84 * @type string $script Optional script handle (also registers it).
83 85 * }
84 86 * @return true|WP_Error
85 87 */
86 -function desktop_mode_register_window_theme( $args = array() ) {
88 +function openstation_register_window_theme( $args = array() ) {
87 89 $defaults = array(
88 90 'id' => '',
89 91 'label' => '',
90 92 'tokens' => array(),
@@ -90,20 +92,20 @@
90 92 'tokens' => array(),
91 93 'priority' => 100,
92 94 'script' => '',
93 95 );
94 - $args = wp_parse_args( $args, $defaults );
96 + $args = wp_parse_args( $args, $defaults );
95 97
96 98 $id = (string) $args['id'];
97 99 if ( '' === $id ) {
98 - return desktop_mode_registration_error(
99 - 'desktop_mode_missing_id',
100 + return openstation_registration_error(
101 + 'openstation_missing_id',
100 102 __( 'Window theme registration requires a non-empty `id`.', 'desktop-mode' )
101 103 );
102 104 }
103 105 if ( ! is_array( $args['tokens'] ) || empty( $args['tokens'] ) ) {
104 - return desktop_mode_registration_error(
105 - 'desktop_mode_missing_tokens',
106 + return openstation_registration_error(
107 + 'openstation_missing_tokens',
106 108 __( 'Window theme registration requires a non-empty `tokens` map.', 'desktop-mode' ),
107 109 array( 'id' => $id )
108 110 );
109 111 }
@@ -110,10 +112,10 @@
110 112 $tokens = array();
111 113 foreach ( $args['tokens'] as $key => $value ) {
112 114 $key = (string) $key;
113 115 if ( '' === $key || 0 !== strpos( $key, '--' ) ) {
114 - return desktop_mode_registration_error(
115 - 'desktop_mode_invalid_token',
116 + return openstation_registration_error(
117 + 'openstation_invalid_token',
116 118 __( 'Window theme tokens must use CSS custom-property keys (start with "--").', 'desktop-mode' ),
117 119 array(
118 120 'id' => $id,
119 121 'key' => $key,
@@ -129,12 +131,12 @@
129 131 'tokens' => $tokens,
130 132 'priority' => (int) $args['priority'],
131 133 'script' => (string) $args['script'],
132 134 );
133 - desktop_mode_window_theme_registry( $id, $entry );
135 + openstation_window_theme_registry( $id, $entry );
134 136
135 137 if ( '' !== $entry['script'] ) {
136 - desktop_mode_window_theme_script_registry( $entry['script'], true );
138 + openstation_window_theme_script_registry( $entry['script'], true );
137 139 }
138 140
139 141 /**
140 142 * Fires after a desktop window-theme is successfully registered.
@@ -141,9 +143,9 @@
141 143 *
142 144 * @param string $id The theme id.
143 145 * @param array $entry The stored registry entry.
144 146 */
145 - do_action( 'desktop_mode_window_theme_registered', $id, $entry );
147 + do_action( 'openstation_window_theme_registered', $id, $entry );
146 148
147 149 return true;
148 150 }
149 151
@@ -155,9 +157,9 @@
155 157 * @param string $handle Script handle to read or write.
156 158 * @param bool|null $value Pass `true` to register; `null` to read only.
157 159 * @return array|bool When called with no args returns the full store.
158 160 */
159 -function desktop_mode_window_theme_script_registry( $handle = '', $value = null ) {
161 +function openstation_window_theme_script_registry( $handle = '', $value = null ) {
160 162 static $store = array();
161 163
162 164 if ( '__flush__' === (string) $handle ) {
163 165 $store = array();
@@ -172,10 +174,10 @@
172 174 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
173 175 }
174 176
175 177 /** Flush the theme-script registry. Tests only. */
176 -function desktop_mode_flush_window_theme_script_registry() {
177 - desktop_mode_window_theme_script_registry( '__flush__' );
178 +function openstation_flush_window_theme_script_registry() {
179 + openstation_window_theme_script_registry( '__flush__' );
178 180 }
179 181
180 182 /**
181 183 * Internal module-level registry for window themes.
@@ -185,9 +187,9 @@
185 187 * @param string $id Theme id to read or write.
186 188 * @param array|null $entry Entry to store, or `null` to read.
187 189 * @return array|null
188 190 */
189 -function desktop_mode_window_theme_registry( $id = '', $entry = null ) {
191 +function openstation_window_theme_registry( $id = '', $entry = null ) {
190 192 static $store = array();
191 193
192 194 if ( '__flush__' === (string) $id ) {
193 195 $store = array();
@@ -202,20 +204,20 @@
202 204 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
203 205 }
204 206
205 207 /** Flush the theme registry. Tests only. */
206 -function desktop_mode_flush_window_theme_registry() {
207 - desktop_mode_window_theme_registry( '__flush__' );
208 +function openstation_flush_window_theme_registry() {
209 + openstation_window_theme_registry( '__flush__' );
208 210 }
209 211
210 212 /**
211 213 * Build the theme-script payload. Same shape as
212 - * `desktop_mode_build_desktop_command_scripts_payload()`.
214 + * `openstation_build_desktop_command_scripts_payload()`.
213 215 *
214 216 * @return array[] List of `{ handle, scriptUrl }` entries.
215 217 */
216 -function desktop_mode_build_window_theme_scripts_payload() {
217 - $registry = desktop_mode_window_theme_script_registry();
218 +function openstation_build_window_theme_scripts_payload() {
219 + $registry = openstation_window_theme_script_registry();
218 220 if ( ! is_array( $registry ) || empty( $registry ) ) {
219 221 return array();
220 222 }
221 223
@@ -224,12 +226,12 @@
224 226 foreach ( $registry as $handle => $active ) {
225 227 if ( ! $active || isset( $seen[ $handle ] ) ) {
226 228 continue;
227 229 }
228 - $payload = desktop_mode_resolve_script_payload( $handle );
230 + $payload = openstation_resolve_script_payload( $handle );
229 231 if ( '' === $payload['url'] ) {
230 - desktop_mode_warn_unresolvable_script_handle(
231 - 'desktop_mode_register_window_theme_script',
232 + openstation_warn_unresolvable_script_handle(
233 + 'openstation_register_window_theme_script',
232 234 'Window theme',
233 235 (string) $handle
234 236 );
235 237 continue;
@@ -240,8 +242,11 @@
240 242 'scriptBefore' => $payload['before'],
241 243 'scriptAfter' => $payload['after'],
242 244 'scriptL10n' => $payload['l10n'],
243 245 'scriptTranslations' => $payload['translations'],
246 + // The handle's dependency closure, replayed before the bundle
247 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
248 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
244 249 );
245 250 $seen[ $handle ] = true;
246 251 }
247 252 return $out;
@@ -252,10 +257,10 @@
252 257 * script handle for each entry.
253 258 *
254 259 * @return array[]
255 260 */
256 -function desktop_mode_build_window_themes_payload() {
257 - $registry = desktop_mode_window_theme_registry();
261 +function openstation_build_window_themes_payload() {
262 + $registry = openstation_window_theme_registry();
258 263 if ( ! is_array( $registry ) || empty( $registry ) ) {
259 264 return array();
260 265 }
261 266
@@ -262,29 +267,40 @@
262 267 $out = array();
263 268 foreach ( $registry as $entry ) {
264 269 $handle = (string) $entry['script'];
265 270 $payload = '' !== $handle
266 - ? desktop_mode_resolve_script_payload( $handle )
267 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
268 - $out[] = array(
269 - 'id' => (string) $entry['id'],
270 - 'label' => (string) $entry['label'],
271 - 'tokens' => (array) $entry['tokens'],
272 - 'priority' => (int) $entry['priority'],
273 - 'scriptUrl' => $payload['url'],
274 - 'scriptHandle' => $handle,
275 - 'scriptBefore' => $payload['before'],
276 - 'scriptAfter' => $payload['after'],
277 - 'scriptL10n' => $payload['l10n'],
271 + ? openstation_resolve_script_payload( $handle )
272 + : array(
273 + 'url' => '',
274 + 'before' => array(),
275 + 'after' => array(),
276 + 'l10n' => array(),
277 + 'translations' => '',
278 + );
279 + $out[] = array(
280 + 'id' => (string) $entry['id'],
281 + 'label' => (string) $entry['label'],
282 + 'tokens' => (array) $entry['tokens'],
283 + 'priority' => (int) $entry['priority'],
284 + 'scriptUrl' => $payload['url'],
285 + 'scriptHandle' => $handle,
286 + 'scriptBefore' => $payload['before'],
287 + 'scriptAfter' => $payload['after'],
288 + 'scriptL10n' => $payload['l10n'],
278 289 'scriptTranslations' => $payload['translations'],
290 + // The handle's dependency closure, replayed before the bundle
291 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
292 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
279 293 );
280 294 }
281 295 return $out;
282 296 }
283 297
284 -/* ============================================================
298 +/*
299 +============================================================
285 300 * Layer 2 — Controls
286 - * ============================================================ */
301 + * ============================================================
302 + */
287 303
288 304 /**
289 305 * Declare a WP-registered script handle as a window-control provider.
290 306 *
@@ -290,18 +306,18 @@
290 306 *
291 307 * @param string $handle WP-registered script handle.
292 308 * @return true|WP_Error
293 309 */
294 -function desktop_mode_register_window_control_script( $handle ) {
310 +function openstation_register_window_control_script( $handle ) {
295 311 $handle = (string) $handle;
296 312 if ( '' === $handle ) {
297 - return desktop_mode_registration_error(
298 - 'desktop_mode_missing_handle',
313 + return openstation_registration_error(
314 + 'openstation_missing_handle',
299 315 __( 'Window control script registration requires a non-empty script handle.', 'desktop-mode' )
300 316 );
301 317 }
302 318
303 - desktop_mode_window_control_script_registry( $handle, true );
319 + openstation_window_control_script_registry( $handle, true );
304 320
305 321 /**
306 322 * Fires after a window-control script handle is registered.
307 323 *
@@ -306,9 +322,9 @@
306 322 * Fires after a window-control script handle is registered.
307 323 *
308 324 * @param string $handle The registered script handle.
309 325 */
310 - do_action( 'desktop_mode_window_control_script_registered', $handle );
326 + do_action( 'openstation_window_control_script_registered', $handle );
311 327
312 328 return true;
313 329 }
314 330
@@ -325,9 +341,9 @@
325 341 * @type string $script Optional companion script handle.
326 342 * }
327 343 * @return true|WP_Error
328 344 */
329 -function desktop_mode_register_window_control( $args = array() ) {
345 +function openstation_register_window_control( $args = array() ) {
330 346 $defaults = array(
331 347 'id' => '',
332 348 'label' => '',
333 349 'icon' => '',
@@ -334,20 +350,20 @@
334 350 'placement' => 'left',
335 351 'order' => 100,
336 352 'script' => '',
337 353 );
338 - $args = wp_parse_args( $args, $defaults );
354 + $args = wp_parse_args( $args, $defaults );
339 355
340 356 $id = (string) $args['id'];
341 357 if ( '' === $id ) {
342 - return desktop_mode_registration_error(
343 - 'desktop_mode_missing_id',
358 + return openstation_registration_error(
359 + 'openstation_missing_id',
344 360 __( 'Window control registration requires a non-empty `id`.', 'desktop-mode' )
345 361 );
346 362 }
347 363 if ( '' === (string) $args['label'] ) {
348 - return desktop_mode_registration_error(
349 - 'desktop_mode_missing_label',
364 + return openstation_registration_error(
365 + 'openstation_missing_label',
350 366 __( 'Window control registration requires a non-empty `label`.', 'desktop-mode' ),
351 367 array( 'id' => $id )
352 368 );
353 369 }
@@ -352,10 +368,10 @@
352 368 );
353 369 }
354 370 $placement = (string) $args['placement'];
355 371 if ( ! in_array( $placement, array( 'left', 'right', 'controls' ), true ) ) {
356 - return desktop_mode_registration_error(
357 - 'desktop_mode_invalid_placement',
372 + return openstation_registration_error(
373 + 'openstation_invalid_placement',
358 374 __( 'Window control `placement` must be one of "left", "right", "controls".', 'desktop-mode' ),
359 375 array(
360 376 'id' => $id,
361 377 'placement' => $placement,
@@ -370,12 +386,12 @@
370 386 'placement' => $placement,
371 387 'order' => (int) $args['order'],
372 388 'script' => (string) $args['script'],
373 389 );
374 - desktop_mode_window_control_registry( $id, $entry );
390 + openstation_window_control_registry( $id, $entry );
375 391
376 392 if ( '' !== $entry['script'] ) {
377 - desktop_mode_window_control_script_registry( $entry['script'], true );
393 + openstation_window_control_script_registry( $entry['script'], true );
378 394 }
379 395
380 396 /**
381 397 * Fires after a window-control is successfully registered.
@@ -382,15 +398,15 @@
382 398 *
383 399 * @param string $id The control id.
384 400 * @param array $entry The stored registry entry.
385 401 */
386 - do_action( 'desktop_mode_window_control_registered', $id, $entry );
402 + do_action( 'openstation_window_control_registered', $id, $entry );
387 403
388 404 return true;
389 405 }
390 406
391 407 /** @internal */
392 -function desktop_mode_window_control_script_registry( $handle = '', $value = null ) {
408 +function openstation_window_control_script_registry( $handle = '', $value = null ) {
393 409 static $store = array();
394 410
395 411 if ( '__flush__' === (string) $handle ) {
396 412 $store = array();
@@ -405,14 +421,14 @@
405 421 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
406 422 }
407 423
408 424 /** Tests only. */
409 -function desktop_mode_flush_window_control_script_registry() {
410 - desktop_mode_window_control_script_registry( '__flush__' );
425 +function openstation_flush_window_control_script_registry() {
426 + openstation_window_control_script_registry( '__flush__' );
411 427 }
412 428
413 429 /** @internal */
414 -function desktop_mode_window_control_registry( $id = '', $entry = null ) {
430 +function openstation_window_control_registry( $id = '', $entry = null ) {
415 431 static $store = array();
416 432
417 433 if ( '__flush__' === (string) $id ) {
418 434 $store = array();
@@ -427,17 +443,17 @@
427 443 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
428 444 }
429 445
430 446 /** Tests only. */
431 -function desktop_mode_flush_window_control_registry() {
432 - desktop_mode_window_control_registry( '__flush__' );
447 +function openstation_flush_window_control_registry() {
448 + openstation_window_control_registry( '__flush__' );
433 449 }
434 450
435 451 /**
436 452 * @return array[] List of `{ handle, scriptUrl }` entries.
437 453 */
438 -function desktop_mode_build_window_control_scripts_payload() {
439 - $registry = desktop_mode_window_control_script_registry();
454 +function openstation_build_window_control_scripts_payload() {
455 + $registry = openstation_window_control_script_registry();
440 456 if ( ! is_array( $registry ) || empty( $registry ) ) {
441 457 return array();
442 458 }
443 459
@@ -446,12 +462,12 @@
446 462 foreach ( $registry as $handle => $active ) {
447 463 if ( ! $active || isset( $seen[ $handle ] ) ) {
448 464 continue;
449 465 }
450 - $payload = desktop_mode_resolve_script_payload( $handle );
466 + $payload = openstation_resolve_script_payload( $handle );
451 467 if ( '' === $payload['url'] ) {
452 - desktop_mode_warn_unresolvable_script_handle(
453 - 'desktop_mode_register_window_control_script',
468 + openstation_warn_unresolvable_script_handle(
469 + 'openstation_register_window_control_script',
454 470 'Window control',
455 471 (string) $handle
456 472 );
457 473 continue;
@@ -462,8 +478,11 @@
462 478 'scriptBefore' => $payload['before'],
463 479 'scriptAfter' => $payload['after'],
464 480 'scriptL10n' => $payload['l10n'],
465 481 'scriptTranslations' => $payload['translations'],
482 + // The handle's dependency closure, replayed before the bundle
483 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
484 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
466 485 );
467 486 $seen[ $handle ] = true;
468 487 }
469 488 return $out;
@@ -471,10 +490,10 @@
471 490
472 491 /**
473 492 * @return array[]
474 493 */
475 -function desktop_mode_build_window_controls_payload() {
476 - $registry = desktop_mode_window_control_registry();
494 +function openstation_build_window_controls_payload() {
495 + $registry = openstation_window_control_registry();
477 496 if ( ! is_array( $registry ) || empty( $registry ) ) {
478 497 return array();
479 498 }
480 499
@@ -481,30 +500,41 @@
481 500 $out = array();
482 501 foreach ( $registry as $entry ) {
483 502 $handle = (string) $entry['script'];
484 503 $payload = '' !== $handle
485 - ? desktop_mode_resolve_script_payload( $handle )
486 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
487 - $out[] = array(
488 - 'id' => (string) $entry['id'],
489 - 'label' => (string) $entry['label'],
490 - 'icon' => (string) $entry['icon'],
491 - 'placement' => (string) $entry['placement'],
492 - 'order' => (int) $entry['order'],
493 - 'scriptUrl' => $payload['url'],
494 - 'scriptHandle' => $handle,
495 - 'scriptBefore' => $payload['before'],
496 - 'scriptAfter' => $payload['after'],
497 - 'scriptL10n' => $payload['l10n'],
504 + ? openstation_resolve_script_payload( $handle )
505 + : array(
506 + 'url' => '',
507 + 'before' => array(),
508 + 'after' => array(),
509 + 'l10n' => array(),
510 + 'translations' => '',
511 + );
512 + $out[] = array(
513 + 'id' => (string) $entry['id'],
514 + 'label' => (string) $entry['label'],
515 + 'icon' => (string) $entry['icon'],
516 + 'placement' => (string) $entry['placement'],
517 + 'order' => (int) $entry['order'],
518 + 'scriptUrl' => $payload['url'],
519 + 'scriptHandle' => $handle,
520 + 'scriptBefore' => $payload['before'],
521 + 'scriptAfter' => $payload['after'],
522 + 'scriptL10n' => $payload['l10n'],
498 523 'scriptTranslations' => $payload['translations'],
524 + // The handle's dependency closure, replayed before the bundle
525 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
526 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
499 527 );
500 528 }
501 529 return $out;
502 530 }
503 531
504 -/* ============================================================
532 +/*
533 +============================================================
505 534 * Layer 3 — Slots
506 - * ============================================================ */
535 + * ============================================================
536 + */
507 537
508 538 /**
509 539 * Canonical slot names. Mirrors the `WindowSlotName` TypeScript
510 540 * union in `src/types.ts`.
@@ -510,9 +540,9 @@
510 540 * union in `src/types.ts`.
511 541 *
512 542 * @return string[]
513 543 */
514 -function desktop_mode_window_slot_names() {
544 +function openstation_window_slot_names() {
515 545 return array(
516 546 'before-titlebar',
517 547 'before-icon',
518 548 'icon',
@@ -528,18 +558,18 @@
528 558 /**
529 559 * @param string $handle WP-registered script handle.
530 560 * @return true|WP_Error
531 561 */
532 -function desktop_mode_register_window_slot_script( $handle ) {
562 +function openstation_register_window_slot_script( $handle ) {
533 563 $handle = (string) $handle;
534 564 if ( '' === $handle ) {
535 - return desktop_mode_registration_error(
536 - 'desktop_mode_missing_handle',
565 + return openstation_registration_error(
566 + 'openstation_missing_handle',
537 567 __( 'Window slot script registration requires a non-empty script handle.', 'desktop-mode' )
538 568 );
539 569 }
540 570
541 - desktop_mode_window_slot_script_registry( $handle, true );
571 + openstation_window_slot_script_registry( $handle, true );
542 572
543 573 /**
544 574 * Fires after a window-slot script handle is registered.
545 575 *
@@ -544,9 +574,9 @@
544 574 * Fires after a window-slot script handle is registered.
545 575 *
546 576 * @param string $handle The registered script handle.
547 577 */
548 - do_action( 'desktop_mode_window_slot_script_registered', $handle );
578 + do_action( 'openstation_window_slot_script_registered', $handle );
549 579
550 580 return true;
551 581 }
552 582
@@ -552,15 +582,15 @@
552 582
553 583 /**
554 584 * @param array $args {
555 585 * @type string $id Required.
556 - * @type string $slot Required, one of {@see desktop_mode_window_slot_names()}.
586 + * @type string $slot Required, one of {@see openstation_window_slot_names()}.
557 587 * @type int $order Default 100.
558 588 * @type string $script Optional script handle.
559 589 * }
560 590 * @return true|WP_Error
561 591 */
562 -function desktop_mode_register_window_slot( $args = array() ) {
592 +function openstation_register_window_slot( $args = array() ) {
563 593 $defaults = array(
564 594 'id' => '',
565 595 'slot' => '',
566 596 'order' => 100,
@@ -565,21 +595,21 @@
565 595 'slot' => '',
566 596 'order' => 100,
567 597 'script' => '',
568 598 );
569 - $args = wp_parse_args( $args, $defaults );
599 + $args = wp_parse_args( $args, $defaults );
570 600
571 601 $id = (string) $args['id'];
572 602 if ( '' === $id ) {
573 - return desktop_mode_registration_error(
574 - 'desktop_mode_missing_id',
603 + return openstation_registration_error(
604 + 'openstation_missing_id',
575 605 __( 'Window slot registration requires a non-empty `id`.', 'desktop-mode' )
576 606 );
577 607 }
578 608 $slot = (string) $args['slot'];
579 - if ( ! in_array( $slot, desktop_mode_window_slot_names(), true ) ) {
580 - return desktop_mode_registration_error(
581 - 'desktop_mode_invalid_slot',
609 + if ( ! in_array( $slot, openstation_window_slot_names(), true ) ) {
610 + return openstation_registration_error(
611 + 'openstation_invalid_slot',
582 612 __( 'Window slot registration requires a known `slot` name.', 'desktop-mode' ),
583 613 array(
584 614 'id' => $id,
585 615 'slot' => $slot,
@@ -592,12 +622,12 @@
592 622 'slot' => $slot,
593 623 'order' => (int) $args['order'],
594 624 'script' => (string) $args['script'],
595 625 );
596 - desktop_mode_window_slot_registry( $id, $entry );
626 + openstation_window_slot_registry( $id, $entry );
597 627
598 628 if ( '' !== $entry['script'] ) {
599 - desktop_mode_window_slot_script_registry( $entry['script'], true );
629 + openstation_window_slot_script_registry( $entry['script'], true );
600 630 }
601 631
602 632 /**
603 633 * Fires after a window-slot is successfully registered.
@@ -604,15 +634,15 @@
604 634 *
605 635 * @param string $id The slot-renderer id.
606 636 * @param array $entry The stored registry entry.
607 637 */
608 - do_action( 'desktop_mode_window_slot_registered', $id, $entry );
638 + do_action( 'openstation_window_slot_registered', $id, $entry );
609 639
610 640 return true;
611 641 }
612 642
613 643 /** @internal */
614 -function desktop_mode_window_slot_script_registry( $handle = '', $value = null ) {
644 +function openstation_window_slot_script_registry( $handle = '', $value = null ) {
615 645 static $store = array();
616 646
617 647 if ( '__flush__' === (string) $handle ) {
618 648 $store = array();
@@ -627,14 +657,14 @@
627 657 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
628 658 }
629 659
630 660 /** Tests only. */
631 -function desktop_mode_flush_window_slot_script_registry() {
632 - desktop_mode_window_slot_script_registry( '__flush__' );
661 +function openstation_flush_window_slot_script_registry() {
662 + openstation_window_slot_script_registry( '__flush__' );
633 663 }
634 664
635 665 /** @internal */
636 -function desktop_mode_window_slot_registry( $id = '', $entry = null ) {
666 +function openstation_window_slot_registry( $id = '', $entry = null ) {
637 667 static $store = array();
638 668
639 669 if ( '__flush__' === (string) $id ) {
640 670 $store = array();
@@ -649,17 +679,17 @@
649 679 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
650 680 }
651 681
652 682 /** Tests only. */
653 -function desktop_mode_flush_window_slot_registry() {
654 - desktop_mode_window_slot_registry( '__flush__' );
683 +function openstation_flush_window_slot_registry() {
684 + openstation_window_slot_registry( '__flush__' );
655 685 }
656 686
657 687 /**
658 688 * @return array[] List of `{ handle, scriptUrl }` entries.
659 689 */
660 -function desktop_mode_build_window_slot_scripts_payload() {
661 - $registry = desktop_mode_window_slot_script_registry();
690 +function openstation_build_window_slot_scripts_payload() {
691 + $registry = openstation_window_slot_script_registry();
662 692 if ( ! is_array( $registry ) || empty( $registry ) ) {
663 693 return array();
664 694 }
665 695
@@ -668,12 +698,12 @@
668 698 foreach ( $registry as $handle => $active ) {
669 699 if ( ! $active || isset( $seen[ $handle ] ) ) {
670 700 continue;
671 701 }
672 - $payload = desktop_mode_resolve_script_payload( $handle );
702 + $payload = openstation_resolve_script_payload( $handle );
673 703 if ( '' === $payload['url'] ) {
674 - desktop_mode_warn_unresolvable_script_handle(
675 - 'desktop_mode_register_window_slot_script',
704 + openstation_warn_unresolvable_script_handle(
705 + 'openstation_register_window_slot_script',
676 706 'Window slot',
677 707 (string) $handle
678 708 );
679 709 continue;
@@ -684,8 +714,11 @@
684 714 'scriptBefore' => $payload['before'],
685 715 'scriptAfter' => $payload['after'],
686 716 'scriptL10n' => $payload['l10n'],
687 717 'scriptTranslations' => $payload['translations'],
718 + // The handle's dependency closure, replayed before the bundle
719 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
720 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
688 721 );
689 722 $seen[ $handle ] = true;
690 723 }
691 724 return $out;
@@ -693,10 +726,10 @@
693 726
694 727 /**
695 728 * @return array[]
696 729 */
697 -function desktop_mode_build_window_slots_payload() {
698 - $registry = desktop_mode_window_slot_registry();
730 +function openstation_build_window_slots_payload() {
731 + $registry = openstation_window_slot_registry();
699 732 if ( ! is_array( $registry ) || empty( $registry ) ) {
700 733 return array();
701 734 }
702 735
@@ -703,28 +736,39 @@
703 736 $out = array();
704 737 foreach ( $registry as $entry ) {
705 738 $handle = (string) $entry['script'];
706 739 $payload = '' !== $handle
707 - ? desktop_mode_resolve_script_payload( $handle )
708 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
709 - $out[] = array(
710 - 'id' => (string) $entry['id'],
711 - 'slot' => (string) $entry['slot'],
712 - 'order' => (int) $entry['order'],
713 - 'scriptUrl' => $payload['url'],
714 - 'scriptHandle' => $handle,
715 - 'scriptBefore' => $payload['before'],
716 - 'scriptAfter' => $payload['after'],
717 - 'scriptL10n' => $payload['l10n'],
740 + ? openstation_resolve_script_payload( $handle )
741 + : array(
742 + 'url' => '',
743 + 'before' => array(),
744 + 'after' => array(),
745 + 'l10n' => array(),
746 + 'translations' => '',
747 + );
748 + $out[] = array(
749 + 'id' => (string) $entry['id'],
750 + 'slot' => (string) $entry['slot'],
751 + 'order' => (int) $entry['order'],
752 + 'scriptUrl' => $payload['url'],
753 + 'scriptHandle' => $handle,
754 + 'scriptBefore' => $payload['before'],
755 + 'scriptAfter' => $payload['after'],
756 + 'scriptL10n' => $payload['l10n'],
718 757 'scriptTranslations' => $payload['translations'],
758 + // The handle's dependency closure, replayed before the bundle
759 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
760 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
719 761 );
720 762 }
721 763 return $out;
722 764 }
723 765
724 -/* ============================================================
766 +/*
767 +============================================================
725 768 * Layer 4 — Custom chrome (Experimental)
726 - * ============================================================ */
769 + * ============================================================
770 + */
727 771
728 772 /**
729 773 * Declare a WP-registered script handle as a window-chrome provider.
730 774 *
@@ -732,18 +776,18 @@
732 776 *
733 777 * @param string $handle WP-registered script handle.
734 778 * @return true|WP_Error
735 779 */
736 -function desktop_mode_register_window_chrome_script( $handle ) {
780 +function openstation_register_window_chrome_script( $handle ) {
737 781 $handle = (string) $handle;
738 782 if ( '' === $handle ) {
739 - return desktop_mode_registration_error(
740 - 'desktop_mode_missing_handle',
783 + return openstation_registration_error(
784 + 'openstation_missing_handle',
741 785 __( 'Window chrome script registration requires a non-empty script handle.', 'desktop-mode' )
742 786 );
743 787 }
744 788
745 - desktop_mode_window_chrome_script_registry( $handle, true );
789 + openstation_window_chrome_script_registry( $handle, true );
746 790
747 791 /**
748 792 * Fires after a window-chrome script handle is registered.
749 793 *
@@ -748,9 +792,9 @@
748 792 * Fires after a window-chrome script handle is registered.
749 793 *
750 794 * @param string $handle The registered script handle.
751 795 */
752 - do_action( 'desktop_mode_window_chrome_script_registered', $handle );
796 + do_action( 'openstation_window_chrome_script_registered', $handle );
753 797
754 798 return true;
755 799 }
756 800
@@ -764,20 +808,20 @@
764 808 * @type string $script Optional script handle.
765 809 * }
766 810 * @return true|WP_Error
767 811 */
768 -function desktop_mode_register_window_chrome( $args = array() ) {
812 +function openstation_register_window_chrome( $args = array() ) {
769 813 $defaults = array(
770 814 'id' => '',
771 815 'label' => '',
772 816 'script' => '',
773 817 );
774 - $args = wp_parse_args( $args, $defaults );
818 + $args = wp_parse_args( $args, $defaults );
775 819
776 820 $id = (string) $args['id'];
777 821 if ( '' === $id ) {
778 - return desktop_mode_registration_error(
779 - 'desktop_mode_missing_id',
822 + return openstation_registration_error(
823 + 'openstation_missing_id',
780 824 __( 'Window chrome registration requires a non-empty `id`.', 'desktop-mode' )
781 825 );
782 826 }
783 827
@@ -785,12 +829,12 @@
785 829 'id' => $id,
786 830 'label' => (string) $args['label'],
787 831 'script' => (string) $args['script'],
788 832 );
789 - desktop_mode_window_chrome_registry( $id, $entry );
833 + openstation_window_chrome_registry( $id, $entry );
790 834
791 835 if ( '' !== $entry['script'] ) {
792 - desktop_mode_window_chrome_script_registry( $entry['script'], true );
836 + openstation_window_chrome_script_registry( $entry['script'], true );
793 837 }
794 838
795 839 /**
796 840 * Fires after a window-chrome is successfully registered.
@@ -797,15 +841,15 @@
797 841 *
798 842 * @param string $id The chrome id.
799 843 * @param array $entry The stored registry entry.
800 844 */
801 - do_action( 'desktop_mode_window_chrome_registered', $id, $entry );
845 + do_action( 'openstation_window_chrome_registered', $id, $entry );
802 846
803 847 return true;
804 848 }
805 849
806 850 /** @internal */
807 -function desktop_mode_window_chrome_script_registry( $handle = '', $value = null ) {
851 +function openstation_window_chrome_script_registry( $handle = '', $value = null ) {
808 852 static $store = array();
809 853
810 854 if ( '__flush__' === (string) $handle ) {
811 855 $store = array();
@@ -820,14 +864,14 @@
820 864 return isset( $store[ (string) $handle ] ) ? $store[ (string) $handle ] : false;
821 865 }
822 866
823 867 /** Tests only. */
824 -function desktop_mode_flush_window_chrome_script_registry() {
825 - desktop_mode_window_chrome_script_registry( '__flush__' );
868 +function openstation_flush_window_chrome_script_registry() {
869 + openstation_window_chrome_script_registry( '__flush__' );
826 870 }
827 871
828 872 /** @internal */
829 -function desktop_mode_window_chrome_registry( $id = '', $entry = null ) {
873 +function openstation_window_chrome_registry( $id = '', $entry = null ) {
830 874 static $store = array();
831 875
832 876 if ( '__flush__' === (string) $id ) {
833 877 $store = array();
@@ -842,17 +886,17 @@
842 886 return isset( $store[ (string) $id ] ) ? $store[ (string) $id ] : null;
843 887 }
844 888
845 889 /** Tests only. */
846 -function desktop_mode_flush_window_chrome_registry() {
847 - desktop_mode_window_chrome_registry( '__flush__' );
890 +function openstation_flush_window_chrome_registry() {
891 + openstation_window_chrome_registry( '__flush__' );
848 892 }
849 893
850 894 /**
851 895 * @return array[] List of `{ handle, scriptUrl }` entries.
852 896 */
853 -function desktop_mode_build_window_chrome_scripts_payload() {
854 - $registry = desktop_mode_window_chrome_script_registry();
897 +function openstation_build_window_chrome_scripts_payload() {
898 + $registry = openstation_window_chrome_script_registry();
855 899 if ( ! is_array( $registry ) || empty( $registry ) ) {
856 900 return array();
857 901 }
858 902
@@ -861,12 +905,12 @@
861 905 foreach ( $registry as $handle => $active ) {
862 906 if ( ! $active || isset( $seen[ $handle ] ) ) {
863 907 continue;
864 908 }
865 - $payload = desktop_mode_resolve_script_payload( $handle );
909 + $payload = openstation_resolve_script_payload( $handle );
866 910 if ( '' === $payload['url'] ) {
867 - desktop_mode_warn_unresolvable_script_handle(
868 - 'desktop_mode_register_window_chrome_script',
911 + openstation_warn_unresolvable_script_handle(
912 + 'openstation_register_window_chrome_script',
869 913 'Window chrome',
870 914 (string) $handle
871 915 );
872 916 continue;
@@ -877,8 +921,11 @@
877 921 'scriptBefore' => $payload['before'],
878 922 'scriptAfter' => $payload['after'],
879 923 'scriptL10n' => $payload['l10n'],
880 924 'scriptTranslations' => $payload['translations'],
925 + // The handle's dependency closure, replayed before the bundle
926 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
927 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
881 928 );
882 929 $seen[ $handle ] = true;
883 930 }
884 931 return $out;
@@ -886,10 +933,10 @@
886 933
887 934 /**
888 935 * @return array[]
889 936 */
890 -function desktop_mode_build_window_chromes_payload() {
891 - $registry = desktop_mode_window_chrome_registry();
937 +function openstation_build_window_chromes_payload() {
938 + $registry = openstation_window_chrome_registry();
892 939 if ( ! is_array( $registry ) || empty( $registry ) ) {
893 940 return array();
894 941 }
895 942
@@ -896,19 +943,28 @@
896 943 $out = array();
897 944 foreach ( $registry as $entry ) {
898 945 $handle = (string) $entry['script'];
899 946 $payload = '' !== $handle
900 - ? desktop_mode_resolve_script_payload( $handle )
901 - : array( 'url' => '', 'before' => array(), 'after' => array(), 'l10n' => array(), 'translations' => '' );
902 - $out[] = array(
903 - 'id' => (string) $entry['id'],
904 - 'label' => (string) $entry['label'],
905 - 'scriptUrl' => $payload['url'],
906 - 'scriptHandle' => $handle,
907 - 'scriptBefore' => $payload['before'],
908 - 'scriptAfter' => $payload['after'],
909 - 'scriptL10n' => $payload['l10n'],
947 + ? openstation_resolve_script_payload( $handle )
948 + : array(
949 + 'url' => '',
950 + 'before' => array(),
951 + 'after' => array(),
952 + 'l10n' => array(),
953 + 'translations' => '',
954 + );
955 + $out[] = array(
956 + 'id' => (string) $entry['id'],
957 + 'label' => (string) $entry['label'],
958 + 'scriptUrl' => $payload['url'],
959 + 'scriptHandle' => $handle,
960 + 'scriptBefore' => $payload['before'],
961 + 'scriptAfter' => $payload['after'],
962 + 'scriptL10n' => $payload['l10n'],
910 963 'scriptTranslations' => $payload['translations'],
964 + // The handle's dependency closure, replayed before the bundle
965 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
966 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
911 967 );
912 968 }
913 969 return $out;
914 970 }