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/recycle-bin/rest.php +32 -53 0.9.71.1.10 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Recycle Bin: REST routes.
3 + * OpenStation — Recycle Bin: REST routes.
4 4 *
5 5 * Five routes, all under `/desktop-mode/v1/recycle-bin`:
6 6 *
7 7 * GET / — list trashed items
@@ -9,14 +9,13 @@
9 9 * POST /purge — body { ids: int[] }
10 10 * POST /empty — empties the visible bin
11 11 * GET /count — total items in the bin (badge polling)
12 12 *
13 - * Permission gating delegates to `desktop_mode_recycle_bin_user_can_*` per item;
13 + * Permission gating delegates to `openstation_recycle_bin_user_can_*` per item;
14 14 * the route-level callback only checks "are you logged in and in
15 - * desktop mode at all?" via `desktop_mode_is_enabled()`.
15 + * OpenStation at all?" via `openstation_is_enabled()`.
16 16 *
17 - * @package WPDesktopMode
18 - * @since 0.6.0
17 + * @package OpenStation
19 18 */
20 19
21 20 defined( 'ABSPATH' ) || exit;
22 21
@@ -21,12 +20,10 @@
21 20 defined( 'ABSPATH' ) || exit;
22 21
23 22 /**
24 23 * Register REST routes.
25 - *
26 - * @since 0.6.0
27 24 */
28 -function desktop_mode_recycle_bin_register_rest_routes() {
25 +function openstation_recycle_bin_register_rest_routes() {
29 26 $namespace = 'desktop-mode/v1';
30 27
31 28 register_rest_route(
32 29 $namespace,
@@ -32,10 +29,10 @@
32 29 $namespace,
33 30 '/recycle-bin',
34 31 array(
35 32 'methods' => WP_REST_Server::READABLE,
36 - 'permission_callback' => 'desktop_mode_recycle_bin_rest_permission',
37 - 'callback' => 'desktop_mode_recycle_bin_rest_list',
33 + 'permission_callback' => 'openstation_recycle_bin_rest_permission',
34 + 'callback' => 'openstation_recycle_bin_rest_list',
38 35 'args' => array(
39 36 'page' => array(
40 37 'type' => 'integer',
41 38 'default' => 1,
@@ -64,10 +61,10 @@
64 61 $namespace,
65 62 '/recycle-bin/restore',
66 63 array(
67 64 'methods' => WP_REST_Server::CREATABLE,
68 - 'permission_callback' => 'desktop_mode_recycle_bin_rest_permission',
69 - 'callback' => 'desktop_mode_recycle_bin_rest_restore',
65 + 'permission_callback' => 'openstation_recycle_bin_rest_permission',
66 + 'callback' => 'openstation_recycle_bin_rest_restore',
70 67 // Accepts either `items: [{id, type}]` (preferred) or
71 68 // `ids: int[]` (legacy — assumes post-ish entities).
72 69 // Both registered as optional; the handler validates.
73 70 'args' => array(
@@ -88,10 +85,10 @@
88 85 $namespace,
89 86 '/recycle-bin/purge',
90 87 array(
91 88 'methods' => WP_REST_Server::CREATABLE,
92 - 'permission_callback' => 'desktop_mode_recycle_bin_rest_permission',
93 - 'callback' => 'desktop_mode_recycle_bin_rest_purge',
89 + 'permission_callback' => 'openstation_recycle_bin_rest_permission',
90 + 'callback' => 'openstation_recycle_bin_rest_purge',
94 91 'args' => array(
95 92 'items' => array(
96 93 'type' => 'array',
97 94 'required' => false,
@@ -109,10 +106,10 @@
109 106 $namespace,
110 107 '/recycle-bin/empty',
111 108 array(
112 109 'methods' => WP_REST_Server::CREATABLE,
113 - 'permission_callback' => 'desktop_mode_recycle_bin_rest_permission',
114 - 'callback' => 'desktop_mode_recycle_bin_rest_empty',
110 + 'permission_callback' => 'openstation_recycle_bin_rest_permission',
111 + 'callback' => 'openstation_recycle_bin_rest_empty',
115 112 )
116 113 );
117 114
118 115 register_rest_route(
@@ -119,31 +116,29 @@
119 116 $namespace,
120 117 '/recycle-bin/count',
121 118 array(
122 119 'methods' => WP_REST_Server::READABLE,
123 - 'permission_callback' => 'desktop_mode_recycle_bin_rest_permission',
120 + 'permission_callback' => 'openstation_recycle_bin_rest_permission',
124 121 'callback' => static function () {
125 122 return rest_ensure_response(
126 - array( 'count' => desktop_mode_recycle_bin_count() )
123 + array( 'count' => openstation_recycle_bin_count() )
127 124 );
128 125 },
129 126 )
130 127 );
131 128 }
132 -add_action( 'rest_api_init', 'desktop_mode_recycle_bin_register_rest_routes' );
129 +add_action( 'rest_api_init', 'openstation_recycle_bin_register_rest_routes' );
133 130
134 131 /**
135 132 * Route-level permission gate.
136 133 *
137 134 * Per-item capability checks happen inside the store layer; here we
138 - * only enforce "logged-in user with desktop mode opted in" — same
135 + * only enforce "logged-in user with OpenStation opted in" — same
139 136 * baseline as every other desktop REST surface.
140 137 *
141 - * @since 0.6.0
142 - *
143 138 * @return bool|WP_Error
144 139 */
145 -function desktop_mode_recycle_bin_rest_permission() {
140 +function openstation_recycle_bin_rest_permission() {
146 141 if ( ! is_user_logged_in() ) {
147 142 return new WP_Error(
148 143 'rest_forbidden',
149 144 __( 'Sorry, you must be logged in.', 'desktop-mode' ),
@@ -149,12 +144,12 @@
149 144 __( 'Sorry, you must be logged in.', 'desktop-mode' ),
150 145 array( 'status' => 401 )
151 146 );
152 147 }
153 - if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) {
148 + if ( function_exists( 'openstation_is_enabled' ) && ! openstation_is_enabled() ) {
154 149 return new WP_Error(
155 150 'rest_forbidden',
156 - __( 'Desktop mode is not enabled for this user.', 'desktop-mode' ),
151 + __( 'OpenStation is not enabled for this user.', 'desktop-mode' ),
157 152 array( 'status' => 403 )
158 153 );
159 154 }
160 155 return true;
@@ -162,15 +157,13 @@
162 157
163 158 /**
164 159 * GET /recycle-bin
165 160 *
166 - * @since 0.6.0
167 - *
168 161 * @param WP_REST_Request $request REST request.
169 162 * @return WP_REST_Response
170 163 */
171 -function desktop_mode_recycle_bin_rest_list( $request ) {
172 - $payload = desktop_mode_recycle_bin_get_items(
164 +function openstation_recycle_bin_rest_list( $request ) {
165 + $payload = openstation_recycle_bin_get_items(
173 166 array(
174 167 'page' => (int) $request->get_param( 'page' ),
175 168 'per_page' => (int) $request->get_param( 'per_page' ),
176 169 'type' => (string) $request->get_param( 'type' ),
@@ -183,29 +176,25 @@
183 176
184 177 /**
185 178 * POST /recycle-bin/restore
186 179 *
187 - * @since 0.6.0
188 - *
189 180 * @param WP_REST_Request $request REST request.
190 181 * @return WP_REST_Response
191 182 */
192 -function desktop_mode_recycle_bin_rest_restore( $request ) {
193 - $items = desktop_mode_recycle_bin_normalize_items( $request );
194 - return rest_ensure_response( desktop_mode_recycle_bin_apply_bulk( $items, 'desktop_mode_recycle_bin_restore' ) );
183 +function openstation_recycle_bin_rest_restore( $request ) {
184 + $items = openstation_recycle_bin_normalize_items( $request );
185 + return rest_ensure_response( openstation_recycle_bin_apply_bulk( $items, 'openstation_recycle_bin_restore' ) );
195 186 }
196 187
197 188 /**
198 189 * POST /recycle-bin/purge
199 190 *
200 - * @since 0.6.0
201 - *
202 191 * @param WP_REST_Request $request REST request.
203 192 * @return WP_REST_Response
204 193 */
205 -function desktop_mode_recycle_bin_rest_purge( $request ) {
206 - $items = desktop_mode_recycle_bin_normalize_items( $request );
207 - return rest_ensure_response( desktop_mode_recycle_bin_apply_bulk( $items, 'desktop_mode_recycle_bin_purge' ) );
194 +function openstation_recycle_bin_rest_purge( $request ) {
195 + $items = openstation_recycle_bin_normalize_items( $request );
196 + return rest_ensure_response( openstation_recycle_bin_apply_bulk( $items, 'openstation_recycle_bin_purge' ) );
208 197 }
209 198
210 199 /**
211 200 * Read either `items: [{id, type}]` (preferred) or `ids: int[]`
@@ -211,14 +200,12 @@
211 200 * Read either `items: [{id, type}]` (preferred) or `ids: int[]`
212 201 * (legacy) and normalise into a list of `[id, type]` pairs the
213 202 * bulk runner can hand straight to a typed callback.
214 203 *
215 - * @since 0.6.0
216 - *
217 204 * @param WP_REST_Request $request REST request.
218 205 * @return array<int, array{id:int, type:string}>
219 206 */
220 -function desktop_mode_recycle_bin_normalize_items( $request ) {
207 +function openstation_recycle_bin_normalize_items( $request ) {
221 208 $out = array();
222 209
223 210 $items = $request->get_param( 'items' );
224 211 if ( is_array( $items ) ) {
@@ -256,30 +243,22 @@
256 243
257 244 /**
258 245 * POST /recycle-bin/empty
259 246 *
260 - * @since 0.6.0
261 - *
262 247 * @return WP_REST_Response
263 248 */
264 -function desktop_mode_recycle_bin_rest_empty() {
265 - return rest_ensure_response( desktop_mode_recycle_bin_empty() );
249 +function openstation_recycle_bin_rest_empty() {
250 + return rest_ensure_response( openstation_recycle_bin_empty() );
266 251 }
267 252
268 253 /**
269 254 * Run a per-item callback over a list, capturing per-item results.
270 255 *
271 - * @since 0.6.0
272 - * @since 0.6.0 `$items` now carries `{id, type}` pairs; the
273 - * callback receives both arguments. Legacy id-only
274 - * callers go through `desktop_mode_recycle_bin_normalize_items`,
275 - * which fills `type` with `''` (post default).
276 - *
277 256 * @param array<int, array{id:int, type:string}> $items Items to operate on.
278 257 * @param callable $callback `($id, $type) → true|WP_Error`.
279 258 * @return array{ok:int[], errors:array<int, array{id:int, code:string, message:string}>}
280 259 */
281 -function desktop_mode_recycle_bin_apply_bulk( $items, $callback ) {
260 +function openstation_recycle_bin_apply_bulk( $items, $callback ) {
282 261 $ok = array();
283 262 $errors = array();
284 263
285 264 foreach ( $items as $item ) {