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
← All changes | includes/window-notices.php +28 -40 0.8.81.1.10 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * Window notices — declarative top-of-window banners.
4 4 *
5 - * Plugins call `desktop_mode_register_window_notice()` to surface a
5 + * Plugins call `openstation_register_window_notice()` to surface a
6 6 * tone-coded banner at the top of every window matching a `match`
7 7 * predicate (or every window by default). The shell renders the
8 - * notice via the `<wpd-notice>` web component inside the window's
8 + * notice via the `<os-notice>` web component inside the window's
9 9 * `after-titlebar` slot, and records the user's dismissal in
10 10 * `localStorage` so the same notice never reappears.
11 11 *
12 12 * Notices are pure declarative data — no JS handle is needed.
@@ -13,9 +13,9 @@
13 13 *
14 14 * Example:
15 15 *
16 16 * ```php
17 - * desktop_mode_register_window_notice( array(
17 + * openstation_register_window_notice( array(
18 18 * 'id' => 'my-plugin/welcome',
19 19 * 'tone' => 'info',
20 20 * 'message' => '<strong>Welcome!</strong> Read the <a href="…">docs</a>.',
21 21 * 'match' => array( 'window' => 'edit-php' ), // optional
@@ -21,22 +21,20 @@
21 21 * 'match' => array( 'window' => 'edit-php' ), // optional
22 22 * ) );
23 23 * ```
24 24 *
25 - * @since 0.22.0
26 - * @package DesktopMode
25 + * @package OpenStation
27 26 */
28 27
29 28 defined( 'ABSPATH' ) || exit;
30 29
31 30 /**
32 - * Allowed tones — mirror the `<wpd-notice>` component's `tone`
31 + * Allowed tones — mirror the `<os-notice>` component's `tone`
33 32 * attribute.
34 33 *
35 - * @since 0.22.0
36 34 * @return string[]
37 35 */
38 -function desktop_mode_window_notice_tones() {
36 +function openstation_window_notice_tones() {
39 37 return array( 'info', 'success', 'warning', 'error', 'danger', 'neutral' );
40 38 }
41 39
42 40 /**
@@ -41,10 +39,8 @@
41 39
42 40 /**
43 41 * Register (or replace) a declarative window notice.
44 42 *
45 - * @since 0.22.0
46 - *
47 43 * @param array $args {
48 44 * @type string $id Required. Persistence + dedupe key.
49 45 * Recommended format `<plugin>/<slug>`.
50 46 * @type string $message Required. HTML body. Passed through
@@ -52,9 +48,9 @@
52 48 * links + basic formatting are allowed
53 49 * but `<script>` and other unsafe
54 50 * markup are stripped.
55 51 * @type string $tone Optional. One of
56 - * {@see desktop_mode_window_notice_tones()}.
52 + * {@see openstation_window_notice_tones()}.
57 53 * Default `info`.
58 54 * @type bool $dismissible Optional. Show a close button.
59 55 * Default `true`.
60 56 * @type string $icon Optional. Dashicons class for a
@@ -89,9 +85,9 @@
89 85 * only on the Posts window when its
90 86 * URL also contains `wc-admin` — not
91 87 * on every Posts window AND every
92 88 * wc-admin-URL window. Use two
93 - * separate `desktop_mode_register_window_notice()`
89 + * separate `openstation_register_window_notice()`
94 90 * calls for OR-across-selector-types.
95 91 *
96 92 * When omitted, the notice paints on
97 93 * every window.
@@ -101,9 +97,9 @@
101 97 * }
102 98 * @return true|WP_Error `true` on success; `WP_Error` on validation
103 99 * failure.
104 100 */
105 -function desktop_mode_register_window_notice( $args = array() ) {
101 +function openstation_register_window_notice( $args = array() ) {
106 102 $defaults = array(
107 103 'id' => '',
108 104 'message' => '',
109 105 'tone' => 'info',
@@ -111,20 +107,20 @@
111 107 'icon' => '',
112 108 'match' => array(),
113 109 'order' => 100,
114 110 );
115 - $args = wp_parse_args( $args, $defaults );
111 + $args = wp_parse_args( $args, $defaults );
116 112
117 113 $id = (string) $args['id'];
118 114 if ( '' === $id ) {
119 - return desktop_mode_registration_error(
120 - 'desktop_mode_missing_id',
115 + return openstation_registration_error(
116 + 'openstation_missing_id',
121 117 __( 'Window notice registration requires a non-empty `id`.', 'desktop-mode' )
122 118 );
123 119 }
124 120 if ( ! preg_match( '/^[a-z0-9_\\/-]+$/i', $id ) ) {
125 - return desktop_mode_registration_error(
126 - 'desktop_mode_invalid_id',
121 + return openstation_registration_error(
122 + 'openstation_invalid_id',
127 123 __( 'Window notice `id` must be alphanumeric with hyphens, underscores, or slashes.', 'desktop-mode' ),
128 124 array( 'id' => $id )
129 125 );
130 126 }
@@ -129,10 +125,10 @@
129 125 );
130 126 }
131 127
132 128 if ( '' === (string) $args['message'] ) {
133 - return desktop_mode_registration_error(
134 - 'desktop_mode_missing_message',
129 + return openstation_registration_error(
130 + 'openstation_missing_message',
135 131 __( 'Window notice registration requires a non-empty `message`.', 'desktop-mode' ),
136 132 array( 'id' => $id )
137 133 );
138 134 }
@@ -137,11 +133,11 @@
137 133 );
138 134 }
139 135
140 136 $tone = (string) $args['tone'];
141 - if ( ! in_array( $tone, desktop_mode_window_notice_tones(), true ) ) {
142 - return desktop_mode_registration_error(
143 - 'desktop_mode_invalid_tone',
137 + if ( ! in_array( $tone, openstation_window_notice_tones(), true ) ) {
138 + return openstation_registration_error(
139 + 'openstation_invalid_tone',
144 140 __( 'Window notice `tone` must be one of the documented values.', 'desktop-mode' ),
145 141 array(
146 142 'id' => $id,
147 143 'tone' => $tone,
@@ -166,19 +162,17 @@
166 162 'match' => is_array( $args['match'] ) ? $args['match'] : array(),
167 163 'order' => (int) $args['order'],
168 164 );
169 165
170 - desktop_mode_window_notice_registry( $entry['id'], $entry );
166 + openstation_window_notice_registry( $entry['id'], $entry );
171 167
172 168 /**
173 169 * Fires after a window notice is successfully registered.
174 170 *
175 - * @since 0.22.0
176 - *
177 171 * @param string $id The notice id.
178 172 * @param array $entry The stored registry entry.
179 173 */
180 - do_action( 'desktop_mode_window_notice_registered', $entry['id'], $entry );
174 + do_action( 'openstation_window_notice_registered', $entry['id'], $entry );
181 175
182 176 return true;
183 177 }
184 178
@@ -184,9 +178,8 @@
184 178
185 179 /**
186 180 * Internal module-level registry for window notices.
187 181 *
188 - * @since 0.22.0
189 182 * @internal
190 183 *
191 184 * @param string $id Id to read or write.
192 185 * @param array|null $entry Entry to store, or `null` to read.
@@ -191,9 +184,9 @@
191 184 * @param string $id Id to read or write.
192 185 * @param array|null $entry Entry to store, or `null` to read.
193 186 * @return array|null
194 187 */
195 -function desktop_mode_window_notice_registry( $id = '', $entry = null ) {
188 +function openstation_window_notice_registry( $id = '', $entry = null ) {
196 189 static $store = array();
197 190
198 191 if ( '__flush__' === (string) $id ) {
199 192 $store = array();
@@ -215,27 +208,24 @@
215 208 * that calls this would wipe every plugin's registered notice on the
216 209 * current request. Mirrors the same `flush_*` shape the
217 210 * commands / settings-tabs / window-chrome registries expose.
218 211 *
219 - * @since 0.22.0
220 212 * @internal
221 213 */
222 -function desktop_mode_flush_window_notice_registry() {
223 - desktop_mode_window_notice_registry( '__flush__' );
214 +function openstation_flush_window_notice_registry() {
215 + openstation_window_notice_registry( '__flush__' );
224 216 }
225 217
226 218 /**
227 219 * Build the payload shipped to the shell. Each entry is the stored
228 220 * registry record, runnable through the
229 - * `desktop_mode_window_notices` filter so plugins can mutate the
221 + * `openstation_window_notices` filter so plugins can mutate the
230 222 * final list (e.g. add a dynamic notice computed at request time).
231 223 *
232 - * @since 0.22.0
233 - *
234 224 * @return array[]
235 225 */
236 -function desktop_mode_build_window_notices_payload() {
237 - $registry = desktop_mode_window_notice_registry();
226 +function openstation_build_window_notices_payload() {
227 + $registry = openstation_window_notice_registry();
238 228 $entries = is_array( $registry ) ? array_values( $registry ) : array();
239 229
240 230 /**
241 231 * Filter the assembled list of window notices before it ships to
@@ -242,13 +232,11 @@
242 232 * the shell. Plugins can append/remove/mutate notices here for
243 233 * request-dependent banners (e.g. "your trial expires today")
244 234 * without registering them statically.
245 235 *
246 - * @since 0.22.0
247 - *
248 236 * @param array[] $entries List of notice entries.
249 237 */
250 - $entries = apply_filters( 'desktop_mode_window_notices', $entries );
238 + $entries = apply_filters( 'openstation_window_notices', $entries );
251 239
252 240 // Re-sort by order for deterministic emission, then by id.
253 241 usort(
254 242 $entries,