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/nonce-refresh.php +31 -30 0.9.61.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Heartbeat-driven nonce refresh.
3 + * OpenStation — Heartbeat-driven nonce refresh.
4 4 *
5 5 * WordPress nonces are valid for `nonce_life` (24 hours by default).
6 6 * The desktop shell is a long-running SPA whose per-window config
7 7 * blobs bake `wp_create_nonce()` values into the page at render
@@ -27,16 +27,15 @@
27 27 * - `updates` — Core's wp.updates nonce used by
28 28 * `wp_ajax_install_plugin` / `wp_ajax_update_plugin`.
29 29 *
30 30 * Plugin authors who need to extend the set can hook
31 - * `desktop_mode_nonce_refresh_actions` and add their own nonce
31 + * `openstation_nonce_refresh_actions` and add their own nonce
32 32 * action strings. The client side picks the new fields up
33 33 * automatically through the same heartbeat field — feature modules
34 34 * just need to register a target for the field they care about via
35 35 * the JS-side `registerNonceTarget()` helper.
36 36 *
37 - * @package WPDesktopMode
38 - * @since 0.8.7
37 + * @package OpenStation
39 38 */
40 39
41 40 defined( 'ABSPATH' ) || exit;
42 41
@@ -43,10 +42,16 @@
43 42 /**
44 43 * Heartbeat field name. Public — `src/nonce-refresh.ts` subscribes
45 44 * to this string. Keep the value stable across versions or update
46 45 * both ends.
46 + *
47 + * The VALUE keeps its pre-rebrand spelling on purpose: it is a
48 + * persisted or externally-visible identifier, so renaming it would
49 + * orphan data already written by live installs (or break a live
50 + * URL). The mismatch between this constant's name and its value is
51 + * deliberate — it is NOT a half-finished rename.
47 52 */
48 -const DESKTOP_MODE_NONCE_REFRESH_FIELD = 'desktop_mode_nonces';
53 +const OPENSTATION_NONCE_REFRESH_FIELD = 'desktop_mode_nonces';
49 54
50 55 /**
51 56 * Heartbeat field carrying the authenticated user's identity.
52 57 * `src/auth-recovery/index.ts` compares `uid` against the shell's
@@ -53,11 +58,15 @@
53 58 * boot-time viewer and hard-reloads when a *different* user logged
54 59 * in through the session-expired prompt — in-place nonce refresh
55 60 * would otherwise leave user A's desktop issuing user B's requests.
56 61 *
57 - * @since 0.9.8
62 + * The VALUE keeps its pre-rebrand spelling on purpose: it is a
63 + * persisted or externally-visible identifier, so renaming it would
64 + * orphan data already written by live installs (or break a live
65 + * URL). The mismatch between this constant's name and its value is
66 + * deliberate — it is NOT a half-finished rename.
58 67 */
59 -const DESKTOP_MODE_AUTH_FIELD = 'desktop_mode_auth';
68 +const OPENSTATION_AUTH_FIELD = 'desktop_mode_auth';
60 69
61 70 /**
62 71 * Mint a fresh map of `{ action => nonce }` for every action the
63 72 * shell needs to keep alive past `nonce_life`. The set is
@@ -64,13 +73,11 @@
64 73 * filterable so other native windows / third-party plugins can
65 74 * extend it; the only requirement is that the action string match
66 75 * whatever was passed to `wp_create_nonce()` at registration.
67 76 *
68 - * @since 0.8.7
69 - *
70 77 * @return array<string,string> Map of nonce-action => current nonce value.
71 78 */
72 -function desktop_mode_nonce_refresh_build_payload() {
79 +function openstation_nonce_refresh_build_payload() {
73 80 $actions = array(
74 81 'wp_rest',
75 82 'desktop-mode-plugins',
76 83 'updates',
@@ -81,17 +88,15 @@
81 88 *
82 89 * Each entry must be a literal nonce action string (the same value
83 90 * passed to `wp_create_nonce()` wherever the original was minted).
84 91 *
85 - * @since 0.8.7
86 - *
87 92 * @param string[] $actions Default nonce actions.
88 93 */
89 - $actions = (array) apply_filters( 'desktop_mode_nonce_refresh_actions', $actions );
94 + $actions = (array) apply_filters( 'openstation_nonce_refresh_actions', $actions );
90 95
91 96 $payload = array();
92 97 foreach ( $actions as $action ) {
93 - if ( ! is_string( $action ) || $action === '' ) {
98 + if ( ! is_string( $action ) || '' === $action ) {
94 99 continue;
95 100 }
96 101 $payload[ $action ] = wp_create_nonce( $action );
97 102 }
@@ -99,11 +104,11 @@
99 104 }
100 105
101 106 /**
102 107 * Heartbeat handler — attach the fresh nonce map to every tick
103 - * from a user who has Desktop Mode enabled.
108 + * from a user who has OpenStation enabled.
104 109 *
105 - * Gated on `desktop_mode_is_enabled()` (not just `is_user_logged_in()`)
110 + * Gated on `openstation_is_enabled()` (not just `is_user_logged_in()`)
106 111 * so users on classic admin screens — editors on post-edit pages,
107 112 * subscribers reading the front-end heartbeat — don't carry the
108 113 * payload around. The shell's nonces only need refreshing for
109 114 * users who actually run the shell.
@@ -111,27 +116,25 @@
111 116 * The cost is tiny when fired (three `wp_create_nonce()` calls,
112 117 * all hot-cached inside a single request) — the gate is about
113 118 * not shipping irrelevant data to non-shell users on every tick.
114 119 *
115 - * @since 0.8.7
116 - *
117 120 * @param array $response Heartbeat response (filter return value).
118 121 * @param array $data Client-sent payload. Unused here.
119 122 * @return array
120 123 */
121 -function desktop_mode_nonce_refresh_heartbeat_received( $response, $data ) {
124 +function openstation_nonce_refresh_heartbeat_received( $response, $data ) {
122 125 unset( $data );
123 126 if ( ! is_array( $response ) ) {
124 127 $response = array();
125 128 }
126 - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) {
129 + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) {
127 130 return $response;
128 131 }
129 - $response[ DESKTOP_MODE_NONCE_REFRESH_FIELD ] = desktop_mode_nonce_refresh_build_payload();
130 - $response[ DESKTOP_MODE_AUTH_FIELD ] = array( 'uid' => get_current_user_id() );
132 + $response[ OPENSTATION_NONCE_REFRESH_FIELD ] = openstation_nonce_refresh_build_payload();
133 + $response[ OPENSTATION_AUTH_FIELD ] = array( 'uid' => get_current_user_id() );
131 134 return $response;
132 135 }
133 -add_filter( 'heartbeat_received', 'desktop_mode_nonce_refresh_heartbeat_received', 5, 2 );
136 +add_filter( 'heartbeat_received', 'openstation_nonce_refresh_heartbeat_received', 5, 2 );
134 137
135 138 /**
136 139 * Nonce-refresh rider for the `nonces_expired` heartbeat path.
137 140 *
@@ -149,21 +152,19 @@
149 152 * the replacements. Client-side, `heartbeat.js` still fires
150 153 * `heartbeat-tick` for this response, so the regular
151 154 * `src/nonce-refresh.ts` subscriber picks the map up unchanged.
152 155 *
153 - * @since 0.9.8
154 - *
155 156 * @param array $response Heartbeat response (filter return value).
156 157 * @return array
157 158 */
158 -function desktop_mode_nonce_refresh_on_expired( $response ) {
159 +function openstation_nonce_refresh_on_expired( $response ) {
159 160 if ( ! is_array( $response ) ) {
160 161 $response = array();
161 162 }
162 - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) {
163 + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) {
163 164 return $response;
164 165 }
165 - $response[ DESKTOP_MODE_NONCE_REFRESH_FIELD ] = desktop_mode_nonce_refresh_build_payload();
166 - $response[ DESKTOP_MODE_AUTH_FIELD ] = array( 'uid' => get_current_user_id() );
166 + $response[ OPENSTATION_NONCE_REFRESH_FIELD ] = openstation_nonce_refresh_build_payload();
167 + $response[ OPENSTATION_AUTH_FIELD ] = array( 'uid' => get_current_user_id() );
167 168 return $response;
168 169 }
169 -add_filter( 'wp_refresh_nonces', 'desktop_mode_nonce_refresh_on_expired', 5 );
170 +add_filter( 'wp_refresh_nonces', 'openstation_nonce_refresh_on_expired', 5 );