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
desktop-mode / includes / accents.php

accents.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.10, at includes/accents.php

152 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Accent color swatches.
4 *
5 * The OS Settings panel lets users pick an accent color that the shell
6 * applies to `--wp-admin-theme-color` on the parent frame. Themes and
7 * plugins can extend or restrict the swatch list via the
8 * {@see 'openstation_accent_colors'} filter — e.g. a brand theme that
9 * injects its corporate palette, or a compliance plugin that collapses
10 * the list to a single approved value.
11 *
12 * @package OpenStation
13 */
14
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Returns the list of accent-color swatches shown in OS Settings.
19 *
20 * Each entry is an array shaped `{ id, label, value }`:
21 *
22 * - `id` is a stable slug (persisted in `localStorage`).
23 * - `label` is the human-readable name used in the picker tooltip.
24 * - `value` is a hex color applied to `--wp-admin-theme-color`.
25 *
26 * The defaults ship with six WordPress-adjacent swatches. Consumers
27 * mutate the list via the `openstation_accent_colors` filter — entries
28 * whose `value` fails `sanitize_hex_color()` are dropped silently so a
29 * bad filter return can't inject arbitrary CSS into the shell.
30 *
31 * @return array<int, array{id: string, label: string, value: string}>
32 */
33 function openstation_get_accent_colors() {
34 $defaults = array(
35 // The brand accents lead the list: Pulse is the identity
36 // colour and the shipped default, Nebula its softer twin.
37 array(
38 'id' => 'pulse',
39 'label' => __( 'Pulse', 'desktop-mode' ),
40 'value' => '#f252fc',
41 ),
42 array(
43 'id' => 'nebula',
44 'label' => __( 'Nebula', 'desktop-mode' ),
45 'value' => '#ec9bff',
46 ),
47 // The other brand accents. Sirius is the cool counterweight to
48 // Pulse; Lagoon sits between the two families and is what the
49 // guide reaches for when Pulse is too loud and WordPress Blue
50 // too corporate; Starlight is the brand's light, for a station
51 // with no colour at all.
52 array(
53 'id' => 'sirius',
54 'label' => __( 'Sirius', 'desktop-mode' ),
55 'value' => '#9af2ff',
56 ),
57 array(
58 'id' => 'lagoon',
59 'label' => __( 'Lagoon', 'desktop-mode' ),
60 'value' => '#9f98ff',
61 ),
62 array(
63 'id' => 'starlight',
64 'label' => __( 'Starlight', 'desktop-mode' ),
65 'value' => '#fffbff',
66 ),
67 array(
68 'id' => 'wp-blue',
69 'label' => __( 'WordPress Blue', 'desktop-mode' ),
70 'value' => '#2271b1',
71 ),
72 array(
73 'id' => 'indigo',
74 'label' => __( 'Indigo', 'desktop-mode' ),
75 'value' => '#3858e9',
76 ),
77 array(
78 'id' => 'teal',
79 'label' => __( 'Teal', 'desktop-mode' ),
80 'value' => '#04a4cc',
81 ),
82 array(
83 'id' => 'emerald',
84 'label' => __( 'Emerald', 'desktop-mode' ),
85 'value' => '#059669',
86 ),
87 array(
88 'id' => 'amber',
89 'label' => __( 'Amber', 'desktop-mode' ),
90 'value' => '#d97706',
91 ),
92 array(
93 'id' => 'rose',
94 'label' => __( 'Rose', 'desktop-mode' ),
95 'value' => '#e11d48',
96 ),
97 );
98
99 /**
100 * Filters the list of accent-color swatches offered in OS Settings.
101 *
102 * ```php
103 * add_filter( 'openstation_accent_colors', function ( $colors ) {
104 * $colors[] = array(
105 * 'id' => 'brand',
106 * 'label' => __( 'Brand', 'my-plugin' ),
107 * 'value' => '#ff00ff',
108 * );
109 * return $colors;
110 * } );
111 * ```
112 *
113 * Non-array return values fall back to the built-in defaults.
114 * Individual entries missing an `id`, `label`, or whose `value`
115 * isn't a valid hex color are dropped — the shell can't render
116 * half-formed swatches safely.
117 *
118 * @param array $defaults Built-in swatches.
119 */
120 $filtered = apply_filters( 'openstation_accent_colors', $defaults );
121 if ( ! is_array( $filtered ) ) {
122 return $defaults;
123 }
124
125 $clean = array();
126 $seen = array();
127 foreach ( $filtered as $entry ) {
128 if ( ! is_array( $entry ) ) {
129 continue;
130 }
131 $id = isset( $entry['id'] ) ? sanitize_key( (string) $entry['id'] ) : '';
132 $label = isset( $entry['label'] ) ? wp_strip_all_tags( (string) $entry['label'] ) : '';
133 $value = isset( $entry['value'] ) ? sanitize_hex_color( (string) $entry['value'] ) : '';
134 if ( '' === $id || '' === $label || null === $value || '' === $value ) {
135 continue;
136 }
137 if ( isset( $seen[ $id ] ) ) {
138 continue;
139 }
140 $seen[ $id ] = true;
141 $clean[] = array(
142 'id' => $id,
143 'label' => $label,
144 'value' => $value,
145 );
146 }
147
148 // If every entry was dropped (e.g. a filter returned all garbage),
149 // fall back to defaults so the picker is never empty.
150 return empty( $clean ) ? $defaults : $clean;
151 }
152