PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.9
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.9
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 0.8.6 All 33 releases
desktop-mode / includes / accents.php

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

146 lines 4.2 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 two brand accents. Sirius is the cool counterweight
48 // to Pulse and the only light accent in the set; Lagoon sits
49 // between the two families and is what the guide reaches for
50 // when Pulse is too loud and WordPress Blue too corporate.
51 array(
52 'id' => 'sirius',
53 'label' => __( 'Sirius', 'desktop-mode' ),
54 'value' => '#9af2ff',
55 ),
56 array(
57 'id' => 'lagoon',
58 'label' => __( 'Lagoon', 'desktop-mode' ),
59 'value' => '#9f98ff',
60 ),
61 array(
62 'id' => 'wp-blue',
63 'label' => __( 'WordPress Blue', 'desktop-mode' ),
64 'value' => '#2271b1',
65 ),
66 array(
67 'id' => 'indigo',
68 'label' => __( 'Indigo', 'desktop-mode' ),
69 'value' => '#3858e9',
70 ),
71 array(
72 'id' => 'teal',
73 'label' => __( 'Teal', 'desktop-mode' ),
74 'value' => '#04a4cc',
75 ),
76 array(
77 'id' => 'emerald',
78 'label' => __( 'Emerald', 'desktop-mode' ),
79 'value' => '#059669',
80 ),
81 array(
82 'id' => 'amber',
83 'label' => __( 'Amber', 'desktop-mode' ),
84 'value' => '#d97706',
85 ),
86 array(
87 'id' => 'rose',
88 'label' => __( 'Rose', 'desktop-mode' ),
89 'value' => '#e11d48',
90 ),
91 );
92
93 /**
94 * Filters the list of accent-color swatches offered in OS Settings.
95 *
96 * ```php
97 * add_filter( 'openstation_accent_colors', function ( $colors ) {
98 * $colors[] = array(
99 * 'id' => 'brand',
100 * 'label' => __( 'Brand', 'my-plugin' ),
101 * 'value' => '#ff00ff',
102 * );
103 * return $colors;
104 * } );
105 * ```
106 *
107 * Non-array return values fall back to the built-in defaults.
108 * Individual entries missing an `id`, `label`, or whose `value`
109 * isn't a valid hex color are dropped — the shell can't render
110 * half-formed swatches safely.
111 *
112 * @param array $defaults Built-in swatches.
113 */
114 $filtered = apply_filters( 'openstation_accent_colors', $defaults );
115 if ( ! is_array( $filtered ) ) {
116 return $defaults;
117 }
118
119 $clean = array();
120 $seen = array();
121 foreach ( $filtered as $entry ) {
122 if ( ! is_array( $entry ) ) {
123 continue;
124 }
125 $id = isset( $entry['id'] ) ? sanitize_key( (string) $entry['id'] ) : '';
126 $label = isset( $entry['label'] ) ? wp_strip_all_tags( (string) $entry['label'] ) : '';
127 $value = isset( $entry['value'] ) ? sanitize_hex_color( (string) $entry['value'] ) : '';
128 if ( '' === $id || '' === $label || null === $value || '' === $value ) {
129 continue;
130 }
131 if ( isset( $seen[ $id ] ) ) {
132 continue;
133 }
134 $seen[ $id ] = true;
135 $clean[] = array(
136 'id' => $id,
137 'label' => $label,
138 'value' => $value,
139 );
140 }
141
142 // If every entry was dropped (e.g. a filter returned all garbage),
143 // fall back to defaults so the picker is never empty.
144 return empty( $clean ) ? $defaults : $clean;
145 }
146