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