PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.11
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.11
1.1.11 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 All 35 releases
← All changes | includes/desktop-files/openers.php +48 -34 0.9.8 → 1.1.11 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,15 +23,23 @@
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
27 + * @package OpenStation
28 28 */
29 29
30 30 defined( 'ABSPATH' ) || exit;
31 31
32 -/** User-meta key holding `{ type => opener_id, … }`. */
33 -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' );
34 42
35 43 /**
36 44 * Internal static-store registry. Same pattern as the file-type
37 45 * and wallpaper registries.
@@ -37,9 +45,9 @@
37 45 * and wallpaper registries.
38 46 *
39 47 * @internal
40 48 */
41 -function desktop_mode_file_opener_registry( $id = '', $entry = null ) {
49 +function openstation_file_opener_registry( $id = '', $entry = null ) {
42 50 static $store = array();
43 51
44 52 if ( '' === (string) $id ) {
45 53 return $store;
@@ -73,13 +81,13 @@
73 81 * @type string[] $capabilities Gate: ALL caps must match.
74 82 * }
75 83 * @return true|WP_Error
76 84 */
77 -function desktop_mode_register_file_opener( $id, $args = array() ) {
85 +function openstation_register_file_opener( $id, $args = array() ) {
78 86 $id = (string) $id;
79 87 if ( '' === $id ) {
80 - return desktop_mode_registration_error(
81 - 'desktop_mode_missing_id',
88 + return openstation_registration_error(
89 + 'openstation_missing_id',
82 90 __( 'Opener id is required.', 'desktop-mode' )
83 91 );
84 92 }
85 93
@@ -90,27 +98,30 @@
90 98 'sort' => 100,
91 99 'script' => '',
92 100 'capabilities' => array(),
93 101 );
94 - $args = wp_parse_args( $args, $defaults );
102 + $args = wp_parse_args( $args, $defaults );
95 103
96 104 foreach ( (array) $args['capabilities'] as $cap ) {
97 105 if ( ! current_user_can( (string) $cap ) ) {
98 - return desktop_mode_registration_error(
99 - 'desktop_mode_capability_denied',
106 + return openstation_registration_error(
107 + 'openstation_capability_denied',
100 108 sprintf(
101 109 /* translators: %s: capability slug. */
102 110 __( 'Current user lacks the %s capability required to register this opener.', 'desktop-mode' ),
103 111 (string) $cap
104 112 ),
105 - array( 'capability' => (string) $cap, 'id' => $id )
113 + array(
114 + 'capability' => (string) $cap,
115 + 'id' => $id,
116 + )
106 117 );
107 118 }
108 119 }
109 120
110 121 if ( '' === (string) $args['label'] ) {
111 - return desktop_mode_registration_error(
112 - 'desktop_mode_missing_label',
122 + return openstation_registration_error(
123 + 'openstation_missing_label',
113 124 __( 'Opener registration requires a non-empty `label`.', 'desktop-mode' ),
114 125 array( 'id' => $id )
115 126 );
116 127 }
@@ -116,10 +127,10 @@
116 127 }
117 128
118 129 $types = array_values( array_filter( array_map( 'strval', (array) $args['types'] ) ) );
119 130 if ( empty( $types ) ) {
120 - return desktop_mode_registration_error(
121 - 'desktop_mode_missing_types',
131 + return openstation_registration_error(
132 + 'openstation_missing_types',
122 133 __( 'Opener registration requires at least one file `type`.', 'desktop-mode' ),
123 134 array( 'id' => $id )
124 135 );
125 136 }
@@ -131,9 +142,9 @@
131 142 'is_default' => (bool) $args['is_default'],
132 143 'sort' => (int) $args['sort'],
133 144 'script' => (string) $args['script'],
134 145 );
135 - desktop_mode_file_opener_registry( $id, $entry );
146 + openstation_file_opener_registry( $id, $entry );
136 147
137 148 /**
138 149 * Fires after a file opener is successfully registered. Does
139 150 * NOT fire on `WP_Error` returns.
@@ -140,9 +151,9 @@
140 151 *
141 152 * @param string $id Opener id.
142 153 * @param array $entry Stored registry entry.
143 154 */
144 - do_action( 'desktop_mode_file_opener_registered', $id, $entry );
155 + do_action( 'openstation_file_opener_registered', $id, $entry );
145 156
146 157 return true;
147 158 }
148 159
@@ -150,10 +161,10 @@
150 161 * Returns every registered opener, sorted by `sort` then label.
151 162 *
152 163 * @return array[]
153 164 */
154 -function desktop_mode_get_file_openers() {
155 - $registry = desktop_mode_file_opener_registry();
165 +function openstation_get_file_openers() {
166 + $registry = openstation_file_opener_registry();
156 167 if ( ! is_array( $registry ) || empty( $registry ) ) {
157 168 return array();
158 169 }
159 170
@@ -162,9 +173,9 @@
162 173 * can hide built-ins, swap labels, or rearrange sort order.
163 174 *
164 175 * @param array[] $registry Registered openers keyed by id.
165 176 */
166 - $registry = apply_filters( 'desktop_mode_file_openers', $registry );
177 + $registry = apply_filters( 'openstation_file_openers', $registry );
167 178 if ( ! is_array( $registry ) ) {
168 179 return array();
169 180 }
170 181
@@ -191,9 +202,9 @@
191 202 *
192 203 * @param string $type File-type slug.
193 204 * @return array[]
194 205 */
195 -function desktop_mode_get_file_openers_for_type( $type ) {
206 +function openstation_get_file_openers_for_type( $type ) {
196 207 $type = (string) $type;
197 208 if ( '' === $type ) {
198 209 return array();
199 210 }
@@ -198,9 +209,9 @@
198 209 return array();
199 210 }
200 211 return array_values(
201 212 array_filter(
202 - desktop_mode_get_file_openers(),
213 + openstation_get_file_openers(),
203 214 static function ( $entry ) use ( $type ) {
204 215 return in_array( $type, (array) $entry['types'], true );
205 216 }
206 217 )
@@ -220,10 +231,10 @@
220 231 * @param string $type File-type slug.
221 232 * @param int $user_id Viewer.
222 233 * @return string Opener id, or empty string when nothing matches.
223 234 */
224 -function desktop_mode_resolve_file_opener_id( $type, $user_id ) {
225 - $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 );
226 237 if ( empty( $candidates ) ) {
227 238 return '';
228 239 }
229 240 $by_id = array();
@@ -233,9 +244,9 @@
233 244
234 245 // 1. User override.
235 246 $override = '';
236 247 if ( $user_id > 0 ) {
237 - $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 );
238 249 if ( is_array( $assoc ) && isset( $assoc[ $type ] ) ) {
239 250 $override = (string) $assoc[ $type ];
240 251 }
241 252 }
@@ -265,9 +276,9 @@
265 276 * @param string $resolved Resolved opener id.
266 277 * @param string $type File-type slug.
267 278 * @param int $user_id Viewer.
268 279 */
269 - 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 );
270 281 }
271 282
272 283 /**
273 284 * Builds the openers payload sent to the shell.
@@ -273,10 +284,10 @@
273 284 * Builds the openers payload sent to the shell.
274 285 *
275 286 * @return array[]
276 287 */
277 -function desktop_mode_build_file_openers_payload() {
278 - $entries = desktop_mode_get_file_openers();
288 +function openstation_build_file_openers_payload() {
289 + $entries = openstation_get_file_openers();
279 290 if ( empty( $entries ) ) {
280 291 return array();
281 292 }
282 293 $out = array();
@@ -282,9 +293,9 @@
282 293 $out = array();
283 294 foreach ( $entries as $entry ) {
284 295 $handle = isset( $entry['script'] ) ? (string) $entry['script'] : '';
285 296 $payload = '' !== $handle
286 - ? desktop_mode_resolve_script_payload( $handle )
297 + ? openstation_resolve_script_payload( $handle )
287 298 : array(
288 299 'url' => '',
289 300 'before' => array(),
290 301 'after' => array(),
@@ -290,9 +301,9 @@
290 301 'after' => array(),
291 302 'l10n' => array(),
292 303 'translations' => '',
293 304 );
294 - $out[] = array(
305 + $out[] = array(
295 306 'id' => (string) $entry['id'],
296 307 'label' => (string) $entry['label'],
297 308 'types' => array_values( (array) $entry['types'] ),
298 309 'isDefault' => (bool) $entry['is_default'],
@@ -302,8 +313,11 @@
302 313 'scriptBefore' => $payload['before'],
303 314 'scriptAfter' => $payload['after'],
304 315 'scriptL10n' => $payload['l10n'],
305 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 ),
306 320 );
307 321 }
308 322 return $out;
309 323 }
@@ -317,17 +331,17 @@
317 331 *
318 332 * @param int $user_id Viewer.
319 333 * @return array<string,string>
320 334 */
321 -function desktop_mode_get_user_file_associations( $user_id ) {
335 +function openstation_get_user_file_associations( $user_id ) {
322 336 if ( $user_id <= 0 ) {
323 337 return array();
324 338 }
325 - $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 );
326 340 if ( ! is_array( $raw ) ) {
327 341 return array();
328 342 }
329 - $openers = desktop_mode_get_file_openers();
343 + $openers = openstation_get_file_openers();
330 344 $known = array();
331 345 foreach ( $openers as $entry ) {
332 346 $known[ (string) $entry['id'] ] = (array) $entry['types'];
333 347 }