| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — My WordPress: post-lock REST field. | |
| 3 | + * OpenStation — My WordPress: post-lock REST field. | |
| 4 | 4 | * |
| 5 | 5 | * Surfaces "is this post currently being edited by someone else?" |
| 6 | 6 | * on every post / page / opt-in CPT REST response so the My WordPress |
| 7 | 7 | * file-explorer can show a lock icon + the locking user's name on |
| @@ -14,16 +14,15 @@ | ||
| 14 | 14 | * We expose the same intelligence as a structured field, gated on |
| 15 | 15 | * `edit_post` so users who can't edit the post never see who else is |
| 16 | 16 | * editing it. |
| 17 | 17 | * |
| 18 | - * The field name is `desktop_mode_lock`; shape: | |
| 18 | + * The field name is `openstation_lock`; shape: | |
| 19 | 19 | * |
| 20 | 20 | * - `null` — not locked, OR the requester lacks edit caps. |
| 21 | 21 | * - `{ userId, userName, userAvatarUrl, time }` — locked by another |
| 22 | 22 | * user. `time` is the ISO-8601 timestamp of the lock heartbeat. |
| 23 | 23 | * |
| 24 | - * @package WPDesktopMode | |
| 25 | - * @since 0.8.0 | |
| 24 | + * @package OpenStation | |
| 26 | 25 | */ |
| 27 | 26 | |
| 28 | 27 | defined( 'ABSPATH' ) || exit; |
| 29 | 28 | |
| @@ -34,14 +33,12 @@ | ||
| 34 | 33 | * - The post isn't locked. |
| 35 | 34 | * - The current user is the lock holder (no point flagging yourself). |
| 36 | 35 | * - The current user can't edit the post (don't leak who's editing). |
| 37 | 36 | * |
| 38 | - * @since 0.8.0 | |
| 39 | - * | |
| 40 | 37 | * @param int $post_id Post id. |
| 41 | 38 | * @return array{userId:int,userName:string,userAvatarUrl:string,time:string}|null |
| 42 | 39 | */ |
| 43 | -function desktop_mode_my_wordpress_post_lock_payload( $post_id ) { | |
| 40 | +function openstation_my_wordpress_post_lock_payload( $post_id ) { | |
| 44 | 41 | $post_id = (int) $post_id; |
| 45 | 42 | if ( $post_id <= 0 ) { |
| 46 | 43 | return null; |
| 47 | 44 | } |
| @@ -94,9 +91,9 @@ | ||
| 94 | 91 | * 3. The `_edit_last` post meta — who saved the post most |
| 95 | 92 | * recently; the only signal on installs with revisions |
| 96 | 93 | * disabled. |
| 97 | 94 | * 4. Anything plugins return from the |
| 98 | - * `desktop_mode_my_wordpress_post_contributors` filter, which | |
| 95 | + * `openstation_my_wordpress_post_contributors` filter, which | |
| 99 | 96 | * receives the post id + the running user-id list. Filter |
| 100 | 97 | * contract is plain int[] for ergonomics; we expand each id |
| 101 | 98 | * into the structured shape afterwards. |
| 102 | 99 | * |
| @@ -107,14 +104,12 @@ | ||
| 107 | 104 | * The post's `post_author` is intentionally NOT included here — |
| 108 | 105 | * it's already surfaced by the canonical "Author" sub-folder. |
| 109 | 106 | * Contributors is the *additional* people surface. |
| 110 | 107 | * |
| 111 | - * @since 0.8.0 | |
| 112 | - * | |
| 113 | 108 | * @param int $post_id Post id. |
| 114 | 109 | * @return array<int,array{userId:int,userName:string,userAvatarUrl:string}> |
| 115 | 110 | */ |
| 116 | -function desktop_mode_my_wordpress_post_contributors_payload( $post_id ) { | |
| 111 | +function openstation_my_wordpress_post_contributors_payload( $post_id ) { | |
| 117 | 112 | $post_id = (int) $post_id; |
| 118 | 113 | if ( $post_id <= 0 ) { |
| 119 | 114 | return array(); |
| 120 | 115 | } |
| @@ -192,9 +187,9 @@ | ||
| 192 | 187 | * Examples: |
| 193 | 188 | * |
| 194 | 189 | * ```php |
| 195 | 190 | * // ACF user-list field "post_contributors": |
| 196 | - * add_filter( 'desktop_mode_my_wordpress_post_contributors', | |
| 191 | + * add_filter( 'openstation_my_wordpress_post_contributors', | |
| 197 | 192 | * function ( $ids, $post_id ) { |
| 198 | 193 | * $extra = (array) get_field( 'post_contributors', $post_id ); |
| 199 | 194 | * foreach ( $extra as $u ) { |
| 200 | 195 | * if ( $u instanceof WP_User ) { |
| @@ -206,15 +201,13 @@ | ||
| 206 | 201 | * return $ids; |
| 207 | 202 | * }, 10, 2 ); |
| 208 | 203 | * ``` |
| 209 | 204 | * |
| 210 | - * @since 0.8.0 | |
| 211 | - * | |
| 212 | 205 | * @param int[] $ids Contributor user ids gathered so far |
| 213 | 206 | * (from Co-Authors Plus, etc.). |
| 214 | 207 | * @param int $post_id Post id. |
| 215 | 208 | */ |
| 216 | - $ids = (array) apply_filters( 'desktop_mode_my_wordpress_post_contributors', $ids, $post_id ); | |
| 209 | + $ids = (array) apply_filters( 'openstation_my_wordpress_post_contributors', $ids, $post_id ); | |
| 217 | 210 | |
| 218 | 211 | // De-duplicate, drop the primary author so the Contributors |
| 219 | 212 | // sub-folder only carries *additional* people, drop empty/0, |
| 220 | 213 | // and resolve to user records. |
| @@ -246,36 +239,29 @@ | ||
| 246 | 239 | return $out; |
| 247 | 240 | } |
| 248 | 241 | |
| 249 | 242 | /** |
| 250 | - * Register the REST fields on every public post type that runs | |
| 251 | - * through the standard `/wp/v2/<type>` endpoint. Posts and pages | |
| 252 | - * cover the Phase 1 surface; CPTs come along for free. | |
| 243 | + * Register the REST fields on every post type the site window can | |
| 244 | + * browse — public REST-exposed types plus the ones bridged under | |
| 245 | + * `desktop-mode/v1`. Posts and pages cover the Phase 1 surface; CPTs | |
| 246 | + * come along for free. | |
| 253 | 247 | * |
| 254 | 248 | * Two fields: |
| 255 | - * - `desktop_mode_lock` — active edit-lock holder. | |
| 256 | - * - `desktop_mode_contributors` — additional contributor users | |
| 249 | + * - `openstation_lock` — active edit-lock holder. | |
| 250 | + * - `openstation_contributors` — additional contributor users | |
| 257 | 251 | * beyond the primary author. |
| 258 | - * | |
| 259 | - * @since 0.8.0 | |
| 260 | 252 | */ |
| 261 | -function desktop_mode_my_wordpress_register_lock_field() { | |
| 262 | - $types = get_post_types( | |
| 263 | - array( | |
| 264 | - 'show_in_rest' => true, | |
| 265 | - 'public' => true, | |
| 266 | - ), | |
| 267 | - 'names' | |
| 268 | - ); | |
| 253 | +function openstation_my_wordpress_register_lock_field() { | |
| 254 | + $types = openstation_my_wordpress_rest_field_post_types(); | |
| 269 | 255 | |
| 270 | 256 | foreach ( $types as $type ) { |
| 271 | 257 | register_rest_field( |
| 272 | 258 | $type, |
| 273 | - 'desktop_mode_lock', | |
| 259 | + 'openstation_lock', | |
| 274 | 260 | array( |
| 275 | 261 | 'get_callback' => static function ( $post ) { |
| 276 | 262 | $post_id = isset( $post['id'] ) ? (int) $post['id'] : 0; |
| 277 | - return desktop_mode_my_wordpress_post_lock_payload( $post_id ); | |
| 263 | + return openstation_my_wordpress_post_lock_payload( $post_id ); | |
| 278 | 264 | }, |
| 279 | 265 | 'schema' => array( |
| 280 | 266 | 'description' => __( 'Active edit-lock holder, or null when the post is not locked.', 'desktop-mode' ), |
| 281 | 267 | 'type' => array( 'object', 'null' ), |
| @@ -292,16 +278,16 @@ | ||
| 292 | 278 | ); |
| 293 | 279 | |
| 294 | 280 | register_rest_field( |
| 295 | 281 | $type, |
| 296 | - 'desktop_mode_contributors', | |
| 282 | + 'openstation_contributors', | |
| 297 | 283 | array( |
| 298 | 284 | 'get_callback' => static function ( $post ) { |
| 299 | 285 | $post_id = isset( $post['id'] ) ? (int) $post['id'] : 0; |
| 300 | - return desktop_mode_my_wordpress_post_contributors_payload( $post_id ); | |
| 286 | + return openstation_my_wordpress_post_contributors_payload( $post_id ); | |
| 301 | 287 | }, |
| 302 | 288 | 'schema' => array( |
| 303 | - 'description' => __( 'Additional contributor users beyond the primary author. Sourced from Co-Authors Plus when present, revision authors, the `_edit_last` meta, plus anything plugins return via `desktop_mode_my_wordpress_post_contributors`. Empty for requesters who cannot edit the post.', 'desktop-mode' ), | |
| 289 | + 'description' => __( 'Additional contributor users beyond the primary author. Sourced from Co-Authors Plus when present, revision authors, the `_edit_last` meta, plus anything plugins return via `openstation_my_wordpress_post_contributors`. Empty for requesters who cannot edit the post.', 'desktop-mode' ), | |
| 304 | 290 | 'type' => 'array', |
| 305 | 291 | 'context' => array( 'view', 'edit' ), |
| 306 | 292 | 'readonly' => true, |
| 307 | 293 | 'items' => array( |
| @@ -316,5 +302,5 @@ | ||
| 316 | 302 | ) |
| 317 | 303 | ); |
| 318 | 304 | } |
| 319 | 305 | } |
| 320 | -add_action( 'rest_api_init', 'desktop_mode_my_wordpress_register_lock_field' ); | |
| 306 | +add_action( 'rest_api_init', 'openstation_my_wordpress_register_lock_field' ); | |