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/Template/Template.php +8 -11 0.5 → 1.5 View file →
@@ -1,13 +1,8 @@
1 1 <?php
2 2
3 3 namespace IvyForms\Routes\Template;
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\Form\AddFormController;
@@ -12,8 +7,9 @@
12 7 use IvyForms\Vendor\DI\NotFoundException;
13 8 use IvyForms\Controllers\Form\AddFormController;
14 9 use IvyForms\Controllers\Template\GetTemplatesController;
15 10 use IvyForms\Controllers\Template\GetTemplateController;
11 +use IvyForms\Services\Permissions\RoutePermissionService;
16 12 use WP_REST_Server;
17 13
18 14 class Template
19 15 {
@@ -22,8 +18,9 @@
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);
26 23 // Get all templates
27 24 register_rest_route(
28 25 $routeNamespace,
29 26 '/templates',
@@ -29,10 +26,10 @@
29 26 '/templates',
30 27 [
31 28 'methods' => WP_REST_Server::READABLE,
32 29 'callback' => $container->get(GetTemplatesController::class),
33 - 'permission_callback' => function () {
34 - return current_user_can('manage_options');
30 + 'permission_callback' => static function () use ($routePermissionService) {
31 + return $routePermissionService->canViewForms();
35 32 }
36 33 ]
37 34 );
38 35
@@ -42,10 +39,10 @@
42 39 '/template/(?P<id>[a-zA-Z0-9_-]+)',
43 40 [
44 41 'methods' => WP_REST_Server::READABLE,
45 42 'callback' => $container->get(GetTemplateController::class),
46 - 'permission_callback' => function () {
47 - return current_user_can('manage_options');
43 + 'permission_callback' => static function () use ($routePermissionService) {
44 + return $routePermissionService->canViewForms();
48 45 }
49 46 ]
50 47 );
51 48
@@ -55,10 +52,10 @@
55 52 '/template/create',
56 53 [
57 54 'methods' => WP_REST_Server::CREATABLE,
58 55 'callback' => $container->get(AddFormController::class),
59 - 'permission_callback' => function () {
60 - return current_user_can('manage_options');
56 + 'permission_callback' => static function () use ($routePermissionService) {
57 + return $routePermissionService->canEditForms();
61 58 }
62 59 ]
63 60 );
64 61 }