PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.0.1
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.0.1
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.0.1, at includes/accents.php

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