PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
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.5, at backend/src/Routes/Settings/Settings.php

77 lines 2.7 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 IvyForms\Services\Permissions\RoutePermissionService;
12 use WP_REST_Server;
13
14 class Settings
15 {
16 /**
17 * @throws DependencyException
18 * @throws NotFoundException
19 */
20 public static function registerRoutes(Container $container, string $routeNamespace): void
21 {
22 $routePermissionService = $container->get(RoutePermissionService::class);
23
24 // Get all settings for admin page
25 register_rest_route(
26 $routeNamespace,
27 '/settings/all',
28 [
29 'methods' => WP_REST_Server::READABLE,
30 'callback' => $container->get(GetAllSettingsController::class),
31 'permission_callback' => static function () use ($routePermissionService) {
32 return $routePermissionService->canAccessSettings();
33 }
34 ]
35 );
36
37 // Get specific setting by category/option (for individual API calls)
38 register_rest_route(
39 $routeNamespace,
40 '/setting/(?P<category>[a-zA-Z0-9_-]+)/(?P<option>[a-zA-Z0-9_-]+)',
41 [
42 'methods' => WP_REST_Server::READABLE,
43 'callback' => $container->get(GetSettingController::class),
44 'permission_callback' => static function () use ($routePermissionService) {
45 return $routePermissionService->canAccessSettings();
46 },
47 'args' => [
48 'category' => [
49 'required' => true,
50 'validate_callback' => function ($param) {
51 return is_string($param) && !empty($param);
52 }
53 ],
54 'option' => [
55 'required' => true,
56 'validate_callback' => function ($param) {
57 return is_string($param) && !empty($param);
58 }
59 ]
60 ]
61 ]
62 );
63
64 register_rest_route(
65 $routeNamespace,
66 '/setting/update/',
67 [
68 'methods' => WP_REST_Server::CREATABLE,
69 'callback' => $container->get(UpdateSettingController::class),
70 'permission_callback' => static function () use ($routePermissionService) {
71 return $routePermissionService->canAccessSettings();
72 }
73 ]
74 );
75 }
76 }
77