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/registries/wallpapers.php +67 -63 0.9.81.1.10 View file →
@@ -1,11 +1,11 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Wallpapers registry.
3 + * OpenStation — Wallpapers registry.
4 4 *
5 5 * Server-side registration API + payload builder + asset enqueue
6 6 * for the desktop wallpaper picker. Wallpaper definitions live
7 - * on `window.desktopModeWallpapers[ id ]` (set by the plugin's
7 + * on `window.openStationWallpapers[ id ]` (set by the plugin's
8 8 * own JS); this module is the PHP side that announces them to
9 9 * the shell and ships their script handles into the boot
10 10 * payload.
11 11 *
@@ -12,9 +12,9 @@
12 12 * Extracted from `components.php` during the architecture-0.8.1
13 13 * PHP slicing (phase 6). Behaviour, function names, filter
14 14 * contracts, and error codes all unchanged.
15 15 *
16 - * @package Desktop_Mode
16 + * @package OpenStation
17 17 */
18 18
19 19 defined( 'ABSPATH' ) || exit;
20 20
@@ -19,12 +19,12 @@
19 19 defined( 'ABSPATH' ) || exit;
20 20
21 21 /**
22 22 * Register a server-side desktop wallpaper. Symmetrical to
23 - * {@see desktop_mode_register_widget()}. The plugin's JS side
23 + * {@see openstation_register_widget()}. The plugin's JS side
24 24 * publishes the full `WallpaperDef` (with mount / resolveValue /
25 25 * renderEditor callbacks as appropriate) on
26 - * `window.desktopModeWallpapers[ <id> ]`; the shell loads the
26 + * `window.openStationWallpapers[ <id> ]`; the shell loads the
27 27 * declared script, reads that global, and registers the def via
28 28 * the normal wallpaper registry. Deactivation unregisters the
29 29 * def and re-applies the current selection (which falls back to
30 30 * a built-in if the user's active wallpaper was the one leaving).
@@ -31,9 +31,9 @@
31 31 *
32 32 * Example:
33 33 *
34 34 * ```php
35 - * desktop_mode_register_wallpaper( 'myplugin/snow', array(
35 + * openstation_register_wallpaper( 'myplugin/snow', array(
36 36 * 'label' => __( 'Snow', 'my-plugin' ),
37 37 * 'preview' => 'linear-gradient(#fff, #ddd)',
38 38 * 'type' => 'canvas',
39 39 * 'script' => 'my-plugin-snow-wallpaper',
@@ -41,10 +41,10 @@
41 41 * ```
42 42 *
43 43 * ```js
44 44 * // Inside my-plugin-snow-wallpaper.js
45 - * window.desktopModeWallpapers = window.desktopModeWallpapers || {};
46 - * window.desktopModeWallpapers[ 'myplugin/snow' ] = {
45 + * window.openStationWallpapers = window.openStationWallpapers || {};
46 + * window.openStationWallpapers[ 'myplugin/snow' ] = {
47 47 * id: 'myplugin/snow',
48 48 * label: 'Snow',
49 49 * type: 'canvas',
50 50 * preview: 'linear-gradient(#fff, #ddd)',
@@ -53,9 +53,9 @@
53 53 * };
54 54 * ```
55 55 *
56 56 * @param string $id Wallpaper id. For canvas wallpapers this must
57 - * match the `window.desktopModeWallpapers[<id>]`
57 + * match the `window.openStationWallpapers[<id>]`
58 58 * key the plugin's JS publishes.
59 59 * @param array $args {
60 60 * @type string $label Picker label. Required.
61 61 * @type string $preview CSS value rendered in the picker
@@ -79,17 +79,17 @@
79 79 * its data comes from, the story behind
80 80 * it. Optional.
81 81 * @type string[] $capabilities Gate: ALL caps must match. Any
82 82 * missed cap returns
83 - * `WP_Error desktop_mode_capability_denied`.
83 + * `WP_Error openstation_capability_denied`.
84 84 * }
85 85 * @return true|WP_Error `true` on success; `WP_Error` otherwise.
86 86 */
87 -function desktop_mode_register_wallpaper( $id, $args = array() ) {
87 +function openstation_register_wallpaper( $id, $args = array() ) {
88 88 $id = (string) $id;
89 89 if ( '' === $id ) {
90 - return desktop_mode_registration_error(
91 - 'desktop_mode_missing_id',
90 + return openstation_registration_error(
91 + 'openstation_missing_id',
92 92 __( 'Wallpaper id is required.', 'desktop-mode' )
93 93 );
94 94 }
95 95
@@ -101,26 +101,29 @@
101 101 'script' => '',
102 102 'description' => '',
103 103 'capabilities' => array(),
104 104 );
105 - $args = wp_parse_args( $args, $defaults );
105 + $args = wp_parse_args( $args, $defaults );
106 106
107 107 foreach ( (array) $args['capabilities'] as $cap ) {
108 108 if ( ! current_user_can( (string) $cap ) ) {
109 - return desktop_mode_registration_error(
110 - 'desktop_mode_capability_denied',
109 + return openstation_registration_error(
110 + 'openstation_capability_denied',
111 111 sprintf(
112 112 /* translators: %s: capability slug. */
113 113 __( 'Current user lacks the %s capability required to register this wallpaper.', 'desktop-mode' ),
114 114 (string) $cap
115 115 ),
116 - array( 'capability' => (string) $cap, 'id' => $id )
116 + array(
117 + 'capability' => (string) $cap,
118 + 'id' => $id,
119 + )
117 120 );
118 121 }
119 122 }
120 123 if ( '' === (string) $args['label'] ) {
121 - return desktop_mode_registration_error(
122 - 'desktop_mode_missing_label',
124 + return openstation_registration_error(
125 + 'openstation_missing_label',
123 126 __( 'Wallpaper registration requires a non-empty `label`.', 'desktop-mode' ),
124 127 array( 'id' => $id )
125 128 );
126 129 }
@@ -131,10 +134,10 @@
131 134 // `mount` callback is published on the JS global by that
132 135 // script). CSS wallpapers can skip the script — the shell can
133 136 // render from the `value` / `preview` string alone.
134 137 if ( 'canvas' === $type && '' === (string) $args['script'] ) {
135 - return desktop_mode_registration_error(
136 - 'desktop_mode_missing_script',
138 + return openstation_registration_error(
139 + 'openstation_missing_script',
137 140 __( 'Canvas wallpaper registration requires a `script` handle that publishes the def.', 'desktop-mode' ),
138 141 array( 'id' => $id )
139 142 );
140 143 }
@@ -168,20 +171,20 @@
168 171 // Plain text by contract — the shell renders it as text, never
169 172 // as HTML, so strip tags here rather than trusting every caller.
170 173 'description' => sanitize_textarea_field( (string) $args['description'] ),
171 174 );
172 - desktop_mode_desktop_wallpaper_registry( $id, $entry );
175 + openstation_desktop_wallpaper_registry( $id, $entry );
173 176
174 177 /**
175 178 * Fires after a desktop wallpaper is successfully registered.
176 179 *
177 - * Does NOT fire when `desktop_mode_register_wallpaper()` returns a
180 + * Does NOT fire when `openstation_register_wallpaper()` returns a
178 181 * `WP_Error`.
179 182 *
180 183 * @param string $id The wallpaper id.
181 184 * @param array $entry The stored registry entry.
182 185 */
183 - do_action( 'desktop_mode_wallpaper_registered', $id, $entry );
186 + do_action( 'openstation_wallpaper_registered', $id, $entry );
184 187
185 188 return true;
186 189 }
187 190
@@ -186,14 +189,14 @@
186 189 }
187 190
188 191 /**
189 192 * Internal module-level registry for wallpapers registered via
190 - * {@see desktop_mode_register_wallpaper()}. Same static-store
193 + * {@see openstation_register_wallpaper()}. Same static-store
191 194 * pattern as the widget + native-window registries.
192 195 *
193 196 * @internal
194 197 */
195 -function desktop_mode_desktop_wallpaper_registry( $id = '', $entry = null ) {
198 +function openstation_desktop_wallpaper_registry( $id = '', $entry = null ) {
196 199 static $store = array();
197 200
198 201 if ( '' === (string) $id ) {
199 202 return $store;
@@ -210,22 +213,22 @@
210 213 * callback is announced via the JS global the script sets up.
211 214 *
212 215 * @return array[]
213 216 */
214 -function desktop_mode_build_desktop_wallpapers_payload() {
215 - $registry = desktop_mode_desktop_wallpaper_registry();
217 +function openstation_build_desktop_wallpapers_payload() {
218 + $registry = openstation_desktop_wallpaper_registry();
216 219 if ( ! is_array( $registry ) || empty( $registry ) ) {
217 220 return array();
218 221 }
219 222 /**
220 223 * Filters the server-declared wallpaper list before it ships to
221 - * the shell. Mirrors the JS-side `desktop-mode.wallpapers` filter
224 + * the shell. Mirrors the JS-side `os.wallpapers` filter
222 225 * so plugins can rearrange, hide, or override entries at boot
223 226 * without round-tripping through the JS registry.
224 227 *
225 228 * @param array[] $registry The registered wallpaper entries.
226 229 */
227 - $registry = apply_filters( 'desktop_mode_wallpapers', $registry );
230 + $registry = apply_filters( 'openstation_wallpapers', $registry );
228 231 if ( ! is_array( $registry ) ) {
229 232 return array();
230 233 }
231 234 $out = array();
@@ -233,22 +236,25 @@
233 236 if ( ! is_array( $entry ) || empty( $entry['id'] ) ) {
234 237 continue;
235 238 }
236 239 $handle = isset( $entry['script'] ) ? (string) $entry['script'] : '';
237 - $payload = desktop_mode_resolve_script_payload( $handle );
238 - $out[] = array(
239 - 'id' => (string) $entry['id'],
240 - 'label' => isset( $entry['label'] ) ? (string) $entry['label'] : '',
241 - 'preview' => isset( $entry['preview'] ) ? (string) $entry['preview'] : '',
242 - 'type' => isset( $entry['type'] ) ? (string) $entry['type'] : 'canvas',
243 - 'value' => isset( $entry['value'] ) ? (string) $entry['value'] : '',
244 - 'description' => isset( $entry['description'] ) ? (string) $entry['description'] : '',
245 - 'scriptUrl' => $payload['url'],
246 - 'scriptHandle' => $handle,
247 - 'scriptBefore' => $payload['before'],
248 - 'scriptAfter' => $payload['after'],
249 - 'scriptL10n' => $payload['l10n'],
240 + $payload = openstation_resolve_script_payload( $handle );
241 + $out[] = array(
242 + 'id' => (string) $entry['id'],
243 + 'label' => isset( $entry['label'] ) ? (string) $entry['label'] : '',
244 + 'preview' => isset( $entry['preview'] ) ? (string) $entry['preview'] : '',
245 + 'type' => isset( $entry['type'] ) ? (string) $entry['type'] : 'canvas',
246 + 'value' => isset( $entry['value'] ) ? (string) $entry['value'] : '',
247 + 'description' => isset( $entry['description'] ) ? (string) $entry['description'] : '',
248 + 'scriptUrl' => $payload['url'],
249 + 'scriptHandle' => $handle,
250 + 'scriptBefore' => $payload['before'],
251 + 'scriptAfter' => $payload['after'],
252 + 'scriptL10n' => $payload['l10n'],
250 253 'scriptTranslations' => $payload['translations'],
254 + // The handle's dependency closure, replayed before the bundle
255 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
256 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
251 257 );
252 258 }
253 259 return $out;
254 260 }
@@ -253,25 +259,23 @@
253 259 return $out;
254 260 }
255 261
256 262
257 -/**
258 - * Enqueue plugin-registered wallpaper scripts on the shell page
259 - * so wallpapers active at boot time have their defs available
260 - * without any dynamic-load roundtrip.
263 +/*
264 + * Wallpaper scripts are NOT enqueued here, and that is deliberate.
265 + *
266 + * A canvas wallpaper's bundle IS the wallpaper — Living Tree is 58 KB
267 + * of PixiJS scene, Snow is 42 KB — and this file used to
268 + * `wp_enqueue_script()` every registered one on every admin page, so
269 + * that every user downloaded and parsed every wallpaper in the
270 + * install including the ones they were not wearing. The metadata in
271 + * the boot payload (label, preview swatch, description) is enough for
272 + * the shell to register a stub and paint a picker tile without any of
273 + * it.
274 + *
275 + * The bundle arrives when something needs the callbacks: the shell
276 + * hydrates the user's ACTIVE wallpaper during the boot sync, and the
277 + * wallpaper picker hydrates the rest when it opens. See
278 + * `src/wallpapers/lazy.ts`. `scriptUrl` in the payload (built above)
279 + * is what makes that possible; nothing else on the PHP side is
280 + * involved.
261 281 */
262 -function desktop_mode_enqueue_desktop_wallpaper_scripts() {
263 - if ( ! desktop_mode_is_enabled() || desktop_mode_is_chromeless_request() || desktop_mode_is_classic_request() ) {
264 - return;
265 - }
266 - $registry = desktop_mode_desktop_wallpaper_registry();
267 - if ( ! is_array( $registry ) ) {
268 - return;
269 - }
270 - foreach ( $registry as $entry ) {
271 - if ( ! empty( $entry['script'] ) ) {
272 - wp_enqueue_script( $entry['script'] );
273 - }
274 - }
275 -}
276 -add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_desktop_wallpaper_scripts', 20 );
277 -