| @@ -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,15 +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 | |
| 37 | + * @package OpenStation | |
| 38 | 38 | */ |
| 39 | 39 | |
| 40 | 40 | defined( 'ABSPATH' ) || exit; |
| 41 | 41 | |
| @@ -42,10 +42,16 @@ | ||
| 42 | 42 | /** |
| 43 | 43 | * Heartbeat field name. Public — `src/nonce-refresh.ts` subscribes |
| 44 | 44 | * to this string. Keep the value stable across versions or update |
| 45 | 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. | |
| 46 | 52 | */ |
| 47 | -const DESKTOP_MODE_NONCE_REFRESH_FIELD = 'desktop_mode_nonces'; | |
| 53 | +const OPENSTATION_NONCE_REFRESH_FIELD = 'desktop_mode_nonces'; | |
| 48 | 54 | |
| 49 | 55 | /** |
| 50 | 56 | * Heartbeat field carrying the authenticated user's identity. |
| 51 | 57 | * `src/auth-recovery/index.ts` compares `uid` against the shell's |
| @@ -51,10 +57,16 @@ | ||
| 51 | 57 | * `src/auth-recovery/index.ts` compares `uid` against the shell's |
| 52 | 58 | * boot-time viewer and hard-reloads when a *different* user logged |
| 53 | 59 | * in through the session-expired prompt — in-place nonce refresh |
| 54 | 60 | * would otherwise leave user A's desktop issuing user B's requests. |
| 61 | + * | |
| 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. | |
| 55 | 67 | */ |
| 56 | -const DESKTOP_MODE_AUTH_FIELD = 'desktop_mode_auth'; | |
| 68 | +const OPENSTATION_AUTH_FIELD = 'desktop_mode_auth'; | |
| 57 | 69 | |
| 58 | 70 | /** |
| 59 | 71 | * Mint a fresh map of `{ action => nonce }` for every action the |
| 60 | 72 | * shell needs to keep alive past `nonce_life`. The set is |
| @@ -63,9 +75,9 @@ | ||
| 63 | 75 | * whatever was passed to `wp_create_nonce()` at registration. |
| 64 | 76 | * |
| 65 | 77 | * @return array<string,string> Map of nonce-action => current nonce value. |
| 66 | 78 | */ |
| 67 | -function desktop_mode_nonce_refresh_build_payload() { | |
| 79 | +function openstation_nonce_refresh_build_payload() { | |
| 68 | 80 | $actions = array( |
| 69 | 81 | 'wp_rest', |
| 70 | 82 | 'desktop-mode-plugins', |
| 71 | 83 | 'updates', |
| @@ -78,13 +90,13 @@ | ||
| 78 | 90 | * passed to `wp_create_nonce()` wherever the original was minted). |
| 79 | 91 | * |
| 80 | 92 | * @param string[] $actions Default nonce actions. |
| 81 | 93 | */ |
| 82 | - $actions = (array) apply_filters( 'desktop_mode_nonce_refresh_actions', $actions ); | |
| 94 | + $actions = (array) apply_filters( 'openstation_nonce_refresh_actions', $actions ); | |
| 83 | 95 | |
| 84 | 96 | $payload = array(); |
| 85 | 97 | foreach ( $actions as $action ) { |
| 86 | - if ( ! is_string( $action ) || $action === '' ) { | |
| 98 | + if ( ! is_string( $action ) || '' === $action ) { | |
| 87 | 99 | continue; |
| 88 | 100 | } |
| 89 | 101 | $payload[ $action ] = wp_create_nonce( $action ); |
| 90 | 102 | } |
| @@ -92,11 +104,11 @@ | ||
| 92 | 104 | } |
| 93 | 105 | |
| 94 | 106 | /** |
| 95 | 107 | * Heartbeat handler — attach the fresh nonce map to every tick |
| 96 | - * from a user who has Desktop Mode enabled. | |
| 108 | + * from a user who has OpenStation enabled. | |
| 97 | 109 | * |
| 98 | - * Gated on `desktop_mode_is_enabled()` (not just `is_user_logged_in()`) | |
| 110 | + * Gated on `openstation_is_enabled()` (not just `is_user_logged_in()`) | |
| 99 | 111 | * so users on classic admin screens — editors on post-edit pages, |
| 100 | 112 | * subscribers reading the front-end heartbeat — don't carry the |
| 101 | 113 | * payload around. The shell's nonces only need refreshing for |
| 102 | 114 | * users who actually run the shell. |
| @@ -108,21 +120,21 @@ | ||
| 108 | 120 | * @param array $response Heartbeat response (filter return value). |
| 109 | 121 | * @param array $data Client-sent payload. Unused here. |
| 110 | 122 | * @return array |
| 111 | 123 | */ |
| 112 | -function desktop_mode_nonce_refresh_heartbeat_received( $response, $data ) { | |
| 124 | +function openstation_nonce_refresh_heartbeat_received( $response, $data ) { | |
| 113 | 125 | unset( $data ); |
| 114 | 126 | if ( ! is_array( $response ) ) { |
| 115 | 127 | $response = array(); |
| 116 | 128 | } |
| 117 | - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) { | |
| 129 | + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) { | |
| 118 | 130 | return $response; |
| 119 | 131 | } |
| 120 | - $response[ DESKTOP_MODE_NONCE_REFRESH_FIELD ] = desktop_mode_nonce_refresh_build_payload(); | |
| 121 | - $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() ); | |
| 122 | 134 | return $response; |
| 123 | 135 | } |
| 124 | -add_filter( 'heartbeat_received', 'desktop_mode_nonce_refresh_heartbeat_received', 5, 2 ); | |
| 136 | +add_filter( 'heartbeat_received', 'openstation_nonce_refresh_heartbeat_received', 5, 2 ); | |
| 125 | 137 | |
| 126 | 138 | /** |
| 127 | 139 | * Nonce-refresh rider for the `nonces_expired` heartbeat path. |
| 128 | 140 | * |
| @@ -143,16 +155,16 @@ | ||
| 143 | 155 | * |
| 144 | 156 | * @param array $response Heartbeat response (filter return value). |
| 145 | 157 | * @return array |
| 146 | 158 | */ |
| 147 | -function desktop_mode_nonce_refresh_on_expired( $response ) { | |
| 159 | +function openstation_nonce_refresh_on_expired( $response ) { | |
| 148 | 160 | if ( ! is_array( $response ) ) { |
| 149 | 161 | $response = array(); |
| 150 | 162 | } |
| 151 | - if ( ! function_exists( 'desktop_mode_is_enabled' ) || ! desktop_mode_is_enabled() ) { | |
| 163 | + if ( ! function_exists( 'openstation_is_enabled' ) || ! openstation_is_enabled() ) { | |
| 152 | 164 | return $response; |
| 153 | 165 | } |
| 154 | - $response[ DESKTOP_MODE_NONCE_REFRESH_FIELD ] = desktop_mode_nonce_refresh_build_payload(); | |
| 155 | - $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() ); | |
| 156 | 168 | return $response; |
| 157 | 169 | } |
| 158 | -add_filter( 'wp_refresh_nonces', 'desktop_mode_nonce_refresh_on_expired', 5 ); | |
| 170 | +add_filter( 'wp_refresh_nonces', 'openstation_nonce_refresh_on_expired', 5 ); | |