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/seen-intros.php +63 -53 0.9.81.1.10 View file →
@@ -1,36 +1,45 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — "Seen intros" registry.
3 + * OpenStation — "Seen intros" registry.
4 4 *
5 - * Tracks which one-time introduction dialogs the current user has
6 - * already dismissed, so the shell can show a "what's new in this
7 - * native app" dialog the first time a ported native window opens
8 - * and never bother the user again afterwards.
5 + * Tracks which one-time announcements the current user has already
6 + * dismissed, so each is shown once and never bothers them again.
9 7 *
10 - * Today the surface is the native Posts window. The same key is
11 - * intentionally generic — any future ported native app (Pages,
12 - * Comments, Users, Plugins, …) registers its own slug and reuses
13 - * this storage. OS Settings → Features exposes a "Reset what's-new
14 - * dialogs" button that clears the whole list so the user can see
15 - * every intro again from scratch.
8 + * Two surfaces use it today: the activation welcome dialog
9 + * (`includes/welcome-dialog.php`, slug `activation-welcome`), shown
10 + * in the classic admin while OpenStation is disabled, and the rebrand
11 + * notice (`src/rebrand-notice.ts`, slug `openstation-rebrand`). The
12 + * key is intentionally generic, so anything else that needs
13 + * show-once semantics registers its own slug and reuses this storage.
14 + * OpenStation Preferences → Features exposes a "Reset what's-new
15 + * dialogs" button that clears the whole list.
16 16 *
17 17 * Storage shape:
18 18 * user meta `desktop_mode_seen_intros` → array<string> of slugs.
19 - * `[ 'posts' ]`, `[ 'posts', 'pages' ]`, etc. Slug values pass
20 - * through `sanitize_key()` and the list is capped at 64 entries
21 - * so a runaway client cannot bloat user-meta indefinitely.
19 + * `[ 'activation-welcome' ]`, `[ 'openstation-rebrand' ]`, etc.
20 + * Slug values pass through `sanitize_key()` and the list is capped
21 + * at 64 entries so a runaway client cannot bloat user-meta
22 + * indefinitely.
22 23 *
23 - * @package WPDesktopMode
24 + * @package OpenStation
24 25 */
25 26
26 27 defined( 'ABSPATH' ) || exit;
27 28
28 -/** User meta key — see file header for shape. */
29 -const DESKTOP_MODE_SEEN_INTROS_META_KEY = 'desktop_mode_seen_intros';
29 +/**
30 + * User meta key — see file header for shape.
31 + *
32 + * The VALUE keeps its pre-rebrand spelling on purpose: it is a
33 + * persisted or externally-visible identifier, so renaming it would
34 + * orphan data already written by live installs (or break a live
35 + * URL). The mismatch between this constant's name and its value is
36 + * deliberate — it is NOT a half-finished rename.
37 + */
38 +const OPENSTATION_SEEN_INTROS_META_KEY = 'desktop_mode_seen_intros';
30 39
31 40 /** Hard cap so a malicious client cannot grow the list unbounded. */
32 -const DESKTOP_MODE_SEEN_INTROS_MAX = 64;
41 +const OPENSTATION_SEEN_INTROS_MAX = 64;
33 42
34 43 /**
35 44 * Returns the list of intro slugs the user has dismissed.
36 45 *
@@ -36,20 +45,20 @@
36 45 *
37 46 * @param int $user_id User ID.
38 47 * @return string[] Sanitized list (may be empty).
39 48 */
40 -function desktop_mode_get_seen_intros( $user_id ) {
49 +function openstation_get_seen_intros( $user_id ) {
41 50 $user_id = (int) $user_id;
42 51 if ( $user_id <= 0 ) {
43 52 return array();
44 53 }
45 54
46 - $raw = get_user_meta( $user_id, DESKTOP_MODE_SEEN_INTROS_META_KEY, true );
55 + $raw = get_user_meta( $user_id, OPENSTATION_SEEN_INTROS_META_KEY, true );
47 56 if ( ! is_array( $raw ) ) {
48 57 return array();
49 58 }
50 59
51 - return desktop_mode_sanitize_seen_intros( $raw );
60 + return openstation_sanitize_seen_intros( $raw );
52 61 }
53 62
54 63 /**
55 64 * Whether the user has already dismissed the given intro.
@@ -57,14 +66,14 @@
57 66 * @param int $user_id User ID.
58 67 * @param string $slug Intro slug (e.g. `'posts'`).
59 68 * @return bool
60 69 */
61 -function desktop_mode_has_seen_intro( $user_id, $slug ) {
70 +function openstation_has_seen_intro( $user_id, $slug ) {
62 71 $slug = sanitize_key( (string) $slug );
63 72 if ( '' === $slug ) {
64 73 return false;
65 74 }
66 - return in_array( $slug, desktop_mode_get_seen_intros( $user_id ), true );
75 + return in_array( $slug, openstation_get_seen_intros( $user_id ), true );
67 76 }
68 77
69 78 /**
70 79 * Adds a slug to the user's seen-intros list.
@@ -75,9 +84,9 @@
75 84 * @param int $user_id User ID.
76 85 * @param string $slug Intro slug.
77 86 * @return bool True on successful write (or no-op), false otherwise.
78 87 */
79 -function desktop_mode_mark_intro_seen( $user_id, $slug ) {
88 +function openstation_mark_intro_seen( $user_id, $slug ) {
80 89 $user_id = (int) $user_id;
81 90 $slug = sanitize_key( (string) $slug );
82 91 if ( $user_id <= 0 || '' === $slug ) {
83 92 return false;
@@ -82,19 +91,19 @@
82 91 if ( $user_id <= 0 || '' === $slug ) {
83 92 return false;
84 93 }
85 94
86 - $current = desktop_mode_get_seen_intros( $user_id );
95 + $current = openstation_get_seen_intros( $user_id );
87 96 if ( in_array( $slug, $current, true ) ) {
88 97 return true;
89 98 }
90 99
91 100 $current[] = $slug;
92 - $current = array_slice( $current, 0, DESKTOP_MODE_SEEN_INTROS_MAX );
101 + $current = array_slice( $current, 0, OPENSTATION_SEEN_INTROS_MAX );
93 102
94 103 return false !== update_user_meta(
95 104 $user_id,
96 - DESKTOP_MODE_SEEN_INTROS_META_KEY,
105 + OPENSTATION_SEEN_INTROS_META_KEY,
97 106 $current
98 107 );
99 108 }
100 109
@@ -104,14 +113,14 @@
104 113 *
105 114 * @param int $user_id User ID.
106 115 * @return bool True on success.
107 116 */
108 -function desktop_mode_clear_seen_intros( $user_id ) {
117 +function openstation_clear_seen_intros( $user_id ) {
109 118 $user_id = (int) $user_id;
110 119 if ( $user_id <= 0 ) {
111 120 return false;
112 121 }
113 - return (bool) delete_user_meta( $user_id, DESKTOP_MODE_SEEN_INTROS_META_KEY );
122 + return (bool) delete_user_meta( $user_id, OPENSTATION_SEEN_INTROS_META_KEY );
114 123 }
115 124
116 125 /**
117 126 * Coerces a raw payload to a clean list of slugs.
@@ -118,9 +127,9 @@
118 127 *
119 128 * @param mixed $raw Raw value.
120 129 * @return string[]
121 130 */
122 -function desktop_mode_sanitize_seen_intros( $raw ) {
131 +function openstation_sanitize_seen_intros( $raw ) {
123 132 if ( ! is_array( $raw ) ) {
124 133 return array();
125 134 }
126 135 $out = array();
@@ -133,9 +142,9 @@
133 142 continue;
134 143 }
135 144 $out[] = $slug;
136 145 }
137 - return array_slice( array_values( array_unique( $out ) ), 0, DESKTOP_MODE_SEEN_INTROS_MAX );
146 + return array_slice( array_values( array_unique( $out ) ), 0, OPENSTATION_SEEN_INTROS_MAX );
138 147 }
139 148
140 149 /**
141 150 * Registers REST routes for the seen-intros surface.
@@ -146,16 +155,16 @@
146 155 *
147 156 * Both return the post-mutation list so the client can refresh its
148 157 * local snapshot without a follow-up GET.
149 158 */
150 -function desktop_mode_register_seen_intros_routes() {
159 +function openstation_register_seen_intros_routes() {
151 160 register_rest_route(
152 161 'desktop-mode/v1',
153 162 '/intros/seen',
154 163 array(
155 164 'methods' => WP_REST_Server::CREATABLE,
156 - 'callback' => 'desktop_mode_rest_mark_intro_seen',
157 - 'permission_callback' => 'desktop_mode_rest_seen_intros_permission',
165 + 'callback' => 'openstation_rest_mark_intro_seen',
166 + 'permission_callback' => 'openstation_rest_seen_intros_permission',
158 167 'args' => array(
159 168 'slug' => array(
160 169 'required' => true,
161 170 'type' => 'string',
@@ -168,28 +177,29 @@
168 177 'desktop-mode/v1',
169 178 '/intros',
170 179 array(
171 180 'methods' => WP_REST_Server::DELETABLE,
172 - 'callback' => 'desktop_mode_rest_clear_seen_intros',
173 - 'permission_callback' => 'desktop_mode_rest_seen_intros_permission',
181 + 'callback' => 'openstation_rest_clear_seen_intros',
182 + 'permission_callback' => 'openstation_rest_seen_intros_permission',
174 183 )
175 184 );
176 185 }
177 -add_action( 'rest_api_init', 'desktop_mode_register_seen_intros_routes' );
186 +add_action( 'rest_api_init', 'openstation_register_seen_intros_routes' );
178 187
179 188 /**
180 189 * Permission gate for the seen-intros routes.
181 190 *
182 - * In-shell intros (slug `posts`, `pages`, …) are only ever shown to a
183 - * user who has already entered Desktop Mode, so they keep the strict
184 - * {@see desktop_mode_rest_require_enabled()} gate — `read` alone is
191 + * In-shell announcements (the rebrand notice, and anything a plugin
192 + * registers) are only ever shown to a user who has already entered
193 + * OpenStation, so they keep the strict
194 + * {@see openstation_rest_require_enabled()} gate — `read` alone is
185 195 * insufficient (every role, Subscriber included, carries `read`).
186 196 *
187 197 * The one exception is the first-run welcome dialog
188 - * ({@see DESKTOP_MODE_WELCOME_INTRO_SLUG}): it renders in the *classic*
189 - * admin precisely when Desktop Mode is NOT enabled, which is the only
198 + * ({@see OPENSTATION_WELCOME_INTRO_SLUG}): it renders in the *classic*
199 + * admin precisely when OpenStation is NOT enabled, which is the only
190 200 * state it ever appears in. Gating its dismissal behind
191 - * `desktop_mode_rest_require_enabled()` would make the dismissal POST
201 + * `openstation_rest_require_enabled()` would make the dismissal POST
192 202 * return 403 every time, so the slug could never be recorded as seen and
193 203 * the dialog re-rendered on every classic-admin page load. We therefore
194 204 * let that single slug through for any logged-in `read`-capable account
195 205 * (the exact audience the dialog is shown to); writing one's own
@@ -198,11 +208,11 @@
198 208 *
199 209 * @param WP_REST_Request $request The REST request.
200 210 * @return true|WP_Error
201 211 */
202 -function desktop_mode_rest_seen_intros_permission( WP_REST_Request $request ) {
212 +function openstation_rest_seen_intros_permission( WP_REST_Request $request ) {
203 213 $slug = sanitize_key( (string) $request->get_param( 'slug' ) );
204 - if ( defined( 'DESKTOP_MODE_WELCOME_INTRO_SLUG' ) && DESKTOP_MODE_WELCOME_INTRO_SLUG === $slug ) {
214 + if ( defined( 'OPENSTATION_WELCOME_INTRO_SLUG' ) && OPENSTATION_WELCOME_INTRO_SLUG === $slug ) {
205 215 if ( ! is_user_logged_in() ) {
206 216 return new WP_Error(
207 217 'rest_forbidden',
208 218 __( 'Authentication required.', 'desktop-mode' ),
@@ -218,9 +228,9 @@
218 228 }
219 229 return true;
220 230 }
221 231
222 - return desktop_mode_rest_require_enabled();
232 + return openstation_rest_require_enabled();
223 233 }
224 234
225 235 /**
226 236 * REST handler for `POST /desktop-mode/v1/intros/seen`.
@@ -227,21 +237,21 @@
227 237 *
228 238 * @param WP_REST_Request $request REST request.
229 239 * @return WP_REST_Response|WP_Error
230 240 */
231 -function desktop_mode_rest_mark_intro_seen( WP_REST_Request $request ) {
241 +function openstation_rest_mark_intro_seen( WP_REST_Request $request ) {
232 242 $user_id = get_current_user_id();
233 243 $slug = sanitize_key( (string) $request->get_param( 'slug' ) );
234 244 if ( '' === $slug ) {
235 245 return new WP_Error(
236 - 'desktop_mode_invalid_intro_slug',
246 + 'openstation_invalid_intro_slug',
237 247 __( 'The `slug` parameter must be a non-empty string.', 'desktop-mode' ),
238 248 array( 'status' => 400 )
239 249 );
240 250 }
241 - desktop_mode_mark_intro_seen( $user_id, $slug );
251 + openstation_mark_intro_seen( $user_id, $slug );
242 252 return rest_ensure_response(
243 - array( 'seenIntros' => desktop_mode_get_seen_intros( $user_id ) )
253 + array( 'seenIntros' => openstation_get_seen_intros( $user_id ) )
244 254 );
245 255 }
246 256
247 257 /**
@@ -248,11 +258,11 @@
248 258 * REST handler for `DELETE /desktop-mode/v1/intros`.
249 259 *
250 260 * @return WP_REST_Response
251 261 */
252 -function desktop_mode_rest_clear_seen_intros() {
262 +function openstation_rest_clear_seen_intros() {
253 263 $user_id = get_current_user_id();
254 - desktop_mode_clear_seen_intros( $user_id );
264 + openstation_clear_seen_intros( $user_id );
255 265 return rest_ensure_response(
256 - array( 'seenIntros' => desktop_mode_get_seen_intros( $user_id ) )
266 + array( 'seenIntros' => openstation_get_seen_intros( $user_id ) )
257 267 );
258 268 }