PluginProbe
The Innovative Form Builder – IvyForms / 1.0
The Innovative Form Builder – IvyForms v1.0
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Routes / Settings / Settings.php

Settings.php in The Innovative Form Builder – IvyForms 1.0, at backend/src/Routes/Settings/Settings.php

74 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Routes\Settings;
4
5 use IvyForms\Vendor\DI\Container;
6 use IvyForms\Vendor\DI\DependencyException;
7 use IvyForms\Vendor\DI\NotFoundException;
8 use IvyForms\Controllers\Settings\GetAllSettingsController;
9 use IvyForms\Controllers\Settings\GetSettingController;
10 use IvyForms\Controllers\Settings\UpdateSettingController;
11 use WP_REST_Server;
12
13 class Settings
14 {
15 /**
16 * @throws DependencyException
17 * @throws NotFoundException
18 */
19 public static function registerRoutes(Container $container, string $routeNamespace): void
20 {
21 // Get all settings for admin page
22 register_rest_route(
23 $routeNamespace,
24 '/settings/all',
25 [
26 'methods' => WP_REST_Server::READABLE,
27 'callback' => $container->get(GetAllSettingsController::class),
28 'permission_callback' => function () {
29 return current_user_can('manage_options');
30 }
31 ]
32 );
33
34 // Get specific setting by category/option (for individual API calls)
35 register_rest_route(
36 $routeNamespace,
37 '/setting/(?P<category>[a-zA-Z0-9_-]+)/(?P<option>[a-zA-Z0-9_-]+)',
38 [
39 'methods' => WP_REST_Server::READABLE,
40 'callback' => $container->get(GetSettingController::class),
41 'permission_callback' => function () {
42 return current_user_can('manage_options');
43 },
44 'args' => [
45 'category' => [
46 'required' => true,
47 'validate_callback' => function ($param) {
48 return is_string($param) && !empty($param);
49 }
50 ],
51 'option' => [
52 'required' => true,
53 'validate_callback' => function ($param) {
54 return is_string($param) && !empty($param);
55 }
56 ]
57 ]
58 ]
59 );
60
61 register_rest_route(
62 $routeNamespace,
63 '/setting/update/',
64 [
65 'methods' => WP_REST_Server::CREATABLE,
66 'callback' => $container->get(UpdateSettingController::class),
67 'permission_callback' => function () {
68 return current_user_can('manage_options');
69 }
70 ]
71 );
72 }
73 }
74