PluginProbe
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO / 2.11.0
ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO v2.11.0
2.11.0 2.10.0 2.9.0 2.8.0 2.7.0 2.6.0 2.5.0 2.4.0 2.3.0 2.2.0 2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.32.0 1.31.0 1.30.0 1.29.0 1.28.0 1.27.0 1.26.0 1.25.0 trunk 1.0.0 All 52 releases
thinkrank / includes / api / class-ui-mode-endpoint.php

class-ui-mode-endpoint.php in ThinkRank AI SEO – AI SEO Plugin for WordPress: Schema, XML Sitemaps, Meta Tags, Search Console & Local SEO 2.11.0, at includes/api/class-ui-mode-endpoint.php

75 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Simple / Advanced mode REST endpoint.
4 *
5 * - POST /thinkrank/v1/ui-mode { mode: simple|advanced } → the stored mode
6 *
7 * @package ThinkRank\API
8 * @since 2.11.0
9 */
10
11 declare(strict_types=1);
12
13 namespace ThinkRank\API;
14
15 use ThinkRank\Admin\UI_Mode;
16 use WP_Error;
17 use WP_REST_Request;
18 use WP_REST_Response;
19
20 // Prevent direct access
21 if (!defined('ABSPATH')) {
22 exit;
23 }
24
25 /**
26 * UI mode endpoint (#730).
27 *
28 * The current user's own preference, so anyone who can open ThinkRank may set
29 * it — the Role Manager's namespace gate already requires that. The mode is
30 * read from the localized `thinkrankAdmin.uiMode`, so there is no GET.
31 *
32 * @since 2.11.0
33 */
34 class UI_Mode_Endpoint {
35
36 /**
37 * Register routes.
38 *
39 * @return void
40 */
41 public function register_routes(): void {
42 register_rest_route('thinkrank/v1', '/ui-mode', [
43 'methods' => 'POST',
44 'callback' => [$this, 'save'],
45 'permission_callback' => static fn(): bool => is_user_logged_in(),
46 'args' => [
47 'mode' => [
48 'type' => 'string',
49 'enum' => UI_Mode::MODES,
50 'required' => true,
51 ],
52 ],
53 ]);
54 }
55
56 /**
57 * POST /ui-mode.
58 *
59 * @param WP_REST_Request $request Request.
60 * @return WP_REST_Response|WP_Error
61 */
62 public function save(WP_REST_Request $request) {
63 $stored = UI_Mode::set((string) $request->get_param('mode'));
64
65 if (null === $stored) {
66 return new WP_Error('thinkrank_ui_mode_invalid', __('Unknown mode.', 'thinkrank'), ['status' => 400]);
67 }
68
69 return new WP_REST_Response([
70 'success' => true,
71 'data' => ['mode' => $stored],
72 ], 200);
73 }
74 }
75