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/commands.php +63 -74 0.9.01.1.10 View file →
@@ -4,26 +4,25 @@
4 4 *
5 5 * Two entry points, mirroring the rest of the plugin surface but tuned
6 6 * for the command-palette use case:
7 7 *
8 - * - `desktop_mode_register_command_script( $handle )` — primary, minimum-
8 + * - `openstation_register_command_script( $handle )` — primary, minimum-
9 9 * ceremony opt-in. Tells the shell: "this enqueued script registers
10 10 * slash-commands; include it in the plugins-changed payload so it
11 11 * gets injected into the shell page mid-session when my plugin is
12 12 * installed or activated without a full reload."
13 13 *
14 - * - `desktop_mode_register_command( $args )` — optional. Plugins that
14 + * - `openstation_register_command( $args )` — optional. Plugins that
15 15 * want to declare command metadata server-side (for discoverability
16 16 * tooling, REST enumeration, future pre-registration shims) use this.
17 17 * The `run` function still lives JS-side; metadata is advisory today.
18 18 *
19 - * Both APIs feed `desktop_mode_build_desktop_command_scripts_payload()` and
20 - * `desktop_mode_build_desktop_commands_payload()`, which contribute
19 + * Both APIs feed `openstation_build_desktop_command_scripts_payload()` and
20 + * `openstation_build_desktop_commands_payload()`, which contribute
21 21 * `serverCommandScripts` and `serverCommands` to the shell payload in
22 - * `desktop_mode_build_menu_payload()`.
22 + * `openstation_build_menu_payload()`.
23 23 *
24 - * @since 0.15.0
25 - * @package WPDesktopMode
24 + * @package OpenStation
26 25 */
27 26
28 27 defined( 'ABSPATH' ) || exit;
29 28
@@ -36,48 +35,44 @@
36 35 * add_action( 'admin_enqueue_scripts', function () {
37 36 * wp_register_script(
38 37 * 'home-assistant-commands',
39 38 * plugins_url( 'js/commands.js', __FILE__ ),
40 - * array( 'desktop-mode' ),
39 + * array( 'openstation' ),
41 40 * '1.0.0',
42 41 * true
43 42 * );
44 43 * wp_enqueue_script( 'home-assistant-commands' );
45 - * } );
46 - * desktop_mode_register_command_script( 'home-assistant-commands' );
44 + * }, 5 ); // Before the shell harvests the payload at priority 10.
45 + * openstation_register_command_script( 'home-assistant-commands' );
47 46 * ```
48 47 *
49 - * The script's JS side calls `wp.desktop.registerCommand( { … } )` as
48 + * The script's JS side calls `wp.os.registerCommand( { … } )` as
50 49 * usual. When a user installs or activates the plugin, the chromeless
51 - * bridge's `desktop-mode-plugins-changed` payload includes the resolved
50 + * bridge's `os-plugins-changed` payload includes the resolved
52 51 * script URL; the shell's command-sync module injects the script into
53 52 * the shell page and the new commands appear in the palette without a
54 53 * full reload.
55 54 *
56 - * @since 0.15.0
57 - *
58 55 * @param string $handle WP-registered script handle.
59 56 * @return true|WP_Error `true` on success; `WP_Error` on validation failure.
60 57 */
61 -function desktop_mode_register_command_script( $handle ) {
58 +function openstation_register_command_script( $handle ) {
62 59 $handle = (string) $handle;
63 60 if ( '' === $handle ) {
64 - return desktop_mode_registration_error(
65 - 'desktop_mode_missing_handle',
61 + return openstation_registration_error(
62 + 'openstation_missing_handle',
66 63 __( 'Command script registration requires a non-empty script handle.', 'desktop-mode' )
67 64 );
68 65 }
69 66
70 - desktop_mode_desktop_command_script_registry( $handle, true );
67 + openstation_desktop_command_script_registry( $handle, true );
71 68
72 69 /**
73 70 * Fires after a desktop command script handle is registered.
74 71 *
75 - * @since 0.15.0
76 - *
77 72 * @param string $handle The registered script handle.
78 73 */
79 - do_action( 'desktop_mode_command_script_registered', $handle );
74 + do_action( 'openstation_command_script_registered', $handle );
80 75
81 76 return true;
82 77 }
83 78
@@ -82,9 +77,9 @@
82 77 }
83 78
84 79 /**
85 80 * Declare a desktop command server-side. Optional companion to
86 - * `desktop_mode_register_command_script()` for plugins that want metadata
81 + * `openstation_register_command_script()` for plugins that want metadata
87 82 * enumerable without JS execution (REST, future pre-registration, etc.).
88 83 * The command's `run` function still lives JS-side; this function only
89 84 * stores metadata.
90 85 *
@@ -90,9 +85,9 @@
90 85 *
91 86 * Example:
92 87 *
93 88 * ```php
94 - * desktop_mode_register_command( array(
89 + * openstation_register_command( array(
95 90 * 'slug' => 'ha-lights',
96 91 * 'label' => __( 'Home Assistant: Lights', 'home-assistant' ),
97 92 * 'description' => __( 'Toggle smart lights from the palette.', 'home-assistant' ),
98 93 * 'icon' => 'dashicons-lightbulb',
@@ -101,13 +96,11 @@
101 96 * ) );
102 97 * ```
103 98 *
104 99 * Implicitly registers the `script` handle via
105 - * `desktop_mode_register_command_script()` when provided, so plugins using
100 + * `openstation_register_command_script()` when provided, so plugins using
106 101 * this API don't need to call both functions.
107 102 *
108 - * @since 0.15.0
109 - *
110 103 * @param array $args {
111 104 * @type string $slug Slash-command slug (without leading `/`). Required.
112 105 * @type string $label Human-readable label. Required.
113 106 * @type string $description Subtitle shown in the palette. Default empty.
@@ -113,14 +106,14 @@
113 106 * @type string $description Subtitle shown in the palette. Default empty.
114 107 * @type string $icon Dashicons class. Default `dashicons-arrow-right-alt`.
115 108 * @type string $hint Argument hint rendered next to the slug. Default empty.
116 109 * @type string $script WP script handle providing the `run` function.
117 - * Registered via `desktop_mode_register_command_script()`
110 + * Registered via `openstation_register_command_script()`
118 111 * when present. Default empty (advisory registration only).
119 112 * }
120 113 * @return true|WP_Error `true` on success; `WP_Error` on validation failure.
121 114 */
122 -function desktop_mode_register_command( $args = array() ) {
115 +function openstation_register_command( $args = array() ) {
123 116 $defaults = array(
124 117 'slug' => '',
125 118 'label' => '',
126 119 'description' => '',
@@ -127,20 +120,20 @@
127 120 'icon' => 'dashicons-arrow-right-alt',
128 121 'hint' => '',
129 122 'script' => '',
130 123 );
131 - $args = wp_parse_args( $args, $defaults );
124 + $args = wp_parse_args( $args, $defaults );
132 125
133 126 $slug = (string) $args['slug'];
134 127 if ( '' === $slug ) {
135 - return desktop_mode_registration_error(
136 - 'desktop_mode_missing_slug',
128 + return openstation_registration_error(
129 + 'openstation_missing_slug',
137 130 __( 'Command registration requires a non-empty `slug`.', 'desktop-mode' )
138 131 );
139 132 }
140 133 if ( '' === (string) $args['label'] ) {
141 - return desktop_mode_registration_error(
142 - 'desktop_mode_missing_label',
134 + return openstation_registration_error(
135 + 'openstation_missing_label',
143 136 __( 'Command registration requires a non-empty `label`.', 'desktop-mode' ),
144 137 array( 'slug' => $slug )
145 138 );
146 139 }
@@ -152,23 +145,21 @@
152 145 'icon' => (string) $args['icon'],
153 146 'hint' => (string) $args['hint'],
154 147 'script' => (string) $args['script'],
155 148 );
156 - desktop_mode_desktop_command_registry( $slug, $entry );
149 + openstation_desktop_command_registry( $slug, $entry );
157 150
158 151 if ( '' !== $entry['script'] ) {
159 - desktop_mode_desktop_command_script_registry( $entry['script'], true );
152 + openstation_register_command_script( $entry['script'] );
160 153 }
161 154
162 155 /**
163 156 * Fires after a desktop command is successfully registered.
164 157 *
165 - * @since 0.15.0
166 - *
167 158 * @param string $slug The command slug.
168 159 * @param array $entry The stored registry entry.
169 160 */
170 - do_action( 'desktop_mode_command_registered', $slug, $entry );
161 + do_action( 'openstation_command_registered', $slug, $entry );
171 162
172 163 return true;
173 164 }
174 165
@@ -173,12 +164,11 @@
173 164 }
174 165
175 166 /**
176 167 * Internal module-level registry for command script handles declared
177 - * via {@see desktop_mode_register_command_script()}. Accessed by both the
168 + * via {@see openstation_register_command_script()}. Accessed by both the
178 169 * registration API (write) and the payload builder (read).
179 170 *
180 - * @since 0.15.0
181 171 * @internal
182 172 *
183 173 * @param string $handle Script handle to read or write.
184 174 * @param bool|null $value Pass `true` to register; `null` to read only.
@@ -183,9 +173,9 @@
183 173 * @param string $handle Script handle to read or write.
184 174 * @param bool|null $value Pass `true` to register; `null` to read only.
185 175 * @return array|bool When called with no args returns the full store.
186 176 */
187 -function desktop_mode_desktop_command_script_registry( $handle = '', $value = null ) {
177 +function openstation_desktop_command_script_registry( $handle = '', $value = null ) {
188 178 static $store = array();
189 179
190 180 if ( '__flush__' === (string) $handle ) {
191 181 $store = array();
@@ -203,20 +193,17 @@
203 193 /**
204 194 * Flush the command-script registry. Tests call this in `set_up` so
205 195 * a previous test's stale handle doesn't leak into the next test's
206 196 * payload-build assertions. No production caller.
207 - *
208 - * @since 0.18.0
209 197 */
210 -function desktop_mode_flush_desktop_command_script_registry() {
211 - desktop_mode_desktop_command_script_registry( '__flush__' );
198 +function openstation_flush_desktop_command_script_registry() {
199 + openstation_desktop_command_script_registry( '__flush__' );
212 200 }
213 201
214 202 /**
215 203 * Internal module-level registry for commands declared via
216 - * {@see desktop_mode_register_command()}.
204 + * {@see openstation_register_command()}.
217 205 *
218 - * @since 0.15.0
219 206 * @internal
220 207 *
221 208 * @param string $slug Slug to read or write.
222 209 * @param array|null $entry Entry to store, or `null` to read.
@@ -221,9 +208,9 @@
221 208 * @param string $slug Slug to read or write.
222 209 * @param array|null $entry Entry to store, or `null` to read.
223 210 * @return array|null
224 211 */
225 -function desktop_mode_desktop_command_registry( $slug = '', $entry = null ) {
212 +function openstation_desktop_command_registry( $slug = '', $entry = null ) {
226 213 static $store = array();
227 214
228 215 if ( '' === (string) $slug ) {
229 216 return $store;
@@ -235,9 +222,9 @@
235 222 }
236 223
237 224 /**
238 225 * Build the script-handle payload fed to the shell. Resolves each
239 - * registered handle to a full payload via {@see desktop_mode_resolve_script_payload()};
226 + * registered handle to a full payload via {@see openstation_resolve_script_payload()};
240 227 * handles that aren't currently enqueued (plugin not active this request)
241 228 * resolve to an empty URL and are dropped. The harvested `extra` data
242 229 * (localize / inline / translations) ships alongside the URL so the
243 230 * shell's lazy `<script>` injection doesn't drop it the way a bare
@@ -242,14 +229,12 @@
242 229 * (localize / inline / translations) ships alongside the URL so the
243 230 * shell's lazy `<script>` injection doesn't drop it the way a bare
244 231 * `<script src="…">` append would.
245 232 *
246 - * @since 0.15.0
247 - *
248 233 * @return array[] List of `{ handle, scriptUrl, scriptBefore, scriptAfter, scriptL10n, scriptTranslations }` entries.
249 234 */
250 -function desktop_mode_build_desktop_command_scripts_payload() {
251 - $registry = desktop_mode_desktop_command_script_registry();
235 +function openstation_build_desktop_command_scripts_payload() {
236 + $registry = openstation_desktop_command_script_registry();
252 237 if ( ! is_array( $registry ) || empty( $registry ) ) {
253 238 return array();
254 239 }
255 240
@@ -258,18 +243,18 @@
258 243 foreach ( $registry as $handle => $active ) {
259 244 if ( ! $active || isset( $seen[ $handle ] ) ) {
260 245 continue;
261 246 }
262 - $payload = desktop_mode_resolve_script_payload( $handle );
247 + $payload = openstation_resolve_script_payload( $handle );
263 248 if ( '' === $payload['url'] ) {
264 - desktop_mode_warn_unresolvable_script_handle(
265 - 'desktop_mode_register_command_script',
249 + openstation_warn_unresolvable_script_handle(
250 + 'openstation_register_command_script',
266 251 'Command',
267 252 (string) $handle
268 253 );
269 254 continue;
270 255 }
271 - $out[] = array(
256 + $out[] = array(
272 257 'handle' => (string) $handle,
273 258 'scriptUrl' => $payload['url'],
274 259 'scriptBefore' => $payload['before'],
275 260 'scriptAfter' => $payload['after'],
@@ -274,8 +259,11 @@
274 259 'scriptBefore' => $payload['before'],
275 260 'scriptAfter' => $payload['after'],
276 261 'scriptL10n' => $payload['l10n'],
277 262 'scriptTranslations' => $payload['translations'],
263 + // The handle's dependency closure, replayed before the bundle
264 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
265 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
278 266 );
279 267 $seen[ $handle ] = true;
280 268 }
281 269 return $out;
@@ -282,19 +270,17 @@
282 270 }
283 271
284 272 /**
285 273 * Build the metadata payload for commands declared via
286 - * {@see desktop_mode_register_command()}. Each entry carries the resolved
274 + * {@see openstation_register_command()}. Each entry carries the resolved
287 275 * `scriptUrl` alongside metadata so the shell's sync knows which script
288 276 * contributed it — enables future pre-registration shims without a round
289 277 * trip.
290 278 *
291 - * @since 0.15.0
292 - *
293 279 * @return array[]
294 280 */
295 -function desktop_mode_build_desktop_commands_payload() {
296 - $registry = desktop_mode_desktop_command_registry();
281 +function openstation_build_desktop_commands_payload() {
282 + $registry = openstation_desktop_command_registry();
297 283 if ( ! is_array( $registry ) || empty( $registry ) ) {
298 284 return array();
299 285 }
300 286
@@ -301,9 +287,9 @@
301 287 $out = array();
302 288 foreach ( $registry as $entry ) {
303 289 $handle = (string) $entry['script'];
304 290 $payload = '' !== $handle
305 - ? desktop_mode_resolve_script_payload( $handle )
291 + ? openstation_resolve_script_payload( $handle )
306 292 : array(
307 293 'url' => '',
308 294 'before' => array(),
309 295 'after' => array(),
@@ -309,20 +295,23 @@
309 295 'after' => array(),
310 296 'l10n' => array(),
311 297 'translations' => '',
312 298 );
313 - $out[] = array(
314 - 'slug' => (string) $entry['slug'],
315 - 'label' => (string) $entry['label'],
316 - 'description' => (string) $entry['description'],
317 - 'icon' => (string) $entry['icon'],
318 - 'hint' => (string) $entry['hint'],
319 - 'scriptUrl' => $payload['url'],
320 - 'scriptHandle' => $handle,
321 - 'scriptBefore' => $payload['before'],
322 - 'scriptAfter' => $payload['after'],
323 - 'scriptL10n' => $payload['l10n'],
299 + $out[] = array(
300 + 'slug' => (string) $entry['slug'],
301 + 'label' => (string) $entry['label'],
302 + 'description' => (string) $entry['description'],
303 + 'icon' => (string) $entry['icon'],
304 + 'hint' => (string) $entry['hint'],
305 + 'scriptUrl' => $payload['url'],
306 + 'scriptHandle' => $handle,
307 + 'scriptBefore' => $payload['before'],
308 + 'scriptAfter' => $payload['after'],
309 + 'scriptL10n' => $payload['l10n'],
324 310 'scriptTranslations' => $payload['translations'],
311 + // The handle's dependency closure, replayed before the bundle
312 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
313 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
325 314 );
326 315 }
327 316 return $out;
328 317 }