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
← All changes | backend/src/Routes/Settings/Settings.php +9 -11 0.8 → 1.5 View file →
@@ -1,13 +1,8 @@
1 1 <?php
2 2
3 3 namespace IvyForms\Routes\Settings;
4 4
5 -// phpcs:disable PSR1.Files.SideEffects
6 -if (!defined('ABSPATH')) {
7 - exit; // Exit if accessed directly
8 -}
9 -
10 5 use IvyForms\Vendor\DI\Container;
11 6 use IvyForms\Vendor\DI\DependencyException;
12 7 use IvyForms\Vendor\DI\NotFoundException;
13 8 use IvyForms\Controllers\Settings\GetAllSettingsController;
@@ -12,8 +7,9 @@
12 7 use IvyForms\Vendor\DI\NotFoundException;
13 8 use IvyForms\Controllers\Settings\GetAllSettingsController;
14 9 use IvyForms\Controllers\Settings\GetSettingController;
15 10 use IvyForms\Controllers\Settings\UpdateSettingController;
11 +use IvyForms\Services\Permissions\RoutePermissionService;
16 12 use WP_REST_Server;
17 13
18 14 class Settings
19 15 {
@@ -22,8 +18,10 @@
22 18 * @throws NotFoundException
23 19 */
24 20 public static function registerRoutes(Container $container, string $routeNamespace): void
25 21 {
22 + $routePermissionService = $container->get(RoutePermissionService::class);
23 +
26 24 // Get all settings for admin page
27 25 register_rest_route(
28 26 $routeNamespace,
29 27 '/settings/all',
@@ -29,10 +27,10 @@
29 27 '/settings/all',
30 28 [
31 29 'methods' => WP_REST_Server::READABLE,
32 30 'callback' => $container->get(GetAllSettingsController::class),
33 - 'permission_callback' => function () {
34 - return current_user_can('manage_options');
31 + 'permission_callback' => static function () use ($routePermissionService) {
32 + return $routePermissionService->canAccessSettings();
35 33 }
36 34 ]
37 35 );
38 36
@@ -42,10 +40,10 @@
42 40 '/setting/(?P<category>[a-zA-Z0-9_-]+)/(?P<option>[a-zA-Z0-9_-]+)',
43 41 [
44 42 'methods' => WP_REST_Server::READABLE,
45 43 'callback' => $container->get(GetSettingController::class),
46 - 'permission_callback' => function () {
47 - return current_user_can('manage_options');
44 + 'permission_callback' => static function () use ($routePermissionService) {
45 + return $routePermissionService->canAccessSettings();
48 46 },
49 47 'args' => [
50 48 'category' => [
51 49 'required' => true,
@@ -68,10 +66,10 @@
68 66 '/setting/update/',
69 67 [
70 68 'methods' => WP_REST_Server::CREATABLE,
71 69 'callback' => $container->get(UpdateSettingController::class),
72 - 'permission_callback' => function () {
73 - return current_user_can('manage_options');
70 + 'permission_callback' => static function () use ($routePermissionService) {
71 + return $routePermissionService->canAccessSettings();
74 72 }
75 73 ]
76 74 );
77 75 }