PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.12
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.12
1.1.12 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 All 36 releases
← All changes | includes/registries/icons.php +50 -3 1.0.1 → 1.1.12 View file →
@@ -8,8 +8,12 @@
8 8 * sit on the desktop wallpaper itself, registered via
9 9 * `openstation_register_icon()` and rendered by
10 10 * `src/desktop-icons.ts`.
11 11 *
12 + * Not to be confused with `includes/wp-icon-registry.php`, which hands our
13 + * eleven pieces of artwork to WordPress's own icon registry for use with
14 + * `wp_get_icon()`. This file is about a surface of the desktop.
15 + *
12 16 * Extracted from the 2,101-LOC `components.php` during the
13 17 * architecture-0.8.1 PHP slicing (phase 6). Behaviour is
14 18 * unchanged: every function name, every WP filter, every error
15 19 * code is identical. PHP looks function references up by name at
@@ -255,8 +259,48 @@
255 259 openstation_desktop_icon_registry( $id, '__unset__' );
256 260 }
257 261
258 262 /**
263 + * One desktop icon entry, as the shell sees it: after the `openstation_icons`
264 + * filter, not from the raw registry.
265 + *
266 + * The payload and the orphan placement both run the filter, so an entry a
267 + * plugin injects there gets a placement row minted for it; the shortcut that
268 + * row points at has to resolve through the same filter or it serializes as
269 + * a missing file and never paints. The same holds the other way: an entry
270 + * the filter removes must not keep resolving from the raw store.
271 + *
272 + * Deliberately uncached here: registrations can change within a request
273 + * (tests do it constantly). Each call runs the whole filter chain, so a
274 + * caller that asks about one icon several times keeps the answer, as
275 + * `OpenStation_Shortcut_File` does for the life of one placement.
276 + *
277 + * @param string $id Icon id.
278 + * @return array|null The entry, or null when no icon has that id.
279 + */
280 +function openstation_desktop_icon_entry( $id ) {
281 + $id = (string) $id;
282 + if ( '' === $id ) {
283 + return null;
284 + }
285 + /** This filter is documented in openstation_build_desktop_icons_payload(). */
286 + $registry = apply_filters( 'openstation_icons', openstation_desktop_icon_registry() );
287 + if ( ! is_array( $registry ) ) {
288 + return null;
289 + }
290 + if ( isset( $registry[ $id ] ) && is_array( $registry[ $id ] ) ) {
291 + return $registry[ $id ];
292 + }
293 + // A filter may hand back a re-indexed list rather than an id map.
294 + foreach ( $registry as $entry ) {
295 + if ( is_array( $entry ) && isset( $entry['id'] ) && $id === (string) $entry['id'] ) {
296 + return $entry;
297 + }
298 + }
299 + return null;
300 +}
301 +
302 +/**
259 303 * Build the desktop-icon list for the shell payload. Applies a
260 304 * `openstation_icons` filter so plugins can hide / reorder / rename
261 305 * entries registered by others — mirrors the wallpaper payload
262 306 * builder's filter discipline.
@@ -264,10 +308,10 @@
264 308 * @return array[]
265 309 */
266 310 function openstation_build_desktop_icons_payload() {
267 311 $registry = openstation_desktop_icon_registry();
268 - if ( ! is_array( $registry ) || empty( $registry ) ) {
269 - return array();
312 + if ( ! is_array( $registry ) ) {
313 + $registry = array();
270 314 }
271 315
272 316 /**
273 317 * Filters the full desktop-icon registry before it ships to the
@@ -277,9 +321,12 @@
277 321 *
278 322 * @param array[] $registry The registered icon entries.
279 323 */
280 324 $registry = apply_filters( 'openstation_icons', $registry );
281 - if ( ! is_array( $registry ) ) {
325 + // Checked after the filter, not before: an empty registry is exactly
326 + // where a filter-injected entry is the only icon, and returning early
327 + // dropped it.
328 + if ( ! is_array( $registry ) || empty( $registry ) ) {
282 329 return array();
283 330 }
284 331
285 332 $out = array();