| @@ -1,14 +1,21 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * OpenStation — Desktop-theme REST routes. |
| 4 | 4 | * |
| 5 | + * GET /desktop-mode/v1/desktop-themes full entries | |
| 5 | 6 | * POST /desktop-mode/v1/desktop-themes multipart `file` |
| 6 | 7 | * DELETE /desktop-mode/v1/desktop-themes/<slug> |
| 7 | 8 | * |
| 8 | - * There is deliberately no GET: the library rides the shell payload | |
| 9 | - * (`serverDesktopThemes`), so a separate read route would be a | |
| 10 | - * second source of truth to keep in sync for no gain. | |
| 9 | + * The GET exists for the boot-payload diet, and it is NOT a second | |
| 10 | + * source of truth: it returns exactly | |
| 11 | + * `openstation_build_desktop_themes_payload()` — the same builder, | |
| 12 | + * the same `openstation_desktop_themes` filter — with the FULL | |
| 13 | + * entries. The boot payload ships the library slimmed (no `cssText`, | |
| 14 | + * no `tokens`; `cssDeferred: true` marks the gap) because the active | |
| 15 | + * theme's stylesheet is server-delivered at boot and an inactive | |
| 16 | + * theme's ~20 KB of compiled CSS is only needed at the moment the | |
| 17 | + * user picks it — which is when the shell calls this route. | |
| 11 | 18 | * |
| 12 | 19 | * @package OpenStation |
| 13 | 20 | */ |
| 14 | 21 | |
| @@ -42,12 +49,23 @@ | ||
| 42 | 49 | register_rest_route( |
| 43 | 50 | 'desktop-mode/v1', |
| 44 | 51 | '/desktop-themes', |
| 45 | 52 | array( |
| 46 | - // POST only — PHP populates `$_FILES` for real POSTs only. | |
| 47 | - 'methods' => WP_REST_Server::CREATABLE, | |
| 48 | - 'permission_callback' => 'openstation_desktop_themes_rest_permission', | |
| 49 | - 'callback' => 'openstation_rest_upload_desktop_theme', | |
| 53 | + array( | |
| 54 | + // Read gate is the shell's own, NOT the manage | |
| 55 | + // capability: the same full entries used to ride the | |
| 56 | + // boot payload to every desktop user, so the route | |
| 57 | + // exposes nothing the payload didn't. | |
| 58 | + 'methods' => WP_REST_Server::READABLE, | |
| 59 | + 'permission_callback' => 'openstation_rest_require_enabled', | |
| 60 | + 'callback' => 'openstation_rest_list_desktop_themes', | |
| 61 | + ), | |
| 62 | + array( | |
| 63 | + // POST only — PHP populates `$_FILES` for real POSTs only. | |
| 64 | + 'methods' => WP_REST_Server::CREATABLE, | |
| 65 | + 'permission_callback' => 'openstation_desktop_themes_rest_permission', | |
| 66 | + 'callback' => 'openstation_rest_upload_desktop_theme', | |
| 67 | + ), | |
| 50 | 68 | ) |
| 51 | 69 | ); |
| 52 | 70 | |
| 53 | 71 | register_rest_route( |
| @@ -66,8 +84,27 @@ | ||
| 66 | 84 | ) |
| 67 | 85 | ); |
| 68 | 86 | } |
| 69 | 87 | add_action( 'rest_api_init', 'openstation_register_desktop_themes_rest_routes' ); |
| 88 | + | |
| 89 | +/** | |
| 90 | + * GET /desktop-themes — the full theme library. | |
| 91 | + * | |
| 92 | + * The on-demand counterpart of the slimmed boot payload: same | |
| 93 | + * builder, same filter, full `cssText` / `tokens`. The shell calls | |
| 94 | + * it from `ensureFullDesktopThemes()` the first time a deferred | |
| 95 | + * entry's stylesheet is actually needed (the user picks a theme in | |
| 96 | + * Preferences → Themes). | |
| 97 | + * | |
| 98 | + * @return WP_REST_Response | |
| 99 | + */ | |
| 100 | +function openstation_rest_list_desktop_themes() { | |
| 101 | + return rest_ensure_response( | |
| 102 | + array( | |
| 103 | + 'themes' => openstation_build_desktop_themes_payload(), | |
| 104 | + ) | |
| 105 | + ); | |
| 106 | +} | |
| 70 | 107 | |
| 71 | 108 | /** |
| 72 | 109 | * POST /desktop-mode/v1/desktop-themes |
| 73 | 110 | * |