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/registry.php +52 -56 0.9.21.1.10 View file →
@@ -1,17 +1,16 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — file-type registry.
3 + * OpenStation — file-type registry.
4 4 *
5 5 * Maps a file-type slug (`'post'`, `'user'`, `'folder'`, …) to the
6 - * `Desktop_Mode_File` subclass that adapts the underlying entity.
6 + * `OpenStation_File` subclass that adapts the underlying entity.
7 7 * Plugins extend the file system by registering their own subclass
8 - * via {@see desktop_mode_register_file_type()}; the desktop UI then
8 + * via {@see openstation_register_file_type()}; the desktop UI then
9 9 * knows how to render and resolve their entities just like the
10 10 * built-in types.
11 11 *
12 - * @package WPDesktopMode
13 - * @since 0.9.0
12 + * @package OpenStation
14 13 */
15 14
16 15 defined( 'ABSPATH' ) || exit;
17 16
@@ -16,19 +15,18 @@
16 15 defined( 'ABSPATH' ) || exit;
17 16
18 17 /**
19 18 * Internal static-store registry. Mirrors the wallpaper / native-
20 - * window pattern (see `desktop_mode_desktop_wallpaper_registry()`).
19 + * window pattern (see `openstation_desktop_wallpaper_registry()`).
21 20 *
22 - * @since 0.9.0
23 21 * @internal
24 22 *
25 - * @param string $type File-type slug ('' to fetch the full store).
23 + * @param string $type File-type slug ('' to fetch the full store).
26 24 * @param array|null $entry Entry to write, or null to read.
27 25 * @return array|null Full store when `$type` is empty; entry when
28 26 * looking one up; `null` when not found.
29 27 */
30 -function desktop_mode_file_type_registry( $type = '', $entry = null ) {
28 +function openstation_file_type_registry( $type = '', $entry = null ) {
31 29 static $store = array();
32 30
33 31 if ( '' === (string) $type ) {
34 32 return $store;
@@ -41,16 +39,14 @@
41 39
42 40 /**
43 41 * Registers a desktop file type.
44 42 *
45 - * @since 0.9.0
46 - *
47 43 * @param string $type File-type slug, e.g. `'post'`, `'user'`,
48 44 * `'jorvy-quote'`. Must be non-empty and unique.
49 45 * @param array $args {
50 46 * @type string $label Required. Human label for picker UIs.
51 47 * @type string $class Required. Fully-qualified
52 - * `Desktop_Mode_File` subclass name.
48 + * `OpenStation_File` subclass name.
53 49 * @type string $script Optional. Enqueued script handle for the
54 50 * plugin's JS-side definition. The shell
55 51 * dynamically loads the URL on activation
56 52 * so a plugin's file types appear without
@@ -59,13 +55,13 @@
59 55 * @type string[] $capabilities Gate: ALL caps must match.
60 56 * }
61 57 * @return true|WP_Error `true` on success, `WP_Error` otherwise.
62 58 */
63 -function desktop_mode_register_file_type( $type, $args = array() ) {
59 +function openstation_register_file_type( $type, $args = array() ) {
64 60 $type = (string) $type;
65 61 if ( '' === $type ) {
66 - return desktop_mode_registration_error(
67 - 'desktop_mode_missing_id',
62 + return openstation_registration_error(
63 + 'openstation_missing_id',
68 64 __( 'File-type slug is required.', 'desktop-mode' )
69 65 );
70 66 }
71 67
@@ -75,27 +71,30 @@
75 71 'script' => '',
76 72 'sort' => 100,
77 73 'capabilities' => array(),
78 74 );
79 - $args = wp_parse_args( $args, $defaults );
75 + $args = wp_parse_args( $args, $defaults );
80 76
81 77 foreach ( (array) $args['capabilities'] as $cap ) {
82 78 if ( ! current_user_can( (string) $cap ) ) {
83 - return desktop_mode_registration_error(
84 - 'desktop_mode_capability_denied',
79 + return openstation_registration_error(
80 + 'openstation_capability_denied',
85 81 sprintf(
86 82 /* translators: %s: capability slug. */
87 83 __( 'Current user lacks the %s capability required to register this file type.', 'desktop-mode' ),
88 84 (string) $cap
89 85 ),
90 - array( 'capability' => (string) $cap, 'type' => $type )
86 + array(
87 + 'capability' => (string) $cap,
88 + 'type' => $type,
89 + )
91 90 );
92 91 }
93 92 }
94 93
95 94 if ( '' === (string) $args['label'] ) {
96 - return desktop_mode_registration_error(
97 - 'desktop_mode_missing_label',
95 + return openstation_registration_error(
96 + 'openstation_missing_label',
98 97 __( 'File-type registration requires a non-empty `label`.', 'desktop-mode' ),
99 98 array( 'type' => $type )
100 99 );
101 100 }
@@ -101,19 +100,25 @@
101 100 }
102 101
103 102 $class = (string) $args['class'];
104 103 if ( '' === $class || ! class_exists( $class ) ) {
105 - return desktop_mode_registration_error(
106 - 'desktop_mode_invalid_class',
104 + return openstation_registration_error(
105 + 'openstation_invalid_class',
107 106 __( 'File-type registration requires an existing `class`.', 'desktop-mode' ),
108 - array( 'type' => $type, 'class' => $class )
107 + array(
108 + 'type' => $type,
109 + 'class' => $class,
110 + )
109 111 );
110 112 }
111 - if ( ! is_subclass_of( $class, 'Desktop_Mode_File' ) ) {
112 - return desktop_mode_registration_error(
113 - 'desktop_mode_invalid_class',
114 - __( '`class` must extend `Desktop_Mode_File`.', 'desktop-mode' ),
115 - array( 'type' => $type, 'class' => $class )
113 + if ( ! is_subclass_of( $class, 'OpenStation_File' ) ) {
114 + return openstation_registration_error(
115 + 'openstation_invalid_class',
116 + __( '`class` must extend `OpenStation_File`.', 'desktop-mode' ),
117 + array(
118 + 'type' => $type,
119 + 'class' => $class,
120 + )
116 121 );
117 122 }
118 123
119 124 $entry = array(
@@ -122,20 +127,18 @@
122 127 'class' => $class,
123 128 'script' => (string) $args['script'],
124 129 'sort' => (int) $args['sort'],
125 130 );
126 - desktop_mode_file_type_registry( $type, $entry );
131 + openstation_file_type_registry( $type, $entry );
127 132
128 133 /**
129 134 * Fires after a desktop file type is successfully registered.
130 135 * Does NOT fire on `WP_Error` returns.
131 136 *
132 - * @since 0.9.0
133 - *
134 137 * @param string $type Type slug.
135 138 * @param array $entry Stored registry entry.
136 139 */
137 - do_action( 'desktop_mode_file_type_registered', $type, $entry );
140 + do_action( 'openstation_file_type_registered', $type, $entry );
138 141
139 142 return true;
140 143 }
141 144
@@ -141,15 +144,13 @@
141 144
142 145 /**
143 146 * Looks up a registered file-type entry.
144 147 *
145 - * @since 0.9.0
146 - *
147 148 * @param string $type Type slug.
148 149 * @return array|null Registry entry, or `null` if unknown.
149 150 */
150 -function desktop_mode_get_file_type( $type ) {
151 - $entry = desktop_mode_file_type_registry( (string) $type );
151 +function openstation_get_file_type( $type ) {
152 + $entry = openstation_file_type_registry( (string) $type );
152 153 return is_array( $entry ) ? $entry : null;
153 154 }
154 155
155 156 /**
@@ -154,14 +155,12 @@
154 155
155 156 /**
156 157 * Returns every registered file type, sorted by `sort` then label.
157 158 *
158 - * @since 0.9.0
159 - *
160 159 * @return array[]
161 160 */
162 -function desktop_mode_get_file_types() {
163 - $registry = desktop_mode_file_type_registry();
161 +function openstation_get_file_types() {
162 + $registry = openstation_file_type_registry();
164 163 if ( ! is_array( $registry ) || empty( $registry ) ) {
165 164 return array();
166 165 }
167 166
@@ -168,13 +167,11 @@
168 167 /**
169 168 * Filters the full file-type registry before consumers see it.
170 169 * Plugins can hide built-in types or swap a class out at runtime.
171 170 *
172 - * @since 0.9.0
173 - *
174 171 * @param array[] $registry Registered entries keyed by slug.
175 172 */
176 - $registry = apply_filters( 'desktop_mode_file_types', $registry );
173 + $registry = apply_filters( 'openstation_file_types', $registry );
177 174 if ( ! is_array( $registry ) ) {
178 175 return array();
179 176 }
180 177
@@ -195,19 +192,17 @@
195 192 return $entries;
196 193 }
197 194
198 195 /**
199 - * Resolves a `(type, ref)` tuple into a `Desktop_Mode_File` instance,
196 + * Resolves a `(type, ref)` tuple into a `OpenStation_File` instance,
200 197 * or `null` if the type is unknown.
201 198 *
202 - * @since 0.9.0
203 - *
204 199 * @param string $type File-type slug.
205 200 * @param string|int $ref Entity reference.
206 - * @return Desktop_Mode_File|null
201 + * @return OpenStation_File|null
207 202 */
208 -function desktop_mode_resolve_file( $type, $ref ) {
209 - $entry = desktop_mode_get_file_type( $type );
203 +function openstation_resolve_file( $type, $ref ) {
204 + $entry = openstation_get_file_type( $type );
210 205 if ( null === $entry ) {
211 206 return null;
212 207 }
213 208 $class = $entry['class'];
@@ -221,14 +216,12 @@
221 216 * Builds the file-types payload sent to the shell. Only metadata
222 217 * (id, label, sort) and the resolved script URL cross the wire —
223 218 * the PHP class never serializes; the JS side has its own mirror.
224 219 *
225 - * @since 0.9.0
226 - *
227 220 * @return array[]
228 221 */
229 -function desktop_mode_build_file_types_payload() {
230 - $entries = desktop_mode_get_file_types();
222 +function openstation_build_file_types_payload() {
223 + $entries = openstation_get_file_types();
231 224 if ( empty( $entries ) ) {
232 225 return array();
233 226 }
234 227 $out = array();
@@ -234,9 +227,9 @@
234 227 $out = array();
235 228 foreach ( $entries as $entry ) {
236 229 $handle = isset( $entry['script'] ) ? (string) $entry['script'] : '';
237 230 $payload = '' !== $handle
238 - ? desktop_mode_resolve_script_payload( $handle )
231 + ? openstation_resolve_script_payload( $handle )
239 232 : array(
240 233 'url' => '',
241 234 'before' => array(),
242 235 'after' => array(),
@@ -242,9 +235,9 @@
242 235 'after' => array(),
243 236 'l10n' => array(),
244 237 'translations' => '',
245 238 );
246 - $out[] = array(
239 + $out[] = array(
247 240 'id' => (string) $entry['type'],
248 241 'label' => (string) $entry['label'],
249 242 'sort' => (int) $entry['sort'],
250 243 'scriptUrl' => $payload['url'],
@@ -252,8 +245,11 @@
252 245 'scriptBefore' => $payload['before'],
253 246 'scriptAfter' => $payload['after'],
254 247 'scriptL10n' => $payload['l10n'],
255 248 'scriptTranslations' => $payload['translations'],
249 + // The handle's dependency closure, replayed before the bundle
250 + // on its lazy load — see `openstation_resolve_script_dependencies()`.
251 + 'scriptDeps' => openstation_resolve_script_dependencies( $handle ),
256 252 );
257 253 }
258 254 return $out;
259 255 }