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/games/rest.php +256 -152 0.9.81.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Games REST routes.
3 + * OpenStation — Games REST routes.
4 4 *
5 5 * Namespace `desktop-mode/v1`:
6 6 *
7 7 * GET /games/(?P<game>[a-z0-9_\-]+)/scores Leaderboard (paged).
@@ -18,11 +18,11 @@
18 18 * Permission: every route requires a logged-in user with desktop
19 19 * mode enabled and the `read` capability (subscribers play games
20 20 * too). Unknown game ids 404. Challenge routes additionally verify
21 21 * party membership; sending gates through the
22 - * `desktop_mode_games_can_challenge` filter.
22 + * `openstation_games_can_challenge` filter.
23 23 *
24 - * @package WPDesktopMode
24 + * @package OpenStation
25 25 */
26 26
27 27 defined( 'ABSPATH' ) || exit;
28 28
@@ -28,17 +28,17 @@
28 28
29 29 /**
30 30 * Base permission gate shared by every games route.
31 31 */
32 -function desktop_mode_games_rest_permission() {
32 +function openstation_games_rest_permission() {
33 33 if ( ! is_user_logged_in() ) {
34 - return new WP_Error( 'desktop_mode_games_unauthenticated', __( 'You must be logged in.', 'desktop-mode' ), array( 'status' => 401 ) );
34 + return new WP_Error( 'openstation_games_unauthenticated', __( 'You must be logged in.', 'desktop-mode' ), array( 'status' => 401 ) );
35 35 }
36 - if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled( get_current_user_id() ) ) {
37 - return new WP_Error( 'desktop_mode_games_disabled', __( 'Desktop mode is not enabled for this user.', 'desktop-mode' ), array( 'status' => 403 ) );
36 + if ( function_exists( 'openstation_is_enabled' ) && ! openstation_is_enabled( get_current_user_id() ) ) {
37 + return new WP_Error( 'openstation_games_disabled', __( 'OpenStation is not enabled for this user.', 'desktop-mode' ), array( 'status' => 403 ) );
38 38 }
39 39 if ( ! current_user_can( 'read' ) ) {
40 - return new WP_Error( 'desktop_mode_games_forbidden', __( 'You cannot use desktop games.', 'desktop-mode' ), array( 'status' => 403 ) );
40 + return new WP_Error( 'openstation_games_forbidden', __( 'You cannot use desktop games.', 'desktop-mode' ), array( 'status' => 403 ) );
41 41 }
42 42
43 43 /**
44 44 * Filters the base games REST permission verdict. Return a
@@ -47,14 +47,14 @@
47 47 *
48 48 * @param true|false|WP_Error $allowed Default `true`.
49 49 * @param int $user_id Current user.
50 50 */
51 - $allowed = apply_filters( 'desktop_mode_games_rest_permission', true, get_current_user_id() );
51 + $allowed = apply_filters( 'openstation_games_rest_permission', true, get_current_user_id() );
52 52 if ( is_wp_error( $allowed ) ) {
53 53 return $allowed;
54 54 }
55 55 if ( true !== $allowed ) {
56 - return new WP_Error( 'desktop_mode_games_forbidden', __( 'You cannot use desktop games.', 'desktop-mode' ), array( 'status' => 403 ) );
56 + return new WP_Error( 'openstation_games_forbidden', __( 'You cannot use desktop games.', 'desktop-mode' ), array( 'status' => 403 ) );
57 57 }
58 58 return true;
59 59 }
60 60
@@ -60,106 +60,203 @@
60 60
61 61 /**
62 62 * Register the routes.
63 63 */
64 -function desktop_mode_games_register_rest_routes() {
64 +function openstation_games_register_rest_routes() {
65 65 $ns = 'desktop-mode/v1';
66 66
67 - register_rest_route( $ns, '/games/(?P<game>[a-z0-9_\-]+)/scores', array(
67 + register_rest_route(
68 + $ns,
69 + '/games/(?P<game>[a-z0-9_\-]+)/scores',
68 70 array(
69 - 'methods' => WP_REST_Server::READABLE,
70 - 'permission_callback' => 'desktop_mode_games_rest_permission',
71 - 'callback' => 'desktop_mode_games_rest_list_scores',
72 - 'args' => array(
73 - 'page' => array( 'type' => 'integer', 'default' => 1, 'minimum' => 1 ),
74 - 'per_page' => array( 'type' => 'integer', 'default' => 25, 'minimum' => 1, 'maximum' => 100 ),
75 - 'orderby' => array( 'type' => 'string', 'default' => 'score', 'enum' => array( 'score', 'created' ) ),
76 - 'order' => array( 'type' => 'string', 'default' => 'desc', 'enum' => array( 'asc', 'desc' ) ),
77 - 'user_id' => array( 'type' => 'integer', 'default' => 0 ),
71 + array(
72 + 'methods' => WP_REST_Server::READABLE,
73 + 'permission_callback' => 'openstation_games_rest_permission',
74 + 'callback' => 'openstation_games_rest_list_scores',
75 + 'args' => array(
76 + 'page' => array(
77 + 'type' => 'integer',
78 + 'default' => 1,
79 + 'minimum' => 1,
80 + ),
81 + 'per_page' => array(
82 + 'type' => 'integer',
83 + 'default' => 25,
84 + 'minimum' => 1,
85 + 'maximum' => 100,
86 + ),
87 + 'orderby' => array(
88 + 'type' => 'string',
89 + 'default' => 'score',
90 + 'enum' => array( 'score', 'created' ),
91 + ),
92 + 'order' => array(
93 + 'type' => 'string',
94 + 'default' => 'desc',
95 + 'enum' => array( 'asc', 'desc' ),
96 + ),
97 + 'user_id' => array(
98 + 'type' => 'integer',
99 + 'default' => 0,
100 + ),
101 + ),
78 102 ),
79 - ),
103 + array(
104 + 'methods' => WP_REST_Server::CREATABLE,
105 + 'permission_callback' => 'openstation_games_rest_permission',
106 + 'callback' => 'openstation_games_rest_submit_score',
107 + 'args' => array(
108 + 'score' => array(
109 + 'type' => 'integer',
110 + 'required' => true,
111 + 'minimum' => 0,
112 + ),
113 + 'meta' => array(
114 + 'type' => 'object',
115 + 'default' => array(),
116 + ),
117 + ),
118 + ),
119 + )
120 + );
121 +
122 + register_rest_route(
123 + $ns,
124 + '/games/challenges',
80 125 array(
126 + array(
127 + 'methods' => WP_REST_Server::READABLE,
128 + 'permission_callback' => 'openstation_games_rest_permission',
129 + 'callback' => 'openstation_games_rest_list_challenges',
130 + 'args' => array(
131 + 'box' => array(
132 + 'type' => 'string',
133 + 'default' => 'all',
134 + 'enum' => array( 'incoming', 'outgoing', 'all' ),
135 + ),
136 + 'state' => array(
137 + 'type' => 'string',
138 + 'default' => '',
139 + 'enum' => array( '', 'pending', 'accepted', 'declined', 'completed' ),
140 + ),
141 + ),
142 + ),
143 + array(
144 + 'methods' => WP_REST_Server::CREATABLE,
145 + 'permission_callback' => 'openstation_games_rest_permission',
146 + 'callback' => 'openstation_games_rest_create_challenge',
147 + 'args' => array(
148 + 'game' => array(
149 + 'type' => 'string',
150 + 'required' => true,
151 + ),
152 + 'recipient_id' => array(
153 + 'type' => 'integer',
154 + 'required' => true,
155 + ),
156 + 'score' => array(
157 + 'type' => 'integer',
158 + 'required' => true,
159 + 'minimum' => 0,
160 + ),
161 + 'meta' => array(
162 + 'type' => 'object',
163 + 'default' => array(),
164 + ),
165 + ),
166 + ),
167 + )
168 + );
169 +
170 + register_rest_route(
171 + $ns,
172 + '/games/challenges/(?P<id>\d+)/accept',
173 + array(
81 174 'methods' => WP_REST_Server::CREATABLE,
82 - 'permission_callback' => 'desktop_mode_games_rest_permission',
83 - 'callback' => 'desktop_mode_games_rest_submit_score',
175 + 'permission_callback' => 'openstation_games_rest_permission',
176 + 'callback' => 'openstation_games_rest_accept_challenge',
177 + )
178 + );
179 +
180 + register_rest_route(
181 + $ns,
182 + '/games/challenges/(?P<id>\d+)/decline',
183 + array(
184 + 'methods' => WP_REST_Server::CREATABLE,
185 + 'permission_callback' => 'openstation_games_rest_permission',
186 + 'callback' => 'openstation_games_rest_decline_challenge',
187 + )
188 + );
189 +
190 + register_rest_route(
191 + $ns,
192 + '/games/challenges/(?P<id>\d+)/complete',
193 + array(
194 + 'methods' => WP_REST_Server::CREATABLE,
195 + 'permission_callback' => 'openstation_games_rest_permission',
196 + 'callback' => 'openstation_games_rest_complete_challenge',
84 197 'args' => array(
85 - 'score' => array( 'type' => 'integer', 'required' => true, 'minimum' => 0 ),
86 - 'meta' => array( 'type' => 'object', 'default' => array() ),
198 + 'score' => array(
199 + 'type' => 'integer',
200 + 'required' => true,
201 + 'minimum' => 0,
202 + ),
203 + 'meta' => array(
204 + 'type' => 'object',
205 + 'default' => array(),
206 + ),
87 207 ),
88 - ),
89 - ) );
208 + )
209 + );
90 210
91 - register_rest_route( $ns, '/games/challenges', array(
211 + register_rest_route(
212 + $ns,
213 + '/games/playtime',
92 214 array(
93 215 'methods' => WP_REST_Server::READABLE,
94 - 'permission_callback' => 'desktop_mode_games_rest_permission',
95 - 'callback' => 'desktop_mode_games_rest_list_challenges',
216 + 'permission_callback' => 'openstation_games_rest_permission',
217 + 'callback' => 'openstation_games_rest_get_playtime',
218 + )
219 + );
220 +
221 + register_rest_route(
222 + $ns,
223 + '/games/(?P<game>[a-z0-9_\-]+)/playtime',
224 + array(
225 + 'methods' => WP_REST_Server::CREATABLE,
226 + 'permission_callback' => 'openstation_games_rest_permission',
227 + 'callback' => 'openstation_games_rest_record_playtime',
96 228 'args' => array(
97 - 'box' => array( 'type' => 'string', 'default' => 'all', 'enum' => array( 'incoming', 'outgoing', 'all' ) ),
98 - 'state' => array( 'type' => 'string', 'default' => '', 'enum' => array( '', 'pending', 'accepted', 'declined', 'completed' ) ),
229 + 'seconds' => array(
230 + 'type' => 'integer',
231 + 'required' => true,
232 + 'minimum' => 1,
233 + ),
99 234 ),
100 - ),
235 + )
236 + );
237 +
238 + register_rest_route(
239 + $ns,
240 + '/games/users/search',
101 241 array(
102 - 'methods' => WP_REST_Server::CREATABLE,
103 - 'permission_callback' => 'desktop_mode_games_rest_permission',
104 - 'callback' => 'desktop_mode_games_rest_create_challenge',
242 + 'methods' => WP_REST_Server::READABLE,
243 + 'permission_callback' => 'openstation_games_rest_permission',
244 + 'callback' => 'openstation_games_rest_search_users',
105 245 'args' => array(
106 - 'game' => array( 'type' => 'string', 'required' => true ),
107 - 'recipient_id' => array( 'type' => 'integer', 'required' => true ),
108 - 'score' => array( 'type' => 'integer', 'required' => true, 'minimum' => 0 ),
109 - 'meta' => array( 'type' => 'object', 'default' => array() ),
246 + 'q' => array(
247 + 'type' => 'string',
248 + 'default' => '',
249 + ),
250 + 'exclude' => array(
251 + 'type' => 'string',
252 + 'default' => '',
253 + ),
110 254 ),
111 - ),
112 - ) );
113 -
114 - register_rest_route( $ns, '/games/challenges/(?P<id>\d+)/accept', array(
115 - 'methods' => WP_REST_Server::CREATABLE,
116 - 'permission_callback' => 'desktop_mode_games_rest_permission',
117 - 'callback' => 'desktop_mode_games_rest_accept_challenge',
118 - ) );
119 -
120 - register_rest_route( $ns, '/games/challenges/(?P<id>\d+)/decline', array(
121 - 'methods' => WP_REST_Server::CREATABLE,
122 - 'permission_callback' => 'desktop_mode_games_rest_permission',
123 - 'callback' => 'desktop_mode_games_rest_decline_challenge',
124 - ) );
125 -
126 - register_rest_route( $ns, '/games/challenges/(?P<id>\d+)/complete', array(
127 - 'methods' => WP_REST_Server::CREATABLE,
128 - 'permission_callback' => 'desktop_mode_games_rest_permission',
129 - 'callback' => 'desktop_mode_games_rest_complete_challenge',
130 - 'args' => array(
131 - 'score' => array( 'type' => 'integer', 'required' => true, 'minimum' => 0 ),
132 - 'meta' => array( 'type' => 'object', 'default' => array() ),
133 - ),
134 - ) );
135 -
136 - register_rest_route( $ns, '/games/playtime', array(
137 - 'methods' => WP_REST_Server::READABLE,
138 - 'permission_callback' => 'desktop_mode_games_rest_permission',
139 - 'callback' => 'desktop_mode_games_rest_get_playtime',
140 - ) );
141 -
142 - register_rest_route( $ns, '/games/(?P<game>[a-z0-9_\-]+)/playtime', array(
143 - 'methods' => WP_REST_Server::CREATABLE,
144 - 'permission_callback' => 'desktop_mode_games_rest_permission',
145 - 'callback' => 'desktop_mode_games_rest_record_playtime',
146 - 'args' => array(
147 - 'seconds' => array( 'type' => 'integer', 'required' => true, 'minimum' => 1 ),
148 - ),
149 - ) );
150 -
151 - register_rest_route( $ns, '/games/users/search', array(
152 - 'methods' => WP_REST_Server::READABLE,
153 - 'permission_callback' => 'desktop_mode_games_rest_permission',
154 - 'callback' => 'desktop_mode_games_rest_search_users',
155 - 'args' => array(
156 - 'q' => array( 'type' => 'string', 'default' => '' ),
157 - 'exclude' => array( 'type' => 'string', 'default' => '' ),
158 - ),
159 - ) );
255 + )
256 + );
160 257 }
161 -add_action( 'rest_api_init', 'desktop_mode_games_register_rest_routes' );
258 +add_action( 'rest_api_init', 'openstation_games_register_rest_routes' );
162 259
163 260 /**
164 261 * Resolve + validate the `game` path param. 404s unknown ids so the
165 262 * scores surface doesn't leak which games exist server-side.
@@ -168,13 +265,13 @@
168 265 *
169 266 * @param WP_REST_Request $req Request.
170 267 * @return string|WP_Error The sanitized game id.
171 268 */
172 -function desktop_mode_games_rest_resolve_game( WP_REST_Request $req ) {
269 +function openstation_games_rest_resolve_game( WP_REST_Request $req ) {
173 270 $game = sanitize_key( (string) $req->get_param( 'game' ) );
174 - if ( '' === $game || ! desktop_mode_games_is_registered( $game ) ) {
271 + if ( '' === $game || ! openstation_games_is_registered( $game ) ) {
175 272 return new WP_Error(
176 - 'desktop_mode_unknown_game',
273 + 'openstation_unknown_game',
177 274 __( 'Unknown game.', 'desktop-mode' ),
178 275 array( 'status' => 404 )
179 276 );
180 277 }
@@ -183,24 +280,29 @@
183 280
184 281 /**
185 282 * GET /games/{game}/scores
186 283 */
187 -function desktop_mode_games_rest_list_scores( WP_REST_Request $req ) {
188 - $game = desktop_mode_games_rest_resolve_game( $req );
284 +function openstation_games_rest_list_scores( WP_REST_Request $req ) {
285 + $game = openstation_games_rest_resolve_game( $req );
189 286 if ( is_wp_error( $game ) ) {
190 287 return $game;
191 288 }
192 - $result = desktop_mode_games_get_scores( $game, array(
193 - 'page' => (int) $req->get_param( 'page' ),
194 - 'per_page' => (int) $req->get_param( 'per_page' ),
195 - 'orderby' => (string) $req->get_param( 'orderby' ),
196 - 'order' => (string) $req->get_param( 'order' ),
197 - 'user_id' => (int) $req->get_param( 'user_id' ),
198 - ) );
199 - return rest_ensure_response( array(
200 - 'scores' => $result['rows'],
201 - 'total' => $result['total'],
202 - ) );
289 + $result = openstation_games_get_scores(
290 + $game,
291 + array(
292 + 'page' => (int) $req->get_param( 'page' ),
293 + 'per_page' => (int) $req->get_param( 'per_page' ),
294 + 'orderby' => (string) $req->get_param( 'orderby' ),
295 + 'order' => (string) $req->get_param( 'order' ),
296 + 'user_id' => (int) $req->get_param( 'user_id' ),
297 + )
298 + );
299 + return rest_ensure_response(
300 + array(
301 + 'scores' => $result['rows'],
302 + 'total' => $result['total'],
303 + )
304 + );
203 305 }
204 306
205 307 /**
206 308 * POST /games/{game}/scores — always records for the current user;
@@ -205,14 +307,14 @@
205 307 /**
206 308 * POST /games/{game}/scores — always records for the current user;
207 309 * there is no way to submit a score on someone else's behalf.
208 310 */
209 -function desktop_mode_games_rest_submit_score( WP_REST_Request $req ) {
210 - $game = desktop_mode_games_rest_resolve_game( $req );
311 +function openstation_games_rest_submit_score( WP_REST_Request $req ) {
312 + $game = openstation_games_rest_resolve_game( $req );
211 313 if ( is_wp_error( $game ) ) {
212 314 return $game;
213 315 }
214 - $id = desktop_mode_games_save_score(
316 + $id = openstation_games_save_score(
215 317 $game,
216 318 get_current_user_id(),
217 319 (int) $req->get_param( 'score' ),
218 320 (array) $req->get_param( 'meta' )
@@ -225,20 +327,22 @@
225 327
226 328 /**
227 329 * GET /games/playtime — the current user's `game id => seconds` map.
228 330 */
229 -function desktop_mode_games_rest_get_playtime() {
331 +function openstation_games_rest_get_playtime() {
230 332 $user_id = get_current_user_id();
231 333 // Day maps are cast per-game so empty buckets JSON-encode as `{}`.
232 334 $daily = array();
233 - foreach ( desktop_mode_games_get_playtime_daily( $user_id ) as $game => $days ) {
335 + foreach ( openstation_games_get_playtime_daily( $user_id ) as $game => $days ) {
234 336 $daily[ $game ] = (object) $days;
235 337 }
236 - return rest_ensure_response( array(
237 - 'playtime' => (object) desktop_mode_games_get_playtime( $user_id ),
238 - 'daily' => (object) $daily,
239 - 'today' => desktop_mode_games_playtime_today_key(),
240 - ) );
338 + return rest_ensure_response(
339 + array(
340 + 'playtime' => (object) openstation_games_get_playtime( $user_id ),
341 + 'daily' => (object) $daily,
342 + 'today' => openstation_games_playtime_today_key(),
343 + )
344 + );
241 345 }
242 346
243 347 /**
244 348 * POST /games/{game}/playtime — always records for the current user;
@@ -243,14 +347,14 @@
243 347 /**
244 348 * POST /games/{game}/playtime — always records for the current user;
245 349 * there is no way to record play time on someone else's behalf.
246 350 */
247 -function desktop_mode_games_rest_record_playtime( WP_REST_Request $req ) {
248 - $game = desktop_mode_games_rest_resolve_game( $req );
351 +function openstation_games_rest_record_playtime( WP_REST_Request $req ) {
352 + $game = openstation_games_rest_resolve_game( $req );
249 353 if ( is_wp_error( $game ) ) {
250 354 return $game;
251 355 }
252 - $total = desktop_mode_games_add_playtime(
356 + $total = openstation_games_add_playtime(
253 357 $game,
254 358 get_current_user_id(),
255 359 (int) $req->get_param( 'seconds' )
256 360 );
@@ -262,14 +366,14 @@
262 366
263 367 /**
264 368 * GET /games/challenges — challenges involving the current user.
265 369 */
266 -function desktop_mode_games_rest_list_challenges( WP_REST_Request $req ) {
370 +function openstation_games_rest_list_challenges( WP_REST_Request $req ) {
267 371 $user_id = get_current_user_id();
268 372 $box = (string) $req->get_param( 'box' );
269 373 $state = (string) $req->get_param( 'state' );
270 374
271 - $rows = desktop_mode_games_get_challenges_for_user( $user_id, 0, 100 );
375 + $rows = openstation_games_get_challenges_for_user( $user_id, 0, 100 );
272 376 $out = array();
273 377 foreach ( $rows as $row ) {
274 378 if ( 'incoming' === $box && (int) $row['recipient_id'] !== $user_id ) {
275 379 continue;
@@ -279,9 +383,9 @@
279 383 }
280 384 if ( '' !== $state && $row['state'] !== $state ) {
281 385 continue;
282 386 }
283 - $out[] = desktop_mode_games_shape_challenge( $row );
387 + $out[] = openstation_games_shape_challenge( $row );
284 388 }
285 389 // Newest change first for the inbox view.
286 390 $out = array_reverse( $out );
287 391 return rest_ensure_response( array( 'challenges' => $out ) );
@@ -289,16 +393,16 @@
289 393
290 394 /**
291 395 * POST /games/challenges
292 396 */
293 -function desktop_mode_games_rest_create_challenge( WP_REST_Request $req ) {
397 +function openstation_games_rest_create_challenge( WP_REST_Request $req ) {
294 398 $challenger_id = get_current_user_id();
295 399 $recipient_id = (int) $req->get_param( 'recipient_id' );
296 400 $game = sanitize_key( (string) $req->get_param( 'game' ) );
297 401
298 - if ( ! desktop_mode_games_is_registered( $game ) ) {
402 + if ( ! openstation_games_is_registered( $game ) ) {
299 403 return new WP_Error(
300 - 'desktop_mode_unknown_game',
404 + 'openstation_unknown_game',
301 405 __( 'Unknown game.', 'desktop-mode' ),
302 406 array( 'status' => 404 )
303 407 );
304 408 }
@@ -312,21 +416,21 @@
312 416 * @param int $challenger_id Sender.
313 417 * @param int $recipient_id Receiver.
314 418 * @param string $game Game id.
315 419 */
316 - $allowed = apply_filters( 'desktop_mode_games_can_challenge', true, $challenger_id, $recipient_id, $game );
420 + $allowed = apply_filters( 'openstation_games_can_challenge', true, $challenger_id, $recipient_id, $game );
317 421 if ( is_wp_error( $allowed ) ) {
318 422 return $allowed;
319 423 }
320 424 if ( true !== $allowed ) {
321 425 return new WP_Error(
322 - 'desktop_mode_challenge_blocked',
426 + 'openstation_challenge_blocked',
323 427 __( 'You cannot challenge this user.', 'desktop-mode' ),
324 428 array( 'status' => 403 )
325 429 );
326 430 }
327 431
328 - $id = desktop_mode_games_create_challenge(
432 + $id = openstation_games_create_challenge(
329 433 $game,
330 434 $challenger_id,
331 435 $recipient_id,
332 436 (int) $req->get_param( 'score' ),
@@ -334,10 +438,10 @@
334 438 );
335 439 if ( is_wp_error( $id ) ) {
336 440 return $id;
337 441 }
338 - $row = desktop_mode_games_get_challenge( $id );
339 - return rest_ensure_response( array( 'challenge' => desktop_mode_games_shape_challenge( $row ) ) );
442 + $row = openstation_games_get_challenge( $id );
443 + return rest_ensure_response( array( 'challenge' => openstation_games_shape_challenge( $row ) ) );
340 444 }
341 445
342 446 /**
343 447 * Load a challenge and verify the current user is its recipient.
@@ -346,20 +450,20 @@
346 450 *
347 451 * @param WP_REST_Request $req Request.
348 452 * @return array|WP_Error The raw challenge row.
349 453 */
350 -function desktop_mode_games_rest_resolve_recipient_challenge( WP_REST_Request $req ) {
351 - $row = desktop_mode_games_get_challenge( (int) $req->get_param( 'id' ) );
454 +function openstation_games_rest_resolve_recipient_challenge( WP_REST_Request $req ) {
455 + $row = openstation_games_get_challenge( (int) $req->get_param( 'id' ) );
352 456 if ( ! $row ) {
353 457 return new WP_Error(
354 - 'desktop_mode_challenge_not_found',
458 + 'openstation_challenge_not_found',
355 459 __( 'Challenge not found.', 'desktop-mode' ),
356 460 array( 'status' => 404 )
357 461 );
358 462 }
359 - if ( (int) $row['recipient_id'] !== get_current_user_id() ) {
463 + if ( get_current_user_id() !== (int) $row['recipient_id'] ) {
360 464 return new WP_Error(
361 - 'desktop_mode_challenge_forbidden',
465 + 'openstation_challenge_forbidden',
362 466 __( 'Only the challenged user can act on this challenge.', 'desktop-mode' ),
363 467 array( 'status' => 403 )
364 468 );
365 469 }
@@ -368,46 +472,46 @@
368 472
369 473 /**
370 474 * POST /games/challenges/{id}/accept
371 475 */
372 -function desktop_mode_games_rest_accept_challenge( WP_REST_Request $req ) {
373 - $row = desktop_mode_games_rest_resolve_recipient_challenge( $req );
476 +function openstation_games_rest_accept_challenge( WP_REST_Request $req ) {
477 + $row = openstation_games_rest_resolve_recipient_challenge( $req );
374 478 if ( is_wp_error( $row ) ) {
375 479 return $row;
376 480 }
377 - $result = desktop_mode_games_set_challenge_state( (int) $row['id'], 'accepted' );
481 + $result = openstation_games_set_challenge_state( (int) $row['id'], 'accepted' );
378 482 if ( is_wp_error( $result ) ) {
379 483 return $result;
380 484 }
381 - $updated = desktop_mode_games_get_challenge( (int) $row['id'] );
382 - return rest_ensure_response( array( 'challenge' => desktop_mode_games_shape_challenge( $updated ) ) );
485 + $updated = openstation_games_get_challenge( (int) $row['id'] );
486 + return rest_ensure_response( array( 'challenge' => openstation_games_shape_challenge( $updated ) ) );
383 487 }
384 488
385 489 /**
386 490 * POST /games/challenges/{id}/decline
387 491 */
388 -function desktop_mode_games_rest_decline_challenge( WP_REST_Request $req ) {
389 - $row = desktop_mode_games_rest_resolve_recipient_challenge( $req );
492 +function openstation_games_rest_decline_challenge( WP_REST_Request $req ) {
493 + $row = openstation_games_rest_resolve_recipient_challenge( $req );
390 494 if ( is_wp_error( $row ) ) {
391 495 return $row;
392 496 }
393 - $result = desktop_mode_games_set_challenge_state( (int) $row['id'], 'declined' );
497 + $result = openstation_games_set_challenge_state( (int) $row['id'], 'declined' );
394 498 if ( is_wp_error( $result ) ) {
395 499 return $result;
396 500 }
397 - $updated = desktop_mode_games_get_challenge( (int) $row['id'] );
398 - return rest_ensure_response( array( 'challenge' => desktop_mode_games_shape_challenge( $updated ) ) );
501 + $updated = openstation_games_get_challenge( (int) $row['id'] );
502 + return rest_ensure_response( array( 'challenge' => openstation_games_shape_challenge( $updated ) ) );
399 503 }
400 504
401 505 /**
402 506 * POST /games/challenges/{id}/complete
403 507 */
404 -function desktop_mode_games_rest_complete_challenge( WP_REST_Request $req ) {
405 - $row = desktop_mode_games_rest_resolve_recipient_challenge( $req );
508 +function openstation_games_rest_complete_challenge( WP_REST_Request $req ) {
509 + $row = openstation_games_rest_resolve_recipient_challenge( $req );
406 510 if ( is_wp_error( $row ) ) {
407 511 return $row;
408 512 }
409 - $updated = desktop_mode_games_complete_challenge(
513 + $updated = openstation_games_complete_challenge(
410 514 (int) $row['id'],
411 515 (int) $req->get_param( 'score' ),
412 516 (array) $req->get_param( 'meta' )
413 517 );
@@ -413,9 +517,9 @@
413 517 );
414 518 if ( is_wp_error( $updated ) ) {
415 519 return $updated;
416 520 }
417 - return rest_ensure_response( array( 'challenge' => desktop_mode_games_shape_challenge( $updated ) ) );
521 + return rest_ensure_response( array( 'challenge' => openstation_games_shape_challenge( $updated ) ) );
418 522 }
419 523
420 524 /**
421 525 * GET /games/users/search?q=<>&exclude=<csv> — autocomplete for the
@@ -421,9 +525,9 @@
421 525 * GET /games/users/search?q=<>&exclude=<csv> — autocomplete for the
422 526 * opponent picker. Thin sibling of the folder-share picker, gated on
423 527 * `read` instead of `edit_posts` so subscribers can be challenged.
424 528 */
425 -function desktop_mode_games_rest_search_users( WP_REST_Request $req ) {
529 +function openstation_games_rest_search_users( WP_REST_Request $req ) {
426 530 $q = trim( (string) $req->get_param( 'q' ) );
427 531 $exclude = array_filter( array_map( 'intval', explode( ',', (string) $req->get_param( 'exclude' ) ) ) );
428 532
429 533 // Always exclude the current viewer — self-challenges are
@@ -448,9 +552,9 @@
448 552 *
449 553 * @param array $args Default args.
450 554 * @param array $req Request params (`q`, `exclude`).
451 555 */
452 - $args = (array) apply_filters( 'desktop_mode_games_user_query_args', $args, $req->get_params() );
556 + $args = (array) apply_filters( 'openstation_games_user_query_args', $args, $req->get_params() );
453 557
454 558 $query = new WP_User_Query( $args );
455 559 $users = $query->get_results();
456 560 $out = array();