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/desktop-files/openers.php +48 -54 0.9.21.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — file-opener registry.
3 + * OpenStation — file-opener registry.
4 4 *
5 5 * An "opener" is the equivalent of a default-app association in a
6 6 * desktop OS: it answers the question "what should happen when the
7 7 * user double-clicks a `post` file?" with a discrete choice — open
@@ -23,25 +23,31 @@
23 23 * registration surface and ships a `handler` field with the
24 24 * actual logic; the PHP entry feeds the OS Settings UI and
25 25 * validates user-meta choices against the known set.
26 26 *
27 - * @package WPDesktopMode
28 - * @since 0.9.0
27 + * @package OpenStation
29 28 */
30 29
31 30 defined( 'ABSPATH' ) || exit;
32 31
33 -/** User-meta key holding `{ type => opener_id, … }`. */
34 -define( 'DESKTOP_MODE_FILE_ASSOCIATIONS_META', 'desktop_mode_file_associations' );
32 +/**
33 + * User-meta key holding `{ type => opener_id, … }`.
34 + *
35 + * The VALUE keeps its pre-rebrand spelling on purpose: it is a
36 + * persisted or externally-visible identifier, so renaming it would
37 + * orphan data already written by live installs (or break a live
38 + * URL). The mismatch between this constant's name and its value is
39 + * deliberate — it is NOT a half-finished rename.
40 + */
41 +define( 'OPENSTATION_FILE_ASSOCIATIONS_META', 'desktop_mode_file_associations' );
35 42
36 43 /**
37 44 * Internal static-store registry. Same pattern as the file-type
38 45 * and wallpaper registries.
39 46 *
40 - * @since 0.9.0
41 47 * @internal
42 48 */
43 -function desktop_mode_file_opener_registry( $id = '', $entry = null ) {
49 +function openstation_file_opener_registry( $id = '', $entry = null ) {
44 50 static $store = array();
45 51
46 52 if ( '' === (string) $id ) {
47 53 return $store;
@@ -54,10 +60,8 @@
54 60
55 61 /**
56 62 * Registers a file-opener.
57 63 *
58 - * @since 0.9.0
59 - *
60 64 * @param string $id Opener id, e.g. `'gutenberg'`. Unique across
61 65 * openers; collisions overwrite (late wins).
62 66 * @param array $args {
63 67 * @type string $label Required. Picker label.
@@ -77,13 +81,13 @@
77 81 * @type string[] $capabilities Gate: ALL caps must match.
78 82 * }
79 83 * @return true|WP_Error
80 84 */
81 -function desktop_mode_register_file_opener( $id, $args = array() ) {
85 +function openstation_register_file_opener( $id, $args = array() ) {
82 86 $id = (string) $id;
83 87 if ( '' === $id ) {
84 - return desktop_mode_registration_error(
85 - 'desktop_mode_missing_id',
88 + return openstation_registration_error(
89 + 'openstation_missing_id',
86 90 __( 'Opener id is required.', 'desktop-mode' )
87 91 );
88 92 }
89 93
@@ -94,27 +98,30 @@
94 98 'sort' => 100,
95 99 'script' => '',
96 100 'capabilities' => array(),
97 101 );
98 - $args = wp_parse_args( $args, $defaults );
102 + $args = wp_parse_args( $args, $defaults );
99 103
100 104 foreach ( (array) $args['capabilities'] as $cap ) {
101 105 if ( ! current_user_can( (string) $cap ) ) {
102 - return desktop_mode_registration_error(
103 - 'desktop_mode_capability_denied',
106 + return openstation_registration_error(
107 + 'openstation_capability_denied',
104 108 sprintf(
105 109 /* translators: %s: capability slug. */
106 110 __( 'Current user lacks the %s capability required to register this opener.', 'desktop-mode' ),
107 111 (string) $cap
108 112 ),
109 - array( 'capability' => (string) $cap, 'id' => $id )
113 + array(
114 + 'capability' => (string) $cap,
115 + 'id' => $id,
116 + )
110 117 );
111 118 }
112 119 }
113 120
114 121 if ( '' === (string) $args['label'] ) {
115 - return desktop_mode_registration_error(
116 - 'desktop_mode_missing_label',
122 + return openstation_registration_error(
123 + 'openstation_missing_label',
117 124 __( 'Opener registration requires a non-empty `label`.', 'desktop-mode' ),
118 125 array( 'id' => $id )
119 126 );
120 127 }
@@ -120,10 +127,10 @@
120 127 }
121 128
122 129 $types = array_values( array_filter( array_map( 'strval', (array) $args['types'] ) ) );
123 130 if ( empty( $types ) ) {
124 - return desktop_mode_registration_error(
125 - 'desktop_mode_missing_types',
131 + return openstation_registration_error(
132 + 'openstation_missing_types',
126 133 __( 'Opener registration requires at least one file `type`.', 'desktop-mode' ),
127 134 array( 'id' => $id )
128 135 );
129 136 }
@@ -135,20 +142,18 @@
135 142 'is_default' => (bool) $args['is_default'],
136 143 'sort' => (int) $args['sort'],
137 144 'script' => (string) $args['script'],
138 145 );
139 - desktop_mode_file_opener_registry( $id, $entry );
146 + openstation_file_opener_registry( $id, $entry );
140 147
141 148 /**
142 149 * Fires after a file opener is successfully registered. Does
143 150 * NOT fire on `WP_Error` returns.
144 151 *
145 - * @since 0.9.0
146 - *
147 152 * @param string $id Opener id.
148 153 * @param array $entry Stored registry entry.
149 154 */
150 - do_action( 'desktop_mode_file_opener_registered', $id, $entry );
155 + do_action( 'openstation_file_opener_registered', $id, $entry );
151 156
152 157 return true;
153 158 }
154 159
@@ -154,14 +159,12 @@
154 159
155 160 /**
156 161 * Returns every registered opener, sorted by `sort` then label.
157 162 *
158 - * @since 0.9.0
159 - *
160 163 * @return array[]
161 164 */
162 -function desktop_mode_get_file_openers() {
163 - $registry = desktop_mode_file_opener_registry();
165 +function openstation_get_file_openers() {
166 + $registry = openstation_file_opener_registry();
164 167 if ( ! is_array( $registry ) || empty( $registry ) ) {
165 168 return array();
166 169 }
167 170
@@ -168,13 +171,11 @@
168 171 /**
169 172 * Filters the opener registry before consumers see it. Plugins
170 173 * can hide built-ins, swap labels, or rearrange sort order.
171 174 *
172 - * @since 0.9.0
173 - *
174 175 * @param array[] $registry Registered openers keyed by id.
175 176 */
176 - $registry = apply_filters( 'desktop_mode_file_openers', $registry );
177 + $registry = apply_filters( 'openstation_file_openers', $registry );
177 178 if ( ! is_array( $registry ) ) {
178 179 return array();
179 180 }
180 181
@@ -198,14 +199,12 @@
198 199
199 200 /**
200 201 * Returns openers that handle a given file type.
201 202 *
202 - * @since 0.9.0
203 - *
204 203 * @param string $type File-type slug.
205 204 * @return array[]
206 205 */
207 -function desktop_mode_get_file_openers_for_type( $type ) {
206 +function openstation_get_file_openers_for_type( $type ) {
208 207 $type = (string) $type;
209 208 if ( '' === $type ) {
210 209 return array();
211 210 }
@@ -210,9 +209,9 @@
210 209 return array();
211 210 }
212 211 return array_values(
213 212 array_filter(
214 - desktop_mode_get_file_openers(),
213 + openstation_get_file_openers(),
215 214 static function ( $entry ) use ( $type ) {
216 215 return in_array( $type, (array) $entry['types'], true );
217 216 }
218 217 )
@@ -228,16 +227,14 @@
228 227 * 1. User-meta override (per type).
229 228 * 2. `is_default` opener for the type.
230 229 * 3. First opener for the type (already sort-ordered).
231 230 *
232 - * @since 0.9.0
233 - *
234 231 * @param string $type File-type slug.
235 232 * @param int $user_id Viewer.
236 233 * @return string Opener id, or empty string when nothing matches.
237 234 */
238 -function desktop_mode_resolve_file_opener_id( $type, $user_id ) {
239 - $candidates = desktop_mode_get_file_openers_for_type( $type );
235 +function openstation_resolve_file_opener_id( $type, $user_id ) {
236 + $candidates = openstation_get_file_openers_for_type( $type );
240 237 if ( empty( $candidates ) ) {
241 238 return '';
242 239 }
243 240 $by_id = array();
@@ -247,9 +244,9 @@
247 244
248 245 // 1. User override.
249 246 $override = '';
250 247 if ( $user_id > 0 ) {
251 - $assoc = get_user_meta( (int) $user_id, DESKTOP_MODE_FILE_ASSOCIATIONS_META, true );
248 + $assoc = get_user_meta( (int) $user_id, OPENSTATION_FILE_ASSOCIATIONS_META, true );
252 249 if ( is_array( $assoc ) && isset( $assoc[ $type ] ) ) {
253 250 $override = (string) $assoc[ $type ];
254 251 }
255 252 }
@@ -275,26 +272,22 @@
275 272 * tuple. Plugins can override the user's choice — useful for
276 273 * role-based forced associations or for AB-testing a new
277 274 * editor before promoting it to default.
278 275 *
279 - * @since 0.9.0
280 - *
281 276 * @param string $resolved Resolved opener id.
282 277 * @param string $type File-type slug.
283 278 * @param int $user_id Viewer.
284 279 */
285 - return (string) apply_filters( 'desktop_mode_resolve_file_opener', $resolved, $type, $user_id );
280 + return (string) apply_filters( 'openstation_resolve_file_opener', $resolved, $type, $user_id );
286 281 }
287 282
288 283 /**
289 284 * Builds the openers payload sent to the shell.
290 285 *
291 - * @since 0.9.0
292 - *
293 286 * @return array[]
294 287 */
295 -function desktop_mode_build_file_openers_payload() {
296 - $entries = desktop_mode_get_file_openers();
288 +function openstation_build_file_openers_payload() {
289 + $entries = openstation_get_file_openers();
297 290 if ( empty( $entries ) ) {
298 291 return array();
299 292 }
300 293 $out = array();
@@ -300,9 +293,9 @@
300 293 $out = array();
301 294 foreach ( $entries as $entry ) {
302 295 $handle = isset( $entry['script'] ) ? (string) $entry['script'] : '';
303 296 $payload = '' !== $handle
304 - ? desktop_mode_resolve_script_payload( $handle )
297 + ? openstation_resolve_script_payload( $handle )
305 298 : array(
306 299 'url' => '',
307 300 'before' => array(),
308 301 'after' => array(),
@@ -308,9 +301,9 @@
308 301 'after' => array(),
309 302 'l10n' => array(),
310 303 'translations' => '',
311 304 );
312 - $out[] = array(
305 + $out[] = array(
313 306 'id' => (string) $entry['id'],
314 307 'label' => (string) $entry['label'],
315 308 'types' => array_values( (array) $entry['types'] ),
316 309 'isDefault' => (bool) $entry['is_default'],
@@ -320,8 +313,11 @@
320 313 'scriptBefore' => $payload['before'],
321 314 'scriptAfter' => $payload['after'],
322 315 'scriptL10n' => $payload['l10n'],
323 316 'scriptTranslations' => $payload['translations'],
317 + // The handle's dependency closure, replayed before the bundle
318 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
319 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
324 320 );
325 321 }
326 322 return $out;
327 323 }
@@ -332,22 +328,20 @@
332 328 * at unknown ids are dropped from the returned map but kept in
333 329 * meta — a deactivated plugin that comes back later resumes its
334 330 * choice).
335 331 *
336 - * @since 0.9.0
337 - *
338 332 * @param int $user_id Viewer.
339 333 * @return array<string,string>
340 334 */
341 -function desktop_mode_get_user_file_associations( $user_id ) {
335 +function openstation_get_user_file_associations( $user_id ) {
342 336 if ( $user_id <= 0 ) {
343 337 return array();
344 338 }
345 - $raw = get_user_meta( (int) $user_id, DESKTOP_MODE_FILE_ASSOCIATIONS_META, true );
339 + $raw = get_user_meta( (int) $user_id, OPENSTATION_FILE_ASSOCIATIONS_META, true );
346 340 if ( ! is_array( $raw ) ) {
347 341 return array();
348 342 }
349 - $openers = desktop_mode_get_file_openers();
343 + $openers = openstation_get_file_openers();
350 344 $known = array();
351 345 foreach ( $openers as $entry ) {
352 346 $known[ (string) $entry['id'] ] = (array) $entry['types'];
353 347 }