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

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